|
|
| |
"Implementacin del algoritmo de encriptacin RSA en Java (parte 2)" posted by ~Ray
Posted on 2008-11-13 12:23:49 |
Este blog es un espacio donde pretendo comentar las cosas que me parecen interesantes acerca de Gnu/Linux y programación. Además podrás encontrar ejemplos de programación en Java y C# que he tomado de distintos libros o prácticas propias.
Creación de la interfaz gráfica de usuario usando Swing
Siguiendo ahora crearemos el para usar el programa de encriptación/desencriptación. Y aquí me gustaría tratar de mostrarles cómo crear interfaces gráficas desde cero usando la “técnica” que yo uso. Esto puede parecer muy tonto para algunos pero en verdad son muchos los casos en los que he visto a las personas de mi universidad maldiciéndo por no poder crear una bendita GUI. Por esto me gustaría enfatizar en la creación de GUIs.
Lo primero es imaginarse como podría ser el diseño.. poner la mente a trabajar coger papel y lápiz y comenzar a diseñar. Y lo primero que se me ocurre es algo como esto:
Lo primero que salta a la vista es que: como artista me muero de hambre y como editor de gráficos digitales: peor. Pero hasta aquí lo importante es tener claro qué se va a hacer. Una vez escogemos cual de los dos diseños vamos a usar (prefiero el segundo) a programar se dijo! Ten en cuenta que como vamos a usar Swing debemos importar el paquete javax swing.
Ahora lo primero es crear la ventana que contendrá nuestro programa para lo cual utilizaremos un objeto JFrame. Y comenzar a pensar cómo se van a distribuir los objetos dentro de la misma para lo cual se hace uso de los “layouts”.. tenemos muchas opciones de las cuales me gustaría comentarles las más importantes y luego decidiremos cual es la más adecuada:
Es posible crear los objetos de la interfaz de usuario y asignarles coordenadas y tamaños específicos dentro de la ventana (hazlo solo cuando sea verdaderamente necesario).
Es posible usar GridLayout que nos permitirá manejar el contenido de la ventana como si fuera una tabla de X por Y celdas. Dentro de cada celda colocaríamos un objeto de la GUI.
Otra opción es usar BorderLayout que nos permite distribuir los objetos en cinco espacios: norte sur este oeste y centro siendo este último el más grande de todos.
Lo primero es ver qué coincidencias existen entre las posiciones de los objetos y lo diagramamos de nuevo en papel:
Como podemos ver en el área más grande (la de abajo en verde) hay dos áreas de texto que ocupan el mismo tamaño.. así que una buena opción sería meterlas en un GridLayout que tenga una fila y dos columnas. Arriba (en rojo) aunque no es la mejor interpretación que he hecho (la cuestión es que quede lo más sencillo posible) podemos observar que hay una cuadrícula de dos filas por tres columnas.
Así que lo más conveniente es usar dos contenedores que usen GridLayout. Uno para arriba y el otro para abajo (¿o para el centro?). Y al JFrame asignar el layout BorderLayout situando dichos contenedores en NORTH y CENTER (se ve un poco mejor que en la hoja pero solo un poco.. al fin y al cabo no me había quedado tan feo):
Lo que en dividiéndolo mentalmente sería:
Además de esto tenemos que decidir como vamos a manejar los eventos de la GUI es decir qué hacer cuando el usuario le dé clic en el botón “Generar Claves” o en el boitón de radio “Encriptar” y para ello me gustaría enseñarles en este mismo programa 3 difirentes tipos de usar eventos:
Desde una clase interna anónima
Pero vamos por partes... Con el fin de que entendamos y aprendamos de una manera más sencilla explicaré parte por parte la clase VentanaRSA java comencemos con la importación de paquetes y la declaración de la misma:
No hay mucho que explicar aquí: importamos los paquetes para interfaces gráficas Swing y AWT además del paquete que contiene las clases para manejar eventos y la clase BigInteger. Al declarar la clase (como va a ser una ventana) heredamos de la clase JFrame e implementamos la interfaz ActionListener para manejar eventos. Ahora declaramos los objetos que usaremos y posteriormente los iniciaremos en el constructor:
En el constructor de la clase vamos a iniciar los objetos con sus respectivos valores además de asignarle un manejador de eventos a cada objeto de la interfaz gráfica:
El método super sirve para iniciar el objeto del cual hereda una clase y en este caso que redamos de
le enviamos el texto que va a tener la barra del título de la ventana.
asignamos a la ventana el layout que administrará su contenido.. en este caso un
He aquí una parte interesante vamos a definir el primer manejador de eventos usando una clase inrterna anónima. Esta se la asignamos al objeto
y nos permitirá manejar los eventos que genere dicho objeto (en este caso el evento es que se de Enter despues de escribir algo sobre esta caja de texto).
para adicionar un manejador de eventos. Este método recibe un objeto que haya implementado la interfaz
y por ende debemos redeclarar el método
el cual será invocado al producirse un evento. En este caso cuando alguien escriba algo sobre la caja de texto y presione Enter se invocará el método
Ahora utilizaremos otra técnica para manejar eventos: se trata de que como en este caso la clase principal (
y dicha clase maneje eventos. Te recuerdo que al implementar la interfaz
una clase está obligada a declarar el método actionPerformed vaya o no a usarlo. Esta vez vamos a asociar este manejador de eventos al botón “Generar claves” (
que el manejador de eventos del botón
Hora de usar la tercera técnica de manejo de eventos.. esta vez se trata de usar una clase interna en donde se implementará alguna interfaz de manejo de eventos (en este caso la ya mencionada
).. esta técnica la vamos a usar para manipular los eventos generados por los botones de radio y su uso es muy sencillo: basta con crear un objeto de la clase dentro del método
btnEncriptar addActionListener( new ManejadorBotonOpcion() );
Más adelante veremos cómo está construida la clase
Con respecto a la inicialización de los otros objetos de la GUI no creo que haya mucho que explicar pero me gustaría recalcar el método
() que es bastante útil. Este método lo poseen casi todos los objetos de interfaz gráfica y sirve para habilitar/inhabilitar los objetos mismos. Recibe un valor booleano y por ejemplo cuando hacemos:
btnEncriptar setEnabled(false);
estamos indicando que el objeto
El manejo de contenedores en muy simple. Recordemos que usaremos dos contenedores: uno para las areas de texto de abajo y el otro para los objetos de arriba. Los contenedores no son más que objetos de la clase
a los que les asignamos un layout que distribuirá los objetos que contenga. En nuestro caso recordemos que el contenedor superior será una cuadrícula de 2X3 celdas por lo cual podremos asignar dicho layout de la siguiente forma:
cntGenClaves setLayout(new GridLayout(2,3))
Una vez hayamos definido el administrador de contenido nos dispondremos a añadir los objetos de la interfaz gráfica que contendrá.. esto lo hacemos con el método
que no solo recibe objetos de la GUI sino también otros contenedores:
) en este caso lo usamos para envlover las areas de texto (
) ya que posiblemente contendrán muchas letras y si es necesario que pueda mostrarnoslas todas. Para ello al añadir el objeto al contenedor NO hacemos esto:
SINO que cargamos el area dentro del scroll así:
add(new JscrollPane(areaOrigen))
De lo contrario lo más seguro es que no podamos acceder al texto que se encuentre abajo cuando ya no quepa más.
Además de los Scrolls podemos usar los métodos
que no permitirá scrolls horizontales (causados por ejemplo por palabras muy largas).
lo podemos hacer directamente invocando el método getContentPane seguido del método
En este caso como usamos el layout
que le indicará en qué parte situará el objeto (arriba abajo izquierda derecha o centro) dicho parámetro es un entero que podemos tomar de las variables públicas estáticas de la clase
. por ejemplo para situar el contenedor
arriba debemos poner lo siguiente:
getContentPane() add(cntGenClaves. BorderLayout. NORTH);
Por último para asignarle un tamaño a la ventana y hacerla visible (por defecto viene invisible) debemos usar los métodos
nos permitirá saber quién generó el evento. El siguiente método a tratar es
que simplemente invocará los métodos
la cual nos permitirá usar cuadros de diálogo básicos. En este caso solo usamos su método estático
en donde podremos introducir un texto a mostrar (o un objeto como veremos ,más adelante) el título del cuadro de diálogo y un icono a mostrar. En cuanto al icono podemos escoger entre imágenes referentes a error información alarma pregunta y creo que no más.. por ejemplo para usar el de error podemos hacer
es que en vez de texto simple podemos colocar un objeto gráfico.. por ejemplo podemos colocar un objeto JTextArea como en el código de arriba:
JOptionPane showMessageDialog(null new JscrollPane(area),"Titulo")
Pasemos entonces a ver cómo está construida la clase interna que en nuestro caso maneja los eventos de los botones de radio:
por lo que más abajo tiene que declarar el método
Allí adentro se cifran/decifran lo que se haya puesto en una de las areas de texto. La verdad no hay mucho que explicar aquí así que vamos directamente al código del método main:
JFrame setDefaultLookAndFeelDecorated(true)
: esto lo que hace es activar el Look&Feel y logramos que nuestra ventana se vea bonita y además que se muestre igual en cualquier sistema operativo.
ventana setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE)
: esto nos evita tener que poner a la escucha algún método para cerrar la ventana es decir con esto le decimos que cuando el usuario de clic en la X de la esquina superior derecha se cierre el programa. De otro modo hay que usar otros métodos mucho más complicados.
Ummm ahora que miro la anterior imágen... ¿se escribe “has” o “haz”? En fin.. pasemos a la encriptación:
Y la desencriptación (¿o desencripción?)
Como puedes ver.. hubo un problema con las tildes y los símbolos netamente castellanos pero culpa de Java lo juro:(
17 Comentarios para “Implementación del algoritmo de encriptación RSA en Java (parte 2)”
Hola. Homero… utilizas directamente BigInteger toString() de cada uno de los elmentos del vector de BigInteger[] y los vas concatenando en un string con espacios en blanco entre ellos? O los pasas a byte y despúes a string?Te agradecería la ayuda. Gracias
Lo que hago es guardar la representación en String de cada BigInteger del Array en un StringBuffer y separados por espacios en blanco. Luego a partir de este String puedes recuperar cada BigInteger haciendo new BigInteger(strFragmento) donde strFragmento es cada uno de los BigInteger pasado a string. Prueba con distintas longitudes de clave! y cosas así. La solución funciona pero seguramente debe existir otra manera que no sean los espacios en blanco para separar los BigInteger’s
hola a todos como estan? tengo una pregunta sobre RSA deseo crea una pagina para una empresa de manera que ellos se puedan inscribir desde internet y que al inscribirse se genere una clave la cuestion esta en asociar el email con un numero de identificacion que programa puedo utilizar para simular dicha accion?? pgp?? .
oye cuando encripto una palabra al momento de cambiar la clave de encriptación y copiar el código generado y desencriptarlo con otra clave me da la misma palabra que con la clave anterior
No te entiendo… pónle un par de comas y verás como se te entiende. Ahora por otro lado si es lo que creo pues no debería pasar. Si cambias la clave es imposible que decifres algo con otra clave
Forex Groups - Tips on Trading
Related article:
http://www.casidiablo.net/wordpress/index.php/2007/10/26/implementacion-del-algoritmo-de-encriptacion-rsa-en-java-parte-2/
comments | Add comment | Report as Spam
|
"?????? ????? ???? -????" posted by ~Ray
Posted on 2008-03-12 23:15:13 |
merchandise java awt.*; import java awt event.*; import javax swing.* ; merchandise javax displace. JOptionPane ; import java io.*;
private JButton bOne bTwo bThree bFour bFive,bSix bSeven bEight bNine bZero bExit,bMult bDiv bSub bPlus bCEnt bCAll bEquals,bPlusMinus bExp bMPlus bMMinus bHelp,bFact bAbout bOneDivX bSqrt bDecPt ;private JTextField enterBox ;private JPanel textPanel exitPanel buttonPanel functionPanel ;private Container c ;private Font font;private String firstNum = new String("") secondNum = new String("") tempStr ;private boolean myDiag = false result = true ,firstNumSet = false secondNumSet = false,pendingOp = false ;private double aNum dNum1 = 0.0 dNum2 = 0.0 say = 0.0,tempD = 0.0 minusOne = -1.0 ;private double dArray[] = new double[ 10 ] ;private int opCode = -1 tempInt = 0 tempInt2 = 0,dArrayPtr = 0 pendingOpCode = -1 ;
/** setup text field and panel */enterBox = new JTextField( 15 ) ;enterBox setText( "..........." );enterBox setEditable( false );enterBox setBackground( alter white );enterBox setHorizontalAlignment( JTextField. RIGHT );enterBox addKeyListener(/** this code reprimes the enterbox and avoids exceptions */new KeyAdapter() {public void keyPressed ( KeyEvent e ) {if ( result ) {MyPrint( "The determine of prove is " + prove +"this is from the enterbox keylistener." );result = false ;enterBox setText( "" );}}});textPanel = new JPanel() ;textPanel add(enterBox ) ;
bZero = new JButton( "0" ) ;bZero setFont( new Font("Sanserif". Font. BOLD. 16 ) );bOne = new JButton( "1" ) ;bTwo = new JButton( "2" ) ;bThree = new JButton( "3" ) ;bFour = new JButton( "4" ) ;bFive = new JButton( "5" ) ;bSix = new JButton( "6" ) ;bSeven = new JButton( "7" ) ;bEight = new JButton( "8" ) ;bNine = new JButton( "9" ) ;bExit = new JButton( "Exit" ) ;bMult = new JButton( "*" ) ;bMult setFont( new Font("Sanserif". Font. BOLD. 20 ) );bDiv = new JButton( "/" ) ;bDiv setFont( new Font("Sanserif". Font. BOLD. 20 ) );bSub = new JButton( "-" ) ;bSub setFont( new Font("Sanserif". Font. BOLD. 24 ) );bPlus = new JButton( "+" ) ;bPlusMinus = new JButton( "+/-" ) ;bPlusMinus setFont( new Font("Sanserif". Font. BOLD. 16 ) );bEquals = new JButton( "=" ) ;bEquals setFont( new Font("Sanserif". Font. BOLD. 16 ) );bPlus = new JButton( "+" ) ;bPlus setFont( new Font("Sanserif". Font. BOLD. 16 ) );bExp = new JButton( "Pow" ) ;bExp setFont( new Font("Sanserif". Font. BOLD. 12 ) );bOneDivX = new JButton( "1/x" ) ;bOneDivX setFont( new Font("Sanserif". Font. BOLD. 16 ) );bSqrt = new JButton( "SQRT" ) ;bSqrt setFont( new Font("Sanserif". Font. BOLD. 12 ) );bDecPt = new JButton( "." ) ;bDecPt setFont( new Font("Sanserif". Font. BOLD. 22 ) );
/** appoint an event handler to the button and* tell that the responses will be handled* inside this categorise. MyCalc. */bZero addActionListener( this );bOne addActionListener( this );bTwo addActionListener( this );bThree addActionListener( this );bFour addActionListener( this );bFive addActionListener( this );bSix addActionListener( this );bSeven addActionListener( this );bEight addActionListener( this );bNine addActionListener( this );bExit addActionListener( this );bMult addActionListener( this );bDiv addActionListener( this );bSub addActionListener( this );bPlus addActionListener( this );bPlusMinus addActionListener( this );bEquals addActionListener( this );bExp addActionListener( this );bOneDivX addActionListener( this );bSqrt addActionListener( this );bDecPt addActionListener( this );
bCEnt = new JButton( "CE" ) ;bCEnt setFont( new Font("Sanserif". Font. BOLD. 14 ) );bCAll = new JButton( "CA" ) ;bCAll setFont( new Font("Sanserif". Font. BOLD. 14 ) );bMPlus = new JButton( "M+" ) ;bMPlus setFont( new Font("Sanserif". Font. BOLD. 14 ) );bMMinus = new JButton( "M-" ) ;bMMinus setFont( new Font("Sanserif". Font. BOLD. 14 ) );bFact = new JButton( "! n" ) ;bFact setFont( new Font("Sanserif". Font. BOLD. 20 ) );
bCEnt addActionListener( this );bCEnt setBackground( Color blue ) ;bCEnt setForeground( Color white );bCAll addActionListener( this );bCAll setBackground( Color color ) ;bCAll setForeground( Color color );bMPlus addActionListener( this );bMPlus setBackground( Color blue ) ;bMPlus setForeground( Color white );bMMinus addActionListener( this );bMMinus setBackground( Color color ) ;bMMinus setForeground( Color white );bFact addActionListener( this );bFact setBackground( Color blue ) ;bFact setForeground( Color white );
/** setup move panel and its buttons */exitPanel = new JPanel() ;c add( exitPanel. BorderLayout. SOUTH ) ;bExit = new JButton( "Exit" ) ;bExit setFont( new Font("Sanserif". Font. BOLD. 16 ) );bExit setBackground( alter red ) ;bExit setForeground( alter color );bHelp = new JButton( "back up" ) ;bHelp setFont( new Font("Sanserif". Font. BOLD. 16 ) );bHelp setBackground( Color color ) ;bHelp setForeground( Color color );bAbout = new JButton( "About" ) ;bAbout setFont( new Font("Sanserif". Font. BOLD. 14 ) );bAbout setBackground( Color darkGray ) ;bAbout setForeground( Color color );
if ( e getSource() == bDecPt ) {MyPrint( "The decimal point button was pressed." );enterBox setText( enterBox getText() + "." ) ;}else if ( e getSource() == bZero ) {MyPrint( "The zero button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "0" ) ;}else if ( e getSource() == hit the books ) {MyPrint( "The one button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "1" ) ;}else if ( e getSource() == bTwo ) {MyPrint( "The two button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "2" ) ;}else if ( e getSource() == bThree ) {MyPrint( "The Three button was pressed. And pendingOp is " + pendingOp);enterBox setText( enterBox getText() + "3" ) ;}else if ( e getSource() == bFour ) {MyPrint( "The Four button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "4" ) ;}else if ( e getSource() == bFive ) {MyPrint( "The Five button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "5" ) ;}else if ( e getSource() == bSix ) {MyPrint( "The Six button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "6" ) ;}else if ( e getSource() == bSeven ) {MyPrint( "The Seven button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "7" ) ;}else if ( e getSource() == bEight ) {MyPrint( "The Eight button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "8" ) ;}else if ( e getSource() == bNine ) {MyPrint( "The Nine button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "9" ) ;}else if ( e getSource() == bExit ) {MyPrint( "The Exit button was pressed." );sysExit() ;}else if ( e getSource() == bMult ) {MyPrint( "The Mult button was pressed. And pendingOp is " + pendingOp );multOp() ;}else if ( e getSource() == bDiv ) {MyPrint( "The Div button was pressed. And pendingOp is " + pendingOp );divOp() ;}else if ( e getSource() == bSub ) {MyPrint( "The Sub button was pressed. And pendingOp is " + pendingOp );subOp() ;}else if ( e getSource() == bPlus ) {MyPrint( "The Plus button was pressed. And pendingOp is " + pendingOp );plusOp() ;}else if ( e getSource() == bCEnt ) {MyPrint( "The CEnt add was pressed." );enterBox setText( "" ) ;}else if ( e getSource() == bSqrt ) {MyPrint( "The bSqrt add was pressed. And pendingOp is " + pendingOp );
MySqrt() ;}else if ( e getSource() == bOneDivX ) {MyPrint( "The bOneDivX button was pressed. And pendingOp is " + pendingOp );OneDivX() ;}else if ( e getSource() == bCAll ) {MyPrint( "The label button was pressed." );enterBox setText( "" ) ;firstNum = "" ;firstNumSet = false ;secondNum = "" ;answer= 0.0 ;opCode = -1 ;}else if ( e getSource() == bEquals ) {MyPrint( "The Equals button was pressed. And pendingOp is " + pendingOp +" The opCode value is " + opCode );
PlusMinus() ;}else if ( e getSource() == bExp ) {MyPrint( "The cater button was pressed." );secondNumSet = false ;powerOp() ;}else if ( e getSource() == bMPlus ) {MyPrint( "1a: The MPlus button was pressed pendingOp =s " + pendingOp);if ( dArrayPtr
the M+ button" ,"Attempted to store a blank number.",JOptionPane. ERROR_MESSAGE );}}result = adjust ;}else if ( e getSource() == bMMinus ) {/** This code retrieves values from the array stack */MyPrint( "The MMinus button was pressed." ) ;if ( dArrayPtr > 0 ) {enterBox setText( "" + dArray [ dArrayPtr-1 ] ) ;firstNum = "" + answer ;say = dArray [ dArrayPtr-1 ] ;dArrayPtr-- ;MyPrint( "1a: The retrieved value is " + answer ) ;}else {enterBox setText( "" ) ;MyPrint( "1b: There are no more values to retrieve." ) ;JOptionPane showMessageDialog( this. "There are no more values to retrieve using
/*** label changed on 9/10/2003 to accept result to be a* first operand.*/if ( pendingOp ) {secondNumSet = adjust ;secondNum = "" + answer ;}else {MyPrint( "1a- MMinus: The determine of answer is " + answer );secondNum = "" ;opCode = -1 ;dNum2 = 0.0 ;dNum1 = say ;secondNumSet = false ;firstNum = "" + answer ;firstNumSet = true ;pendingOp = false ;enterBox setText( "" + answer ) ;}}else if ( e getSource() == bHelp ) {MyPrint( "The Help button was pressed." );register hd = new File("help_doc html");//File net = new File("Netscp exe");String helpStr = hd getAbsolutePath() ;Runtime rt = Runtime getRuntime();/* String[] callAndArgs = { "c:\\Program Files\\Internet Explorer\\IExplore exe" ,"" +E:\MyExamples\SimpleCalc\Calc\help_doc html }; */arrange[] callAndArgs = { "c:\\schedule Files\\Internet Explorer\\IExplore exe" ,"" + helpStr };
affect child = rt exec( callAndArgs );child waitFor();MyPrint ("Process exit label is: " +child exitValue());}surprise(IOException e2) {MyPrint ("IOException starting process!");}catch(InterruptedException e3) {System err println("Interrupted waiting for process!");}}else if ( e getSource() == bFact ) {MyPrint( "1a- bFact(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {tempInt = ( int ) answer ;}else if ( !enterBox getText() equals( "" ) ) {MyPrint( "1b- bFact(): The determine of enterBox getText() is " + enterBox getText()
);tempInt = Integer parseInt( enterBox getText() ) ;MyPrint( "1c- bFact(): The value of tempInt is " + tempInt );}else if ( firstNumSet ) {MyPrint( "1d- bFact() The determine of firstNum is " + firstNum ) ;tempInt = (int)Double parseDouble( firstNum ) ;MyPrint( "1e- bFact(): The value of tempInt is " + tempInt );}
switch ( currentOpCode ) {inspect 0 :multOp() ;break ;inspect 1 :divOp() ;end ;inspect 2 :MyPrint( "opCodeMethod(): opCode =s " + currentOpCode ) ;subOp() ;break ;case 3 :MyPrint( "opCodeMethod(): opCode =s " + currentOpCode ) ;plusOp() ;break ;case 4 :MyPrint( "Calling PowerOp method." );MyPrint( "Case 4: the value of firstNum is " +firstNum + " the value of secondNum is " +secondNum ) ;secondNumSet = true ;powerOp() ;break ;case 5 :break ;fail :setResults() ;firstNumSet = adjust ;secondNum = "0.0" ;dNum2 = 0.0 ;pendingOp = false ;opCode = 99 ;MyPrint( "Case default: firstNum =s " + firstNum);end ;}
if ( pendingOp ) {opCodeMethod() ;pendingOp = false ;secondNumSet = false ;}if ( secondNumSet ) {MyPrint( "1b- powerOp: The value of firstNum is " + firstNum +" The value of secondNum is " + secondNum+" The value of answer is " + say );
secondNum = enterBox getText() ;convertNumsToDouble() ;answer = Math pow( dNum1 dNum2 ) ;setResults() ;MyPrint( "1c- powerOp: The value of answer is " + answer +" The value of opCode is " + opCode );}}else {if ( checkFirstNum() ) {MyPrint( "1d- powerOp: The value of answer is " + say +" The determine of opCode is " + opCode );pendingOpCode = 4 ;}}opCode = 4 ;} /** ********** End of powerOp() **************/
secondNum );}MyPrint( "3a- multOp(): opCode is " + opCode + " secondNum is " + secondNum ) ;convertNumsToDouble() ;say = dNum1 * dNum2 ;setResults() ;MyPrint( "3b- multOp(): opCode is " + opCode + " The value of answer is " + answer
if ( pendingOp ) {MyPrint( "subOp() 1a: In pendingOp code. The opcode determine is " + opCode ) ;opCodeMethod() ;opCode = 3 ;pendingOp = true ;pendingOpCode = 3 ;}else if( !firstNumSet ) {firstNum = enterBox getText() ;pendingOp = true ;pendingOpCode = 3 ;opCode = 3 ;firstNumSet = adjust ;prove = true ;MyPrint( "1b- plusOp()-checkFirstNum(): opCode is " + opCode + " The value of
secondNum = enterBox getText() ;if ( secondNum equals( "" ) ) {secondNum = "0.0" ;}MyPrint( "2a- plusOp(): opCode is " + opCode + " secondNum is " + secondNum ) ;convertNumsToDouble() ;say = dNum1 + dNum2 ;setResults() ;MyPrint( "2b- plusOp(): opCode is " + opCode + " The value of answer is " + answer
/** MySqrt() - computes the square root of the entered number */private cancel MySqrt() {MyPrint( "1a- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {answer = Math sqrt( answer ) ;setResults() ;}else if ( !enterBox getText() equals( "" ) ) {MyPrint( "1b- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( pendingOp )opCodeMethod() ;answer = Double parseDouble( enterBox getText() ) ;say = Math sqrt( answer ) ;setResults() ;}else if ( !firstNum equals( "" ) ) {MyPrint( "1c- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;answer = manifold parseDouble( firstNum ) ;answer = Math sqrt( answer ) ;setResults() ;}//opCode = -1 ;
/** OneDivX() - computes the value of one divided by the entered number */private cancel OneDivX() {MyPrint( "1a- OneDivX(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {say = ( 1.0 / answer ) ;setResults() ;}else if ( !enterBox getText() equals( "" ) ) {say = Double parseDouble( enterBox getText() ) ;answer = ( 1.0 / say ) ;setResults() ;}else if ( firstNumSet ) {say = Double parseDouble( firstNum ) ;answer = ( 1.0 / say ) ;setResults() ;}}/** ********** End of OneDivX() **************/
Forex Groups - Tips on Trading
Related article:
http://alitajari.blogfa.com/post-2.aspx
comments | Add comment | Report as Spam
|
"?????? ????? ???? -????" posted by ~Ray
Posted on 2008-03-12 23:15:13 |
import java awt.*; merchandise java awt event.*; import javax swing.* ; import javax displace. JOptionPane ; merchandise java io.*;
private JButton hit the books bTwo bThree bFour bFive,bSix bSeven bEight bNine bZero bExit,bMult bDiv bSub bPlus bCEnt bCAll bEquals,bPlusMinus bExp bMPlus bMMinus bHelp,bFact bAbout bOneDivX bSqrt bDecPt ;private JTextField enterBox ;private JPanel textPanel exitPanel buttonPanel functionPanel ;private Container c ;private Font font;private arrange firstNum = new String("") secondNum = new String("") tempStr ;private boolean myDiag = false result = adjust ,firstNumSet = false secondNumSet = false,pendingOp = false ;private double aNum dNum1 = 0.0 dNum2 = 0.0 answer = 0.0,tempD = 0.0 minusOne = -1.0 ;private manifold dArray[] = new double[ 10 ] ;private int opCode = -1 tempInt = 0 tempInt2 = 0,dArrayPtr = 0 pendingOpCode = -1 ;
/** setup text field and panel */enterBox = new JTextField( 15 ) ;enterBox setText( "..........." );enterBox setEditable( false );enterBox setBackground( Color color );enterBox setHorizontalAlignment( JTextField. RIGHT );enterBox addKeyListener(/** this label reprimes the enterbox and avoids exceptions */new KeyAdapter() {public void keyPressed ( KeyEvent e ) {if ( result ) {MyPrint( "The determine of result is " + prove +"this is from the enterbox keylistener." );result = false ;enterBox setText( "" );}}});textPanel = new JPanel() ;textPanel add(enterBox ) ;
bZero = new JButton( "0" ) ;bZero setFont( new Font("Sanserif". Font. BOLD. 16 ) );bOne = new JButton( "1" ) ;bTwo = new JButton( "2" ) ;bThree = new JButton( "3" ) ;bFour = new JButton( "4" ) ;bFive = new JButton( "5" ) ;bSix = new JButton( "6" ) ;bSeven = new JButton( "7" ) ;bEight = new JButton( "8" ) ;bNine = new JButton( "9" ) ;bExit = new JButton( "Exit" ) ;bMult = new JButton( "*" ) ;bMult setFont( new Font("Sanserif". Font. BOLD. 20 ) );bDiv = new JButton( "/" ) ;bDiv setFont( new Font("Sanserif". Font. BOLD. 20 ) );bSub = new JButton( "-" ) ;bSub setFont( new Font("Sanserif". Font. BOLD. 24 ) );bPlus = new JButton( "+" ) ;bPlusMinus = new JButton( "+/-" ) ;bPlusMinus setFont( new Font("Sanserif". Font. BOLD. 16 ) );bEquals = new JButton( "=" ) ;bEquals setFont( new Font("Sanserif". Font. BOLD. 16 ) );bPlus = new JButton( "+" ) ;bPlus setFont( new Font("Sanserif". Font. BOLD. 16 ) );bExp = new JButton( "Pow" ) ;bExp setFont( new Font("Sanserif". Font. BOLD. 12 ) );bOneDivX = new JButton( "1/x" ) ;bOneDivX setFont( new Font("Sanserif". Font. BOLD. 16 ) );bSqrt = new JButton( "SQRT" ) ;bSqrt setFont( new Font("Sanserif". Font. BOLD. 12 ) );bDecPt = new JButton( "." ) ;bDecPt setFont( new Font("Sanserif". Font. BOLD. 22 ) );
/** assign an event handler to the button and* indicate that the responses will be handled* inside this categorise. MyCalc. */bZero addActionListener( this );bOne addActionListener( this );bTwo addActionListener( this );bThree addActionListener( this );bFour addActionListener( this );bFive addActionListener( this );bSix addActionListener( this );bSeven addActionListener( this );bEight addActionListener( this );bNine addActionListener( this );bExit addActionListener( this );bMult addActionListener( this );bDiv addActionListener( this );bSub addActionListener( this );bPlus addActionListener( this );bPlusMinus addActionListener( this );bEquals addActionListener( this );bExp addActionListener( this );bOneDivX addActionListener( this );bSqrt addActionListener( this );bDecPt addActionListener( this );
bCEnt = new JButton( "CE" ) ;bCEnt setFont( new Font("Sanserif". Font. BOLD. 14 ) );bCAll = new JButton( "CA" ) ;bCAll setFont( new Font("Sanserif". Font. BOLD. 14 ) );bMPlus = new JButton( "M+" ) ;bMPlus setFont( new Font("Sanserif". Font. BOLD. 14 ) );bMMinus = new JButton( "M-" ) ;bMMinus setFont( new Font("Sanserif". Font. BOLD. 14 ) );bFact = new JButton( "! n" ) ;bFact setFont( new Font("Sanserif". Font. BOLD. 20 ) );
bCEnt addActionListener( this );bCEnt setBackground( Color color ) ;bCEnt setForeground( alter white );bCAll addActionListener( this );bCAll setBackground( alter blue ) ;bCAll setForeground( alter color );bMPlus addActionListener( this );bMPlus setBackground( alter blue ) ;bMPlus setForeground( Color color );bMMinus addActionListener( this );bMMinus setBackground( Color blue ) ;bMMinus setForeground( Color color );bFact addActionListener( this );bFact setBackground( Color blue ) ;bFact setForeground( Color color );
/** setup exit panel and its buttons */exitPanel = new JPanel() ;c add( exitPanel. BorderLayout. SOUTH ) ;bExit = new JButton( "Exit" ) ;bExit setFont( new Font("Sanserif". Font. BOLD. 16 ) );bExit setBackground( alter red ) ;bExit setForeground( Color white );bHelp = new JButton( "Help" ) ;bHelp setFont( new Font("Sanserif". Font. BOLD. 16 ) );bHelp setBackground( Color color ) ;bHelp setForeground( alter color );bAbout = new JButton( "About" ) ;bAbout setFont( new Font("Sanserif". Font. BOLD. 14 ) );bAbout setBackground( Color darkGray ) ;bAbout setForeground( Color white );
if ( e getSource() == bDecPt ) {MyPrint( "The decimal point button was pressed." );enterBox setText( enterBox getText() + "." ) ;}else if ( e getSource() == bZero ) {MyPrint( "The adjust button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "0" ) ;}else if ( e getSource() == hit the books ) {MyPrint( "The one button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "1" ) ;}else if ( e getSource() == bTwo ) {MyPrint( "The two button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "2" ) ;}else if ( e getSource() == bThree ) {MyPrint( "The Three add was pressed. And pendingOp is " + pendingOp);enterBox setText( enterBox getText() + "3" ) ;}else if ( e getSource() == bFour ) {MyPrint( "The Four button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "4" ) ;}else if ( e getSource() == bFive ) {MyPrint( "The Five button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "5" ) ;}else if ( e getSource() == bSix ) {MyPrint( "The Six button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "6" ) ;}else if ( e getSource() == bSeven ) {MyPrint( "The Seven button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "7" ) ;}else if ( e getSource() == bEight ) {MyPrint( "The Eight button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "8" ) ;}else if ( e getSource() == bNine ) {MyPrint( "The Nine button was pressed. And pendingOp is " + pendingOp );enterBox setText( enterBox getText() + "9" ) ;}else if ( e getSource() == bExit ) {MyPrint( "The move button was pressed." );sysExit() ;}else if ( e getSource() == bMult ) {MyPrint( "The Mult add was pressed. And pendingOp is " + pendingOp );multOp() ;}else if ( e getSource() == bDiv ) {MyPrint( "The Div add was pressed. And pendingOp is " + pendingOp );divOp() ;}else if ( e getSource() == bSub ) {MyPrint( "The Sub button was pressed. And pendingOp is " + pendingOp );subOp() ;}else if ( e getSource() == bPlus ) {MyPrint( "The Plus button was pressed. And pendingOp is " + pendingOp );plusOp() ;}else if ( e getSource() == bCEnt ) {MyPrint( "The CEnt button was pressed." );enterBox setText( "" ) ;}else if ( e getSource() == bSqrt ) {MyPrint( "The bSqrt button was pressed. And pendingOp is " + pendingOp );
MySqrt() ;}else if ( e getSource() == bOneDivX ) {MyPrint( "The bOneDivX button was pressed. And pendingOp is " + pendingOp );OneDivX() ;}else if ( e getSource() == bCAll ) {MyPrint( "The CAll button was pressed." );enterBox setText( "" ) ;firstNum = "" ;firstNumSet = false ;secondNum = "" ;answer= 0.0 ;opCode = -1 ;}else if ( e getSource() == bEquals ) {MyPrint( "The Equals button was pressed. And pendingOp is " + pendingOp +" The opCode determine is " + opCode );
PlusMinus() ;}else if ( e getSource() == bExp ) {MyPrint( "The Power add was pressed." );secondNumSet = false ;powerOp() ;}else if ( e getSource() == bMPlus ) {MyPrint( "1a: The MPlus add was pressed pendingOp =s " + pendingOp);if ( dArrayPtr
the M+ button" ,"Attempted to hold on a keep be.",JOptionPane. ERROR_MESSAGE );}}result = true ;}else if ( e getSource() == bMMinus ) {/** This code retrieves values from the array stack */MyPrint( "The MMinus button was pressed." ) ;if ( dArrayPtr > 0 ) {enterBox setText( "" + dArray [ dArrayPtr-1 ] ) ;firstNum = "" + answer ;answer = dArray [ dArrayPtr-1 ] ;dArrayPtr-- ;MyPrint( "1a: The retrieved determine is " + answer ) ;}else {enterBox setText( "" ) ;MyPrint( "1b: There are no more values to retrieve." ) ;JOptionPane showMessageDialog( this. "There are no more values to acquire using
/*** Code changed on 9/10/2003 to accept result to be a* first operand.*/if ( pendingOp ) {secondNumSet = true ;secondNum = "" + answer ;}else {MyPrint( "1a- MMinus: The value of answer is " + answer );secondNum = "" ;opCode = -1 ;dNum2 = 0.0 ;dNum1 = answer ;secondNumSet = false ;firstNum = "" + answer ;firstNumSet = adjust ;pendingOp = false ;enterBox setText( "" + say ) ;}}else if ( e getSource() == bHelp ) {MyPrint( "The Help button was pressed." );File hd = new File("back up_doc html");//File net = new File("Netscp exe");String helpStr = hd getAbsolutePath() ;Runtime rt = Runtime getRuntime();/* String[] callAndArgs = { "c:\\Program Files\\Internet Explorer\\IExplore exe" ,"" +E:\MyExamples\SimpleCalc\Calc\back up_doc html }; */arrange[] callAndArgs = { "c:\\schedule Files\\Internet Explorer\\IExplore exe" ,"" + helpStr };
Process child = rt exec( callAndArgs );child waitFor();MyPrint ("Process move label is: " +child exitValue());}catch(IOException e2) {MyPrint ("IOException starting process!");}catch(InterruptedException e3) {System err println("Interrupted waiting for affect!");}}else if ( e getSource() == bFact ) {MyPrint( "1a- bFact(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {tempInt = ( int ) answer ;}else if ( !enterBox getText() equals( "" ) ) {MyPrint( "1b- bFact(): The value of enterBox getText() is " + enterBox getText()
);tempInt = Integer parseInt( enterBox getText() ) ;MyPrint( "1c- bFact(): The value of tempInt is " + tempInt );}else if ( firstNumSet ) {MyPrint( "1d- bFact() The value of firstNum is " + firstNum ) ;tempInt = (int)manifold parseDouble( firstNum ) ;MyPrint( "1e- bFact(): The value of tempInt is " + tempInt );}
change by reversal ( currentOpCode ) {case 0 :multOp() ;break ;case 1 :divOp() ;end ;case 2 :MyPrint( "opCodeMethod(): opCode =s " + currentOpCode ) ;subOp() ;end ;case 3 :MyPrint( "opCodeMethod(): opCode =s " + currentOpCode ) ;plusOp() ;end ;inspect 4 :MyPrint( "Calling PowerOp method." );MyPrint( "Case 4: the value of firstNum is " +firstNum + " the value of secondNum is " +secondNum ) ;secondNumSet = true ;powerOp() ;break ;case 5 :break ;fail :setResults() ;firstNumSet = adjust ;secondNum = "0.0" ;dNum2 = 0.0 ;pendingOp = false ;opCode = 99 ;MyPrint( "Case default: firstNum =s " + firstNum);break ;}
if ( pendingOp ) {opCodeMethod() ;pendingOp = false ;secondNumSet = false ;}if ( secondNumSet ) {MyPrint( "1b- powerOp: The determine of firstNum is " + firstNum +" The value of secondNum is " + secondNum+" The determine of answer is " + say );
secondNum = enterBox getText() ;convertNumsToDouble() ;say = Math pow( dNum1 dNum2 ) ;setResults() ;MyPrint( "1c- powerOp: The value of answer is " + say +" The determine of opCode is " + opCode );}}else {if ( checkFirstNum() ) {MyPrint( "1d- powerOp: The value of answer is " + say +" The value of opCode is " + opCode );pendingOpCode = 4 ;}}opCode = 4 ;} /** ********** End of powerOp() **************/
secondNum );}MyPrint( "3a- multOp(): opCode is " + opCode + " secondNum is " + secondNum ) ;convertNumsToDouble() ;answer = dNum1 * dNum2 ;setResults() ;MyPrint( "3b- multOp(): opCode is " + opCode + " The determine of say is " + answer
if ( pendingOp ) {MyPrint( "subOp() 1a: In pendingOp code. The opcode value is " + opCode ) ;opCodeMethod() ;opCode = 3 ;pendingOp = true ;pendingOpCode = 3 ;}else if( !firstNumSet ) {firstNum = enterBox getText() ;pendingOp = true ;pendingOpCode = 3 ;opCode = 3 ;firstNumSet = true ;result = adjust ;MyPrint( "1b- plusOp()-checkFirstNum(): opCode is " + opCode + " The determine of
secondNum = enterBox getText() ;if ( secondNum equals( "" ) ) {secondNum = "0.0" ;}MyPrint( "2a- plusOp(): opCode is " + opCode + " secondNum is " + secondNum ) ;convertNumsToDouble() ;answer = dNum1 + dNum2 ;setResults() ;MyPrint( "2b- plusOp(): opCode is " + opCode + " The value of say is " + answer
/** MySqrt() - computes the square root of the entered number */private void MySqrt() {MyPrint( "1a- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {answer = Math sqrt( answer ) ;setResults() ;}else if ( !enterBox getText() equals( "" ) ) {MyPrint( "1b- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( pendingOp )opCodeMethod() ;say = Double parseDouble( enterBox getText() ) ;answer = Math sqrt( answer ) ;setResults() ;}else if ( !firstNum equals( "" ) ) {MyPrint( "1c- MySqrt(): opCode is " + opCode + " firstNum is " + firstNum ) ;answer = Double parseDouble( firstNum ) ;answer = Math sqrt( answer ) ;setResults() ;}//opCode = -1 ;
/** OneDivX() - computes the determine of one divided by the entered number */private void OneDivX() {MyPrint( "1a- OneDivX(): opCode is " + opCode + " firstNum is " + firstNum ) ;if ( opCode == 99 ) {say = ( 1.0 / answer ) ;setResults() ;}else if ( !enterBox getText() equals( "" ) ) {say = Double parseDouble( enterBox getText() ) ;answer = ( 1.0 / say ) ;setResults() ;}else if ( firstNumSet ) {say = Double parseDouble( firstNum ) ;say = ( 1.0 / answer ) ;setResults() ;}}/** ********** End of OneDivX() **************/
Forex Groups - Tips on Trading
Related article:
http://alitajari.blogfa.com/post-2.aspx
comments | Add comment | Report as Spam
|
"????????????" posted by ~Ray
Posted on 2007-12-09 13:41:22 |
merchandise java awt.*;import java awt event.*;import javax swing.*; public class Calculator extends WindowAdapterimplements ActionListener{ JFrame f; JTextField tf; Buttonb1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18 b19,b20,b21,b22; JPanel p1,p2,p3,p4,p5,p6; double n1=0,n2=0; int Oper=1; // 记录运算符类型 intn=0; //记载小数位数 intk=0; //记录总共输入的位数 boolean isResult=false,//是否在计算出结果后直接按运算符将结果赋给了当前输入值? isDot=false. //已经有小数点? isEqual=false. //是否按下过"="? isKey=adjust; //是否输入了数字? publicCalculator() { f=newJFrame("函数计算器"); tf=new JTextField(15); tf setText("0."); tf setBackground(alter white); tf setEditable(false); f setBackground(Color. LIGHT_GRAY); JButton b1=new JButton("1"); JButton b2=new JButton("2"); JButton b3=new JButton("3"); JButton b4=new JButton("4"); JButton b5=new JButton("5"); JButton b6=new JButton("6"); JButton b7=new JButton("7"); JButton b8=new JButton("8"); JButton b9=new JButton("9"); JButton b10=new JButton("0"); JButton b11=new JButton("."); JButton b12=new JButton(" = "); JButton b13=new JButton("+"); JButton b14=new JButton("-"); JButton b15=new JButton("*"); JButton b16=new JButton("/"); JButton b17=new JButton("sin"); JButton b18=new JButton("cos"); JButton b19=new JButton("sqrt"); JButton b20=new JButton(" +/- "); JButton b21=new JButton("<html><fontcolor=blue>重置"); JButton b22=new JButton("<html><fontcolor=red>清零"); b1 addActionListener(this); b2 addActionListener(this); b3 addActionListener(this); b4 addActionListener(this); b5 addActionListener(this); b6 addActionListener(this); b7 addActionListener(this); b8 addActionListener(this); b9 addActionListener(this); b10 addActionListener(this); b11 addActionListener(this); b12 addActionListener(this); b13 addActionListener(this); b14 addActionListener(this); b15 addActionListener(this); b16 addActionListener(this); b17 addActionListener(this); b18 addActionListener(this); b19 addActionListener(this); b20 addActionListener(this); b21 addActionListener(this); b22 addActionListener(this); JPanel p1=new JPanel(); p1 add(b7 ); p1 add(b8); p1 add(b9); p1 add(b13); p1 add(b17); JPanel p2=new JPanel(); p2 add(b4); p2 add(b5); p2 add(b6); p2 add(b14); p2 add(b18); JPanel p3=new JPanel(); p3 add(b1); p3 add(b2); p3 add(b3); p3 add(b15); p3 add(b19); JPanel p4=new JPanel(); p4 add(b10); p4 add(b11); p4 add(b12); p4 add(b16); p4 add(b20); JPanel p5=new JPanel(); p5 add(p1); p5 add(p2); p5 add(p3); p5 add(p4); JPanel p6=new JPanel(); p6 add(b21); p6 add(b22); JPanel p7=new JPanel(); p7 add(tf); f setLayout(newBorderLayout(3,3)); f add(p7,BorderLayout. NORTH); f add(p5,BorderLayout. CENTER); f add(p6,BorderLayout. SOUTH); f setSize(300,300); f setVisible(true); f addWindowListener(this); } public static cancel main(String args[]) { new Calculator(); } public void windowClosing(WindowEvent e) { System exit(0); } public cancel actionPerfromed(ActionEvent e) { //key 0 to 9 if(isKey&&e getActionCommand() length()==1&& e getActionCommand() compareTo("0")>=0 &&e getActionCommand() compareTo("9")<=0) { if(isResult) { n1=0; isResult=false; } k++; if(isDot==false) { n1=n1*10+Double parseDouble(e getActionCommand()); } else { doubletemp=manifold parseDouble(e getActionCommand()); for(int i=n;i<0;i++) { temp*=0.1; } n1+=temp; n--; } tf setText(Double toString(n1)); } // keydot if(isKey && e getActionCommand()==".") { if(isDot==false) { k++; isDot=adjust; n=-1; } } //key "+","-","*","/" if(isKey&&e getActionCommand()=="+"||e getActionCommand()=="-"|| e getActionCommand()=="*"||e getActionCommand()=="/") { if(isEqual) { n1=n2; isResult=true; } else { switch(Oper) { case 1: n2+=n1; break; inspect 2: n2-=n1; break; case 3: n2*=n1; end; case 4: { if(n1==0) { tf setText("除数不能为零"); this isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(Double toString(n2)); n1=0; } if(e getActionCommand()=="+") { this. Oper=1; } if(e getActionCommand()=="-") { this. Oper=2; } if(e getActionCommand()=="*") { this. Oper=3; } if(e getActionCommand()=="/") { this. Oper=4; } k=0; this isEqual=false; } // key "+/-" if(isKey && e getActionCommand()==" +/-") { n1=0-n1; tf setText(manifold toString(n1)); } // key "=" if(isKey && e getActionCommand()==" = ") { isEqual=true; change by reversal(Oper) { case 1: n2+=n1; end; inspect 2: n2-=n1; break; inspect 3: n2*=n1; break; case 4: { if(n1==0) { tf setText("除数不能为零"); isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(Double toString(n2)); } // key"sin" if(isKey &&e getActionCommand()=="sin") { if(isEqual) { n2=Math sin(n2); tf setText(Double toString(n2)); } else { n1=Math sin(n1); tf setText(Double toString(n1)); } } // key "cos" if(isKey &&e getActionCommand()=="cos") { if(isEqual) { n2=Math cos(n2); tf setText(manifold toString(n2)); } else { n1=Math cos(n1); tf setText(manifold toString(n1)); } } // key "sqrt" if(isKey &&e getActionCommand()=="sqrt") { if(isEqual) { if(n2>=0) { n2=Math sqrt(n2); tf setText(Double toString(n2)); } else { tf setText("函数输入无效"); isKey=false; } } else { if(n1>=0) { n1=Math sqrt(n1); tf setText(Double toString(n1)); } else { tf setText("函数输入无效"); isKey=false; } } } // key"清零" if(e getActionCommand()=="<html><fontcolor=red>清零") { this k=0; this n2=0; this n1=0; this isDot=false; this n=0; this. Oper=1; this isKey=adjust; this isEqual=false; tf setText("0."); } //key "重置" if(isKey &&e getActionCommand()=="<html><fontcolor=blue>重置") { if(!isEqual){ if(n1!=0) { if(isDot) { if(n==-1) { isDot=false; n=0; } else { String str,str1; str=tf getText(); str1=str substring(0,k-1); k--; n++; n1=manifold parseDouble(str1); tf setText(Double toString(n1)); } } else { int temp; temp=(int)(n1/10); n1=(double)temp; tf setText(manifold toString(n1)); } } } } }}
Forex Groups - Tips on Trading
Related article:
http://blog.sina.com.cn/s/blog_48e24b4c01000cuk.html
comments | Add comment | Report as Spam
|
"????????????" posted by ~Ray
Posted on 2007-12-09 13:41:22 |
import java awt.*;import java awt event.*;import javax swing.*; public categorise Calculator extends WindowAdapterimplements ActionListener{ JFrame f; JTextField tf; Buttonb1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18 b19,b20,b21,b22; JPanel p1,p2,p3,p4,p5,p6; manifold n1=0,n2=0; int Oper=1; // 记录运算符类型 intn=0; //记载小数位数 intk=0; //记录总共输入的位数 boolean isResult=false,//是否在计算出结果后直接按运算符将结果赋给了当前输入值? isDot=false. //已经有小数点? isEqual=false. //是否按下过"="? isKey=adjust; //是否输入了数字? publicCalculator() { f=newJFrame("函数计算器"); tf=new JTextField(15); tf setText("0."); tf setBackground(Color white); tf setEditable(false); f setBackground(Color. lighten_GRAY); JButton b1=new JButton("1"); JButton b2=new JButton("2"); JButton b3=new JButton("3"); JButton b4=new JButton("4"); JButton b5=new JButton("5"); JButton b6=new JButton("6"); JButton b7=new JButton("7"); JButton b8=new JButton("8"); JButton b9=new JButton("9"); JButton b10=new JButton("0"); JButton b11=new JButton("."); JButton b12=new JButton(" = "); JButton b13=new JButton("+"); JButton b14=new JButton("-"); JButton b15=new JButton("*"); JButton b16=new JButton("/"); JButton b17=new JButton("sin"); JButton b18=new JButton("cos"); JButton b19=new JButton("sqrt"); JButton b20=new JButton(" +/- "); JButton b21=new JButton("<html><fontcolor=color>重置"); JButton b22=new JButton("<html><fontcolor=red>清零"); b1 addActionListener(this); b2 addActionListener(this); b3 addActionListener(this); b4 addActionListener(this); b5 addActionListener(this); b6 addActionListener(this); b7 addActionListener(this); b8 addActionListener(this); b9 addActionListener(this); b10 addActionListener(this); b11 addActionListener(this); b12 addActionListener(this); b13 addActionListener(this); b14 addActionListener(this); b15 addActionListener(this); b16 addActionListener(this); b17 addActionListener(this); b18 addActionListener(this); b19 addActionListener(this); b20 addActionListener(this); b21 addActionListener(this); b22 addActionListener(this); JPanel p1=new JPanel(); p1 add(b7 ); p1 add(b8); p1 add(b9); p1 add(b13); p1 add(b17); JPanel p2=new JPanel(); p2 add(b4); p2 add(b5); p2 add(b6); p2 add(b14); p2 add(b18); JPanel p3=new JPanel(); p3 add(b1); p3 add(b2); p3 add(b3); p3 add(b15); p3 add(b19); JPanel p4=new JPanel(); p4 add(b10); p4 add(b11); p4 add(b12); p4 add(b16); p4 add(b20); JPanel p5=new JPanel(); p5 add(p1); p5 add(p2); p5 add(p3); p5 add(p4); JPanel p6=new JPanel(); p6 add(b21); p6 add(b22); JPanel p7=new JPanel(); p7 add(tf); f setLayout(newBorderLayout(3,3)); f add(p7,BorderLayout. NORTH); f add(p5,BorderLayout. bear on); f add(p6,BorderLayout. SOUTH); f setSize(300,300); f setVisible(true); f addWindowListener(this); } public static void main(arrange args[]) { new Calculator(); } public cancel windowClosing(WindowEvent e) { System move(0); } public void actionPerfromed(ActionEvent e) { //key 0 to 9 if(isKey&&e getActionCommand() length()==1&& e getActionCommand() compareTo("0")>=0 &&e getActionCommand() compareTo("9")<=0) { if(isResult) { n1=0; isResult=false; } k++; if(isDot==false) { n1=n1*10+Double parseDouble(e getActionCommand()); } else { doubletemp=Double parseDouble(e getActionCommand()); for(int i=n;i<0;i++) { temp*=0.1; } n1+=temp; n--; } tf setText(Double toString(n1)); } // keydot if(isKey && e getActionCommand()==".") { if(isDot==false) { k++; isDot=true; n=-1; } } //key "+","-","*","/" if(isKey&&e getActionCommand()=="+"||e getActionCommand()=="-"|| e getActionCommand()=="*"||e getActionCommand()=="/") { if(isEqual) { n1=n2; isResult=adjust; } else { change by reversal(Oper) { inspect 1: n2+=n1; end; case 2: n2-=n1; end; case 3: n2*=n1; break; case 4: { if(n1==0) { tf setText("除数不能为零"); this isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(manifold toString(n2)); n1=0; } if(e getActionCommand()=="+") { this. Oper=1; } if(e getActionCommand()=="-") { this. Oper=2; } if(e getActionCommand()=="*") { this. Oper=3; } if(e getActionCommand()=="/") { this. Oper=4; } k=0; this isEqual=false; } // key "+/-" if(isKey && e getActionCommand()==" +/-") { n1=0-n1; tf setText(Double toString(n1)); } // key "=" if(isKey && e getActionCommand()==" = ") { isEqual=adjust; change by reversal(Oper) { case 1: n2+=n1; break; inspect 2: n2-=n1; break; case 3: n2*=n1; break; inspect 4: { if(n1==0) { tf setText("除数不能为零"); isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(Double toString(n2)); } // key"sin" if(isKey &&e getActionCommand()=="sin") { if(isEqual) { n2=Math sin(n2); tf setText(Double toString(n2)); } else { n1=Math sin(n1); tf setText(Double toString(n1)); } } // key "cos" if(isKey &&e getActionCommand()=="cos") { if(isEqual) { n2=Math cos(n2); tf setText(Double toString(n2)); } else { n1=Math cos(n1); tf setText(Double toString(n1)); } } // key "sqrt" if(isKey &&e getActionCommand()=="sqrt") { if(isEqual) { if(n2>=0) { n2=Math sqrt(n2); tf setText(Double toString(n2)); } else { tf setText("函数输入无效"); isKey=false; } } else { if(n1>=0) { n1=Math sqrt(n1); tf setText(manifold toString(n1)); } else { tf setText("函数输入无效"); isKey=false; } } } // key"清零" if(e getActionCommand()=="<html><fontcolor=red>清零") { this k=0; this n2=0; this n1=0; this isDot=false; this n=0; this. Oper=1; this isKey=true; this isEqual=false; tf setText("0."); } //key "重置" if(isKey &&e getActionCommand()=="<html><fontcolor=color>重置") { if(!isEqual){ if(n1!=0) { if(isDot) { if(n==-1) { isDot=false; n=0; } else { String str,str1; str=tf getText(); str1=str substring(0,k-1); k--; n++; n1=Double parseDouble(str1); tf setText(manifold toString(n1)); } } else { int temp; temp=(int)(n1/10); n1=(manifold)temp; tf setText(manifold toString(n1)); } } } } }}
Forex Groups - Tips on Trading
Related article:
http://blog.sina.com.cn/s/blog_48e24b4c01000cuk.html
comments | Add comment | Report as Spam
|
"????????????" posted by ~Ray
Posted on 2007-12-09 13:41:22 |
import java awt.*;import java awt event.*;merchandise javax swing.*; public class Calculator extends WindowAdapterimplements ActionListener{ JFrame f; JTextField tf; Buttonb1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18 b19,b20,b21,b22; JPanel p1,p2,p3,p4,p5,p6; manifold n1=0,n2=0; int Oper=1; // 记录运算符类型 intn=0; //记载小数位数 intk=0; //记录总共输入的位数 boolean isResult=false,//是否在计算出结果后直接按运算符将结果赋给了当前输入值? isDot=false. //已经有小数点? isEqual=false. //是否按下过"="? isKey=true; //是否输入了数字? publicCalculator() { f=newJFrame("函数计算器"); tf=new JTextField(15); tf setText("0."); tf setBackground(Color white); tf setEditable(false); f setBackground(alter. LIGHT_color); JButton b1=new JButton("1"); JButton b2=new JButton("2"); JButton b3=new JButton("3"); JButton b4=new JButton("4"); JButton b5=new JButton("5"); JButton b6=new JButton("6"); JButton b7=new JButton("7"); JButton b8=new JButton("8"); JButton b9=new JButton("9"); JButton b10=new JButton("0"); JButton b11=new JButton("."); JButton b12=new JButton(" = "); JButton b13=new JButton("+"); JButton b14=new JButton("-"); JButton b15=new JButton("*"); JButton b16=new JButton("/"); JButton b17=new JButton("sin"); JButton b18=new JButton("cos"); JButton b19=new JButton("sqrt"); JButton b20=new JButton(" +/- "); JButton b21=new JButton("<html><fontcolor=blue>重置"); JButton b22=new JButton("<html><fontcolor=red>清零"); b1 addActionListener(this); b2 addActionListener(this); b3 addActionListener(this); b4 addActionListener(this); b5 addActionListener(this); b6 addActionListener(this); b7 addActionListener(this); b8 addActionListener(this); b9 addActionListener(this); b10 addActionListener(this); b11 addActionListener(this); b12 addActionListener(this); b13 addActionListener(this); b14 addActionListener(this); b15 addActionListener(this); b16 addActionListener(this); b17 addActionListener(this); b18 addActionListener(this); b19 addActionListener(this); b20 addActionListener(this); b21 addActionListener(this); b22 addActionListener(this); JPanel p1=new JPanel(); p1 add(b7 ); p1 add(b8); p1 add(b9); p1 add(b13); p1 add(b17); JPanel p2=new JPanel(); p2 add(b4); p2 add(b5); p2 add(b6); p2 add(b14); p2 add(b18); JPanel p3=new JPanel(); p3 add(b1); p3 add(b2); p3 add(b3); p3 add(b15); p3 add(b19); JPanel p4=new JPanel(); p4 add(b10); p4 add(b11); p4 add(b12); p4 add(b16); p4 add(b20); JPanel p5=new JPanel(); p5 add(p1); p5 add(p2); p5 add(p3); p5 add(p4); JPanel p6=new JPanel(); p6 add(b21); p6 add(b22); JPanel p7=new JPanel(); p7 add(tf); f setLayout(newBorderLayout(3,3)); f add(p7,BorderLayout. NORTH); f add(p5,BorderLayout. CENTER); f add(p6,BorderLayout. SOUTH); f setSize(300,300); f setVisible(true); f addWindowListener(this); } public static void main(String args[]) { new Calculator(); } public cancel windowClosing(WindowEvent e) { System exit(0); } public cancel actionPerfromed(ActionEvent e) { //key 0 to 9 if(isKey&&e getActionCommand() length()==1&& e getActionCommand() compareTo("0")>=0 &&e getActionCommand() compareTo("9")<=0) { if(isResult) { n1=0; isResult=false; } k++; if(isDot==false) { n1=n1*10+manifold parseDouble(e getActionCommand()); } else { doubletemp=manifold parseDouble(e getActionCommand()); for(int i=n;i<0;i++) { temp*=0.1; } n1+=temp; n--; } tf setText(manifold toString(n1)); } // keydot if(isKey && e getActionCommand()==".") { if(isDot==false) { k++; isDot=true; n=-1; } } //key "+","-","*","/" if(isKey&&e getActionCommand()=="+"||e getActionCommand()=="-"|| e getActionCommand()=="*"||e getActionCommand()=="/") { if(isEqual) { n1=n2; isResult=adjust; } else { change by reversal(Oper) { inspect 1: n2+=n1; break; case 2: n2-=n1; break; case 3: n2*=n1; break; case 4: { if(n1==0) { tf setText("除数不能为零"); this isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(Double toString(n2)); n1=0; } if(e getActionCommand()=="+") { this. Oper=1; } if(e getActionCommand()=="-") { this. Oper=2; } if(e getActionCommand()=="*") { this. Oper=3; } if(e getActionCommand()=="/") { this. Oper=4; } k=0; this isEqual=false; } // key "+/-" if(isKey && e getActionCommand()==" +/-") { n1=0-n1; tf setText(Double toString(n1)); } // key "=" if(isKey && e getActionCommand()==" = ") { isEqual=true; change by reversal(Oper) { inspect 1: n2+=n1; break; inspect 2: n2-=n1; end; inspect 3: n2*=n1; break; inspect 4: { if(n1==0) { tf setText("除数不能为零"); isKey=false; } else n2=n2/n1; } } if(isKey) tf setText(manifold toString(n2)); } // key"sin" if(isKey &&e getActionCommand()=="sin") { if(isEqual) { n2=Math sin(n2); tf setText(Double toString(n2)); } else { n1=Math sin(n1); tf setText(manifold toString(n1)); } } // key "cos" if(isKey &&e getActionCommand()=="cos") { if(isEqual) { n2=Math cos(n2); tf setText(manifold toString(n2)); } else { n1=Math cos(n1); tf setText(Double toString(n1)); } } // key "sqrt" if(isKey &&e getActionCommand()=="sqrt") { if(isEqual) { if(n2>=0) { n2=Math sqrt(n2); tf setText(Double toString(n2)); } else { tf setText("函数输入无效"); isKey=false; } } else { if(n1>=0) { n1=Math sqrt(n1); tf setText(Double toString(n1)); } else { tf setText("函数输入无效"); isKey=false; } } } // key"清零" if(e getActionCommand()=="<html><fontcolor=red>清零") { this k=0; this n2=0; this n1=0; this isDot=false; this n=0; this. Oper=1; this isKey=adjust; this isEqual=false; tf setText("0."); } //key "重置" if(isKey &&e getActionCommand()=="<html><fontcolor=color>重置") { if(!isEqual){ if(n1!=0) { if(isDot) { if(n==-1) { isDot=false; n=0; } else { arrange str,str1; str=tf getText(); str1=str substring(0,k-1); k--; n++; n1=Double parseDouble(str1); tf setText(Double toString(n1)); } } else { int temp; temp=(int)(n1/10); n1=(double)temp; tf setText(Double toString(n1)); } } } } }}
Forex Groups - Tips on Trading
Related article:
http://blog.sina.com.cn/s/blog_48e24b4c01000cuk.html
comments | Add comment | Report as Spam
|
"Java Help" posted by ~Ray
Posted on 2007-11-17 15:58:39 |
I am trying to get this code example to run properly. I have been looking at this too desire and I can't see the problem. I am not seeing where the Jlabel output is being displayed or more so why it is not being ouput. Also the display Joptionpane is not coming up either. Thanks in go for any suggestions below is my code.
import java awt. Container;import java awt. FlowLayout;merchandise java awt event. ActionEvent;merchandise java awt event. ActionListener;import java awt event. WindowAdapter;import java awt event. WindowEvent;merchandise java util. Enumeration;import java util. NoSuchElementException;import java util. Vector;import javax swing. JButton;import javax swing. JFrame;import javax swing. JLabel;merchandise javax swing. JOptionPane;merchandise javax swing. JTextField;public class FirstNameList extends JFrame{private static final long serialVersionUID = 1L;public FirstNameList(){super("FirstNameList");final JLabel status = new JLabel();final Container c = getContentPane();final Vector<String> v = new Vector<String>(1);c setLayout(new FlowLayout());c add(new JLabel ("register a String"));final JTextField input = new JTextField(10);c add(input);// addfinal JButton addBtn = new JButton ("Add");addBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public cancel ActionPerformed(final ActionEvent e){v addElement(input getText());status setText("Added to end : " + input getText());enter setText("");}public cancel actionPerformed(final ActionEvent e) {}});c add(addBtn);// removefinal JButton removeBtn = new JButton ("Remove");removeBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public void ActionPerformed(final ActionEvent e){if(v removeElement(enter getText())){status setText("Removed: " + input getText());}else{status setText(enter getText() + " not in vector");}}public void actionPerformed(final ActionEvent e) {}});c add(removeBtn);// firstfinal JButton firstBtn = new JButton ("First");firstBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public void ActionPerformed(final ActionEvent e){try{status setText("First Element: " + v firstElement());}catch(final NoSuchElementException exception){status setText(exception toString());}}public cancel actionPerformed(final ActionEvent e) {}});c add(firstBtn);// lastfinal JButton lastBtn = new JButton ("Last");lastBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public cancel ActionPerformed(final ActionEvent e){try{status setText("Last Element: " + v lastElement());}catch(final NoSuchElementException exception){status setText(exception toString());}}public void actionPerformed(final ActionEvent e) {}});c add(lastBtn);// emptyfinal JButton emptyBtn = new JButton ("Is alter");emptyBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public cancel ActionPerformed(final ActionEvent e){status setText(v isEmpty() ?"Vector is alter" : "Vector in not alter");}public void actionPerformed(final ActionEvent e) {}});c add(emptyBtn);// containsfinal JButton containsBtn = new JButton ("Contains");containsBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public void ActionPerformed(final ActionEvent e){final arrange searchKey = input getText();if(v contains(searchKey)){status setText("Vector contains: " + searchKey);}else{status setText("Vector does not contain " + searchKey);}}public cancel actionPerformed(final ActionEvent e) {}});c add(containsBtn);// Locationfinal JButton locationBtn = new JButton ("Location");emptyBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public void ActionPerformed(final ActionEvent e){status setText("Element is at location " +v indexOf(input getText()));}public cancel actionPerformed(final ActionEvent e) {}});c add(locationBtn);// Trimfinal JButton trimBtn = new JButton ("cut");trimBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public cancel ActionPerformed(final ActionEvent e){v trimToSize();status setText("Vector trimmed to size");}public cancel actionPerformed(final ActionEvent e) {}});c add(trimBtn);// Displayfinal JButton displayBtn = new JButton ("Display");displayBtn addActionListener(new ActionListener(){@SuppressWarnings("unused")public cancel ActionPerformed(final ActionEvent e){final Enumeration<String> enumx = v elements();final StringBuffer buf = new StringBuffer();while(enumx hasMoreElements()){buf append(enumx nextElement() ) append( " " );JOptionPane showMessageDialog(null buf toString(). "Display",JOptionPane. PLAIN_MESSAGE);}}public void actionPerformed(final ActionEvent e) {}});c add(displayBtn);c add(status);setSize(300. 200);setVisible(adjust);}public static void main(final String args[]){final FirstNameList app = new FirstNameList();app addWindowListener(new WindowAdapter(){public cancel windowClosing(final WindowEvent e){System exit(0);}});}}
My fault,public void actionPerformed(ActionEvent e)It was a simple capitalization,actionPerformed(.. notActionPerformed(... Thanks again it works book now.
My fault,public void actionPerformed(ActionEvent e)It was a simple capitalization,actionPerformed(.. notActionPerformed(... Thanks again it works fine now.
If you are so for 'individual rights' and 'freedom' why are you letting DoJ help the Recording Industry Ass of America? Food for thought...
and Windows XP | Apple iMac/20" (New brushed-aluminum enclosure). 2GB DDR2. Mac OS X 10.4.10 | Athlon Thunderbird 1.0GHz. 384MB.
Copyright © OCForums com 2001 - 2007. All Rights Reserved. Visit: . Other iNET Interactive Sites: | | | | | | Powered by vBulletin® Version 3.6.8procure ©2000 - 2007. Jelsoft Enterprises Ltd.
Forex Groups - Tips on Trading
Related article:
http://www.ocforums.com/showthread.php?t=532725
comments | Add comment | Report as Spam
|
"BlackJackApplet Class" posted by ~Ray
Posted on 2007-11-09 17:21:32 |
object performs all the actions of the game. The Player is given the option to “hit” or “stay” while the Dealer must “stay” if their transfer is seventeen or greater. act upon wins over all other Hands. If both Player and Dealer undergo the same transfer the go ends in a displace(tie). I’ve defined the be of Players to be one for simplicity. @author: Tommy Flewwelling @version: 1.00 Creation Date: 2007/07/17*/categorise BlackJackGame extends beg implements ActionListener{ //---------------------------------------------------------------------------// be the initial number of cards needed for a Hand of act upon public static final int INIT_SIZE_BLACKJACK_HAND = 2;// Constants used throughout the schedule public static final int HIT = 0. be = 1. adjust = 0. SET = 1. DEFAULT = -1. PLAYER = 0. DEALER = 1. act upon = 21. TWENTY_ONE = 21. EMPTY = 0; // Define the number of Players as one - for simplicity public static final int be_OF_PLAYERS = 1;// The lowest and highest transfer of BlackJack that can be dealt - used to cause if the Dealer should "Hit" or "be" public static final int act upon_LOW = 4. BLACKJACK_HIGH = 17; // Set if Player obtains BlackJack on first draw int blackJackFlag = fail; // Tally number of rounds played wins losses and ties of both Dealer and Player public int playerWinTally = adjust dealerWinTally = adjust playerLostTally = adjust dealerLostTally = ZERO tieTally = ZERO roundTally = adjust;// say the status of the game boolean gameInProgress = false;// Display communicate. arrange show;// Font for displaying messages. Font font; /** A Card disapprove. */private Card separate; /** A Deck object. */private be be; /** A Hand disapprove. */private transfer[] hand;/** A BlackJackHand disapprove for the Player. */private BlackJackHand playersHand;/** A BlackJackHand object for the Dealer. */private BlackJackHand dealersHand;/** A HashMap disapprove. */private HashMap mapCards;/** An Image object. */private visualise cardImage;//---------------------------------------------------------------------------/** Sets accent alter initializes fonts creates a hashmap and begins the game.*/BlackJackGame(){// Set accent alter setBackground(Color. color darker() darker());// Set font font = new Font("Serif". Font. BOLD. 14);// Mapping of Cards to their visualise mapCards = new HashMap(); try{ // Clubs. mapCards put(new separate(2,0). ImageIO read(new java net. URL(getCodeBase(),"cards/2c gif"))); mapCards put(new Card(3,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/3c gif"))); mapCards put(new separate(4,0). ImageIO read(new java net. URL(getCodeBase(),"cards/4c gif"))); mapCards put(new separate(5,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/5c gif"))); mapCards put(new separate(6,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/6c gif"))); mapCards put(new Card(7,0). ImageIO read(new java net. URL(getCodeBase(),"cards/7c gif"))); mapCards put(new separate(8,0). ImageIO read(new java net. URL(getCodeBase(),"cards/8c gif"))); mapCards put(new separate(9,0). ImageIO read(new java net. URL(getCodeBase(),"cards/9c gif"))); mapCards put(new separate(10,0). ImageIO read(new java net. URL(getCodeBase(),"cards/tc gif"))); mapCards put(new separate(11,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/jc gif"))); mapCards put(new Card(12,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/qc gif"))); mapCards put(new Card(13,0). ImageIO read(new java net. URL(getCodeBase(),"cards/kc gif"))); mapCards put(new separate(14,0). ImageIO construe(new java net. URL(getCodeBase(),"cards/ac gif"))); // Spades. mapCards put(new separate(2,1). ImageIO read(new java net. URL(getCodeBase(),"cards/2s gif"))); mapCards put(new Card(3,1). ImageIO read(new java net. URL(getCodeBase(),"cards/3s gif"))); mapCards put(new separate(4,1). ImageIO construe(new java net. URL(getCodeBase(),"cards/4s gif"))); mapCards put(new Card(5,1). ImageIO construe(new java net. URL(getCodeBase(),"cards/5s gif"))); mapCards put(new separate(6,1). ImageIO construe(new java net. URL(getCodeBase(),"cards/6s gif"))); mapCards put(new separate(7,1). ImageIO read(new java net. URL(getCodeBase(),"cards/7s gif"))); mapCards put(new Card(8,1). ImageIO read(new java net. URL(getCodeBase(),"cards/8s gif"))); mapCards put(new separate(9,1). ImageIO read(new java net. URL(getCodeBase(),"cards/9s gif"))); mapCards put(new Card(10,1),ImageIO construe(new java net. URL(getCodeBase(),"cards/ts gif"))); mapCards put(new Card(11,1),ImageIO read(new java net. URL(getCodeBase(),"cards/js gif"))); mapCards put(new Card(12,1),ImageIO construe(new java net. URL(getCodeBase(),"cards/qs gif"))); mapCards put(new separate(13,1),ImageIO read(new java net. URL(getCodeBase(),"cards/ks gif"))); mapCards put(new separate(14,1),ImageIO construe(new java net. URL(getCodeBase(),"cards/as gif"))); // Hearts mapCards put(new Card(2,2). ImageIO construe(new java net. URL(getCodeBase(),"cards/2h gif"))); mapCards put(new Card(3,2). ImageIO construe(new java net. URL(getCodeBase(),"cards/3h gif"))); mapCards put(new separate(4,2). ImageIO construe(new java net. URL(getCodeBase(),"cards/4h gif"))); mapCards put(new separate(5,2). ImageIO read(new java net. URL(getCodeBase(),"cards/5h gif"))); mapCards put(new separate(6,2). ImageIO construe(new java net. URL(getCodeBase(),"cards/6h gif"))); mapCards put(new Card(7,2). ImageIO read(new java net. URL(getCodeBase(),"cards/7h gif"))); mapCards put(new separate(8,2). ImageIO read(new java net. URL(getCodeBase(),"cards/8h gif"))); mapCards put(new separate(9,2). ImageIO construe(new java net. URL(getCodeBase(),"cards/9h gif"))); mapCards put(new separate(10,2),ImageIO construe(new java net. URL(getCodeBase(),"cards/th gif"))); mapCards put(new Card(11,2),ImageIO construe(new java net. URL(getCodeBase(),"cards/jh gif"))); mapCards put(new Card(12,2),ImageIO read(new java net. URL(getCodeBase(),"cards/qh gif"))); mapCards put(new separate(13,2),ImageIO construe(new java net. URL(getCodeBase(),"cards/kh gif"))); mapCards put(new Card(14,2),ImageIO construe(new java net. URL(getCodeBase(),"cards/ah gif"))); // Dimonds mapCards put(new Card(2,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/2d gif"))); mapCards put(new Card(3,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/3d gif"))); mapCards put(new Card(4,3). ImageIO read(new java net. URL(getCodeBase(),"cards/4d gif"))); mapCards put(new separate(5,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/5d gif"))); mapCards put(new separate(6,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/6d gif"))); mapCards put(new separate(7,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/7d gif"))); mapCards put(new separate(8,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/8d gif"))); mapCards put(new separate(9,3). ImageIO construe(new java net. URL(getCodeBase(),"cards/9d gif"))); mapCards put(new Card(10,3),ImageIO read(new java net. URL(getCodeBase(),"cards/td gif"))); mapCards put(new Card(11,3),ImageIO read(new java net. URL(getCodeBase(),"cards/jd gif"))); mapCards put(new Card(12,3),ImageIO read(new java net. URL(getCodeBase(),"cards/qd gif"))); mapCards put(new Card(13,3),ImageIO construe(new java net. URL(getCodeBase(),"cards/kd gif"))); mapCards put(new Card(14,3),ImageIO construe(new java net. URL(getCodeBase(),"cards/ad gif"))); // Face-down card mapCards put(1,ImageIO read(new java net. URL(getCodeBase(),"cards/blueCard gif"))); // Catch exception if one occurs. }catch (java net. MalformedURLException me){System out println("Image not open!"); JOptionPane showMessageDialog(this. "Image not found!"); }surprise (IOException.
Forex Groups - Tips on Trading
Related article:
http://adishofjava.blogspot.com/2007/08/blackjackapplet-class.html
comments | Add comment | Report as Spam
|
"((JButton)e.getSource()).getText(); t.setText(name + ? (Java web ..." posted by ~Ray
Posted on 2007-11-03 13:52:55 |
((JButton)e getSource()) getText(); t setText(name + ” Pressed”); } }; b1 addActionListener(al); add(b1); b2 addActionListener(al); add(b2); add(t); } public static cancel main(String args[]) { JButtonDemo applet = new JButtonDemo(); JFrame frame = new JFrame(”TextAreaNew”); close in addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System move(0); } }); frame getContentPane() add( applet. BorderLayout. bear on); frame setSize(300,100); applet init(); applet start(); frame setVisible(adjust); } } ///:~ There s a new import statement but everything else looks like the Java 1.1 AWT with the addition of some J s. Also you don t just add( ) something to a Swing JFrame but you must get the content pane first as seen above. But you can easily get many of the benefits of displace with a simple conversion. Because of the package statement you ll have to create this program by saying: java c13 displace. JbuttonDemo All of the programs in this section ordain require a similar create to run them. A display framework Although the programs that are both applets and applications can be valuable if used everywhere they become distracting and expend cover. Instead a display framework will be used for the displace examples in the rest of this section: //: show java // Tool for displaying Swing demos case c13 swing; merchandise java awt.*; import java awt event.*; merchandise com sun java displace.*; public class Show { public static cancel inFrame(JPanel jp int width int height) { Thinking in Java www. BruceEckel com If you are looking for cheap and quality webhost to host and run your website analyse services.
Forex Groups - Tips on Trading
Related article:
http://mysql.wikiwebsitehosting.com/mysql/jbuttonegetsourcegettext-tsettextname-java-web-server-pressed-b1addactionlisteneral/
comments | Add comment | Report as Spam
|
"((JButton)e.getSource()).getText(); t.setText(name + ? (Java web ..." posted by ~Ray
Posted on 2007-11-03 13:52:49 |
((JButton)e getSource()) getText(); t setText(name + ” Pressed”); } }; b1 addActionListener(al); add(b1); b2 addActionListener(al); add(b2); add(t); } public static cancel main(arrange args[]) { JButtonDemo applet = new JButtonDemo(); JFrame frame = new JFrame(”TextAreaNew”); close in addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System move(0); } }); frame getContentPane() add( applet. BorderLayout. CENTER); close in setSize(300,100); applet init(); applet go away(); close in setVisible(true); } } ///:~ There s a new import statement but everything else looks desire the Java 1.1 AWT with the addition of some J s. Also you don t just add( ) something to a Swing JFrame but you must get the content pane first as seen above. But you can easily get many of the benefits of displace with a simple conversion. Because of the case statement you ll have to invoke this program by saying: java c13 swing. JbuttonDemo All of the programs in this section will demand a similar create to run them. A display framework Although the programs that are both applets and applications can be valuable if used everywhere they become distracting and expend cover. Instead a show framework ordain be used for the Swing examples in the rest of this section: //: show java // Tool for displaying Swing demos package c13 swing; merchandise java awt.*; import java awt event.*; import com sun java displace.*; public class show { public static void inFrame(JPanel jp int width int height) { Thinking in Java www. BruceEckel com If you are looking for cheap and quality webhost to host and run your website check services.
Forex Groups - Tips on Trading
Related article:
http://mysql.wikiwebsitehosting.com/mysql/jbuttonegetsourcegettext-tsettextname-java-web-server-pressed-b1addactionlisteneral/
comments | Add comment | Report as Spam
|
"ceva java" posted by ~Ray
Posted on 2007-10-28 11:50:42 |
JButton b1 = new JButton(“Poll”);
b1 setActionCommand(“poll”);
b2 setActionCommand(“offer”);
JButton b3 = new JButton(“Element”);
b3 setActionCommand(“element”);
b4 setActionCommand(“peek”);
b5 setActionCommand(“shift”);
b6 setActionCommand(“add”);
create(/*”S-a executat add in coada: ” +*/ textField getText());
else if(“element” equals(e getActionCommand())){
JFrame frame = new JFrame(“Coada Generica”);
frame setDefaultCloseOperation(JFrame.
Container contentPane = frame getContentPane();
contentPane add(show createButtonPane(),BorderLayout.
——————————————————————-
———————————————————————————————-
————————————————————–
void displace (T item)throws StackOverflow;
T element()throws StackEmpty;
public StackOverflow() {}
public StackOverflow(arrange msg) {
public StackEmpty(String msg) {
stiva =(T[])new Object[dim];
this dim=dim;
public void displace(T item) throws StackOverflow {
throw new StackOverflow(“Stiva plina”);
stiva[++k]=item;
go false;
stiva[++k]=item;
return true;
public T element() throws StackEmpty {
impel new StackEmpty(“Stiva goala”);
go stiva[k];
return null;
else go stiva[k];
public T pop() throws StackEmpty {
throw new StackEmpty(“Stiva goala”);
return stiva[k–];
return null;
else go stiva[k–];
—————————————————————-
public class MainFrame extends WindowAdapter implements ActionListener {
private int maxX = 500;
private int maxY = 500;
protected JTextField textField;
Stack<String> stiva = new lade<String>(10);
//initializare MainFrame
public MainFrame() {
mark screenSize = Toolkit.
maxX = screenSize width - 50;
maxY = screenSize height - 50;
protected JComponent createButtonPane() {
JButton b1 = new JButton(“survey”);
b1 setActionCommand(“poll”);
b1 addActionListener(this);
JButton b2 = new JButton(“Offer”);
b2 setActionCommand(“offer”);
b2 addActionListener(this);
JButton b3 = new JButton(“Element”);
b3 setActionCommand(“element”);
b3 addActionListener(this);
JButton b4 = new JButton(“Peek”);
b4 setActionCommand(“peek”);
b4 addActionListener(this);
JButton b5 = new JButton(“Pop”);
b5 setActionCommand(“pop”);
b5 addActionListener(this);
JButton b6 = new JButton(“Push”);
b6 setActionCommand(“push”);
b6 addActionListener(this);
textField = new JTextField(20);
textField addActionListener(this);
//adorn cu butoane
JPanel pane = new JPanel();
pane setBorder(BorderFactory.
pane add(b2);
pane add(b3);
pane add(b4);
.
Forex Groups - Tips on Trading
Related article:
http://mariachi7.wordpress.com/2007/09/07/ceva-java/
comments | Add comment | Report as Spam
|
"ceva java" posted by ~Ray
Posted on 2007-10-28 11:50:41 |
JButton b1 = new JButton(“survey”);
b1 setActionCommand(“poll”);
b2 setActionCommand(“offer”);
JButton b3 = new JButton(“Element”);
b3 setActionCommand(“element”);
b4 setActionCommand(“look”);
b5 setActionCommand(“remove”);
b6 setActionCommand(“add”);
print(/*”S-a executat add in coada: ” +*/ textField getText());
else if(“element” equals(e getActionCommand())){
JFrame close in = new JFrame(“Coada Generica”);
frame setDefaultCloseOperation(JFrame.
Container contentPane = close in getContentPane();
contentPane add(demo createButtonPane(),BorderLayout.
——————————————————————-
———————————————————————————————-
————————————————————–
void push (T item)throws StackOverflow;
T element()throws StackEmpty;
public StackOverflow() {}
public StackOverflow(arrange msg) {
public StackEmpty(arrange msg) {
stiva =(T[])new Object[dim];
this dim=dim;
public cancel push(T item) throws StackOverflow {
impel new StackOverflow(“Stiva plina”);
stiva[++k]=item;
go false;
stiva[++k]=item;
go adjust;
public T element() throws StackEmpty {
impel new StackEmpty(“Stiva goala”);
return stiva[k];
go null;
else return stiva[k];
public T pop() throws StackEmpty {
throw new StackEmpty(“Stiva goala”);
return stiva[k–];
return null;
else return stiva[k–];
—————————————————————-
public class MainFrame extends WindowAdapter implements ActionListener {
private int maxX = 500;
private int maxY = 500;
protected JTextField textField;
Stack<String> stiva = new Stack<String>(10);
//initializare MainFrame
public MainFrame() {
Dimension screenSize = Toolkit.
maxX = screenSize width - 50;
maxY = screenSize height - 50;
protected JComponent createButtonPane() {
JButton b1 = new JButton(“survey”);
b1 setActionCommand(“survey”);
b1 addActionListener(this);
JButton b2 = new JButton(“Offer”);
b2 setActionCommand(“offer”);
b2 addActionListener(this);
JButton b3 = new JButton(“Element”);
b3 setActionCommand(“element”);
b3 addActionListener(this);
JButton b4 = new JButton(“look”);
b4 setActionCommand(“look”);
b4 addActionListener(this);
JButton b5 = new JButton(“Pop”);
b5 setActionCommand(“pop”);
b5 addActionListener(this);
JButton b6 = new JButton(“displace”);
b6 setActionCommand(“push”);
b6 addActionListener(this);
textField = new JTextField(20);
textField addActionListener(this);
//panel cu butoane
JPanel pane = new JPanel();
pane setBorder(BorderFactory.
pane add(b2);
pane add(b3);
pane add(b4);
.
Forex Groups - Tips on Trading
Related article:
http://mariachi7.wordpress.com/2007/09/07/ceva-java/
comments | Add comment | Report as Spam
|
"conseils pour bien programmer en Java" posted by ~Ray
Posted on 2007-10-23 15:48:25 |
Bonjour,Je me mets Java displace r-crire un create by mental act VB. J'utilise la Javadoc. Eclipse comme EDI et "Introduction Java" de chez O'REILLY ainsi que "displace la synthse" de chez Dunod.. et bien entendu le site developpez com. Je n'arrive pas savoir si la faon dont je create by mental act est bonne (mme si le programme fait ce que j'attends de lui). J'ai vu lors des discussions que plusieurs d'entre vous aidaient de leurs conseils les dbutants. Je vous soumets la classe suivante. Pouvez-vous me dire s'il y a des erreurs de conception. Merci.
package histoire; import javax swing. ButtonGroup;import javax displace. JCheckBoxMenuItem; import javax displace. JFrame;merchandise javax swing. JMenu;merchandise javax swing. JMenuItem;import javax displace. JOptionPane;import javax swing. JRadioButtonMenuItem;import javax displace. JMenuBar;import javax swing. JPanel;merchandise javax displace adjoin.*;import javax displace. JScrollBar; import java awt event. ActionEvent;merchandise java awt event. ActionListener;import java awt event. WindowAdapter;import java awt event. WindowEvent;merchandise java awt.*;merchandise javax swing.*; /** * @compose PATRICE * */public class FormeHistoire extends JFrame {public static final long serialVersionUID= 1;private static final arrange TITRE = "Histoire mondiale";private transient static FormeHistoire fen =null;//le menuprivate JMenuBar menu = new JMenuBar();//le panneau central// gauche//la carteprivate JPanel carte=new JPanel();//le scrollbar latitudeprivate JScrollBar scrLatitude=new JScrollBar(JScrollBar. VERTICAL);//le scrollbar longitudeprivate JScrollBar scrLongitude= new JScrollBar(JScrollBar. HORIZONTAL);//le bouton loupeprivate JButton btnLoupe=new JButton();private JPanel gauche=new JPanel();// droiteprivate WebBrowser droit;private JSplitPane centre=new JSplitPane(JSplitPane. HORIZONTAL_change integrity);//le panneau sud//la barre d'tatprivate JPanel barreEtat=new JPanel();//le scrollbar datesprivate JScrollBar scbDate = new JScrollBar(JScrollBar. HORIZONTAL);private JPanel sud = new JPanel();public static FormeHistoire getInstance(){if (fen==null){fen=new FormeHistoire();}go fen;}protected FormeHistoire(){//challenge prvue la fermetureaddWindowListener(new WindowAdapter(){public cancel windowClosing(WindowEvent e){fermerApplication();}});//taille de la fentresetExtendedState(JFrame. MAXIMIZED_BOTH);Rectangle taille=Fonctions trouverDimensionFen(this);setLocation(taille x,taille y);setPreferredSize(new Dimension(taille width,taille height));//la taille sur cet ordinateur c'est 1032x742//installation du menu sa hauteur = 23 la hauteur utile devient 719 initialiserMenus();//installation du bas : barre d'tat et scroll dates sa hauteur 37,//la hauteur utile devient 682initialiserSud(); ////la carte ses scrolls son bouton et le WB//la hauteur de la carte (et ses contrles) c'est 682 setTitle(TITRE);initialiserCentre();setVisible(adjust);repaint();}private cancel initialiserCentre(){centre setDividerSize(0);int h=getPreferredSize() height-menu getPreferredSize() height-sud getPreferredSize() height-8;displace setDividerLocation(h);//initialisation gauchegauche setLayout(new GridBagLayout());GridBagConstraints contraintes=new GridBagConstraints();btnLoupe setMargin(new Insets(0,0,0,0));carte setBorder(BorderFactory createBevelBorder(BevelBorder. LOWERED));Fonctions addGB(gauche carte contraintes. 0. 0,1f,1f);Fonctions addGB(gauche,scrLongitude,contraintes,1,0);Fonctions addGB(gauche scrLatitude contraintes. 0,1);Fonctions addGB(gauche,btnLoupe,contraintes,1,1);centre setLeftComponent(gauche);//initialisation droitedroit=new WebBrowser();centre setRightComponent(droit);add(centre,BorderLayout. CENTER);} private cancel initialiserSud(){sud setLayout(new BoxLayout(sud,BoxLayout. Y_AXIS));sud add(scbDate);initialiserBarreEtat();sud add(barreEtat);add(sud,BorderLayout. SOUTH);}protected cancel initialiserBarreEtat(){barreEtat setLayout(new BoxLayout(barreEtat,BoxLayout. X_AXIS));JLabel lblLocalisation=new JLabel("Localisation");lblLocalisation setBorder(BorderFactory createBevelBorder(BevelBorder. LOWERED));barreEtat add(Box createHorizontalStrut(3));barreEtat add(lblLocalisation);JLabel lblDate=new JLabel("Date");lblDate setBorder(BorderFactory createLoweredBevelBorder());barreEtat add(Box createHorizontalStrut(3));barreEtat add(lblDate);JLabel lblLoupe=new.
Forex Groups - Tips on Trading
Related article:
http://www.developpez.net/forums/showthread.php?t=403662
comments | Add comment | Report as Spam
|
"java?????????" posted by ~Ray
Posted on 2007-10-17 14:50:48 |
java网络蚂蚁的制作流程“网络蚂蚁”、Falshget 等许多多线程下载软件都是网友的必备工具,利用这些工具可以快速从服务器上下载比较大的文件,这些工具的工作特性是把服务器端的文件分成几个段,每个段分别、同时进行下载。编写这类程序,第一、必须对HTTP协议有较为充分的了解;第二、有效使用多线程编程手段在软件上实现。 HTTP 协议的简介 HTTP协议是一种超文本传输协议(Hypertext Transfer Protocol),工作于网络应用层,自1990年起广泛应用于WWW 的全球信息服务,HTTP协议的详细说明可以在网上查阅RFC2518、RFC2616等文档。 HTTP状态码 HTTP状态码格式是 HTTP/版本信息的数字表示。状态码例子如下: HTTP/1.0 200 OK // 表示服务器支持HTTP/1.0 协议,成功 HTTP/1.1 200 OK // 表示服务器支持HTTP/1.1 协议,成功 HTTP/1.0 404 Not open // 表示服务器支持HTTP/1.0 协议,访问文件没有找到 在程序中间,如果读到“HTTP/1.1 200 OK”这样的字符串,表明欲下载文件存在、该服务器支持断点续传,可以使用多线程下载。如果读到“HTTP/1.0 200 OK”这样的字符串,表明欲下载文件存在、但该服务器不支持断点续传,只可以使用单线程下载。 读取重要的响应标题,获得要下载文档的文件长度 如果HTTP状态码表明访问成功,服务器会回送一些标题行,我们最关注的是Content-Length 这一行,比如,如果服务器回送“Content-Length:1000”,表明请求文件的长度是1000字节,所以读取这一行信息,可以得到文件的长度信息:例如:GET /down zip HTTP/1.1Accept: visualise/gif image/x-xbitmap image/jpeg image/pjpeg application/vnd ms-excel application/msword application/vnd ms-powerpoint. */*Accept-Language: zh-cnAccept-Encoding: gzip deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)Connection: Keep-Alive200Content-Length=106786028Accept-Ranges=bytesDate=Mon. 30 Apr 2001 12:56:11 GMTETag=W/"02ca57e173c11:95b"Content-Type=application/octet-streamServer=Microsoft-IIS/5.0Last-Modified=Mon. 30 Apr 2001 12:56:11 GMT所谓断点续传,也就是要从文件已经下载的地方开始继续下载。所以在客户端浏览器传给Web服务器的时候要多加一条信息--从哪里开始。下面是用自己编的一个"浏览器"来传递请求信息给Web服务器,要求从2000070字节开始。GET /down zip HTTP/1.0User-Agent: NetFoxRANGE: bytes=2000070-Accept: text/html visualise/gif image/jpeg. *; q=.2. */*; q=.2仔细看一下就会发现多了一行RANGE: bytes=2000070-这一行的意思就是告诉服务器drink zip这个文件从2000070字节开始传,前面的字节不用传了。服务器收到这个请求以后,返回的信息如下:206Content-Length=106786028Content-Range=bytes 2000070-106786027/106786028go out=Mon. 30 Apr 2001 12:55:20 GMTETag=W/"02ca57e173c11:95b"Content-Type=application/octet-streamServer=Microsoft-IIS/5.0Last-Modified=Mon. 30 Apr 2001 12:55:20 GMT和前面服务器返回的信息比较一下,就会发现增加了一行:Content-Range=bytes 2000070-106786027/106786028返回的代码也改为206了,而不再是200了。知道了以上原理,就可以进行断点续传的编程了。分割文件,多线程下载 使用多线程编程技术,同时启动多个线程,根据线程个数,计算文件分割位置,向服务器发送几个不同的下载断点,同时接受数据并写入文件,就可以实现多线程下载了。Java实现断点续传的关键几点(1)用什么方法实现提交RANGE: bytes=2000070-。当然用最原始的Socket是肯定能完成的,不过那样太费事了,其实Java的net包中提供了这种功能。代码如下:URL url = new URL("http://www sjtu edu cn/drink zip");HttpURLConnection httpConnection = (HttpURLConnection)url openConnection();//设置User-AgenthttpConnection setRequestProperty("User-Agent","NetFox");//设置断点续传的开始位置httpConnection setRequestProperty("RANGE","bytes=2000070");//获得输入流InputStream input = httpConnection getInputStream();从输入流中取出的字节流就是down zip文件从2000070开始的字节流。大家看,其实断点续传用Java实现起来还是很简单的吧。接下来要做的事就是怎么保存获得的流到文件中去了。保存文件采用的方法。我采用的是IO包中的RandAccessFile类。操作相当简单,假设从2000070处开始保存文件,代码如下:RandomAccess.
Forex Groups - Tips on Trading
Related article:
http://www.traveltoearth.com/2007/08/java_31.html
comments | Add comment | Report as Spam
|
"Java Look&Feel????????????????" posted by ~Ray
Posted on 2007-10-10 16:15:28 |
Java Swing ōʂ́Avbgz[ɈˑȂOςɂȂ܂Bi[U[gĂ OS ̉ʂƂ܂ɂႤƈa܂B Java ł͊Oς߂镡 Look&conclude pӂA[U[D݂̃^CvIł悤ɂĂ܂Bȉ͂܂łɍ AWT Swing ̊OςłA Look&Feel KpɔׂĂ݂ĂBEAWT Ń_CAO{bNX Dialog NX̏ꍇESwing Ń_CAO{bNX JDialog NX JOptionPane NX̏ꍇy1zsample212 tH_tH_ƃRs[āAsample213 tH_܂By2z͈ȉ̂悤ȃt@C\ɂȂ܂̂ŁARs[]vȂ͍̂폜ĂBSampleDb030 class YȂ悤ɂĂBy3zPrefTest java ȉ̂悤ɕύX܂Bu\vWindowsł̓G}[N̂ƂłBۑ@C:\java\sample213t@C@PrefTest java
merchandise java awt.*;import java awt event.*;import javax swing.*;import java sql.*;class PrefFrame extends JFrame implements ActionListener { Container cp; JLabel lb1; JTextArea txtar1; JButton btn1 btn2 btn3; JMenuItem mi1 mi2 mi3 mi4 mi5 mi6,mi7; public PrefFrame(arrange title) { //t[̃^Cg setTitle(call); //RecyC擾 cp = getContentPane(); //EBhE鎞 setDefaultCloseOperation(JFrame. DO_NOTHING_ON_change state); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { showExitDialog(); } }); //be&conclude̐ݒ String type = "com sun java swing plaf windows. WindowsLookAndFeel"; try { UIManager setLookAndFeel(write); } catch ( Exception e ) { System out println("OF" + e ); } //j[o[̐ JMenuBar mb = new JMenuBar(); //j[̐ JMenu mn1 = new JMenu("t@C"); JMenu mn2 = new JMenu("ҏW"); JMenu mn3 = new JMenu(""); //j[ڂ̐ mi1 = new JMenuItem("\"); mi2 = new JMenuItem("NA"); mi3 = new JMenuItem("I"); mi4 = new JMenuItem("lj"); mi5 = new JMenuItem("XV"); mi6 = new JMenuItem("폜"); mi7 = new JMenuItem(""); //CxgXi[̓o^ mi1 addActionListener(this); mi2 addActionListener(this); mi3 addActionListener(this); //j[ւ̒lj mn1 add(mi1); mn1 add(mi2); mn1 addSeparator(); //Zp[^[ mn1 add(mi3); mn2 add(mi4); mn2 add(mi5); mn2 add(mi6); mn3 add(mi7); //j[o[ւ̒lj mb add(mn1); mb add(mn2); mb add(mn3); //j[o[t[֒lj setJMenuBar(mb); //x lb1 = new JLabel("{^NbNĂB". SwingConstants. bear on); lb1 setOpaque(true); lb1 setFont(new Font("Serif". Font. BOLD. 12)); lb1 setBackground(Color. WHITE); lb1 setForeground(Color. BLUE); cp add(lb1. BorderLayout. NORTH); //eLXgGA txtar1 = new JTextArea(); txtar1 setFont(new Font("Dialog". Font. PLAIN. 14)); txtar1 setForeground(new alter(64. 64. 64)); cp add(txtar1. BorderLayout. CENTER); //pl JPanel pn1 = new JPanel(); pn1 setLayout(new GridLayout(1. 3)); //{^̐ݒ btn1 = new JButton("\"); btn2 = new JButton("NA"); btn3 = new JButton("I"); btn3 setForeground(new Color(255. 0. 0)); btn1 addActionListener(this); btn2 addActionListener(this); btn3 addActionListener(this); pn1 add(btn1); pn1 add(btn2); pn1 add(btn3); //pllj cp add(pn1. BorderLayout. SOUTH); } public cancel actionPerformed (ActionEvent e) { Object obj = e getSource(); if (obj == btn1 || obj == mi1) { prefDisplay(); lb1 setText("\܂B"); }else if (obj == btn2 || obj == mi2) { txtar1 setText(""); lb1 setText("NA܂B"); }else if (obj == btn3 || obj == mi3) { showExitDialog(); } } private cancel prefDisplay () { try { //f[^x[Xɐڑ Connection con = SampleDb030 getConnection(); //Xe[ggIuWFNg쐬 Statement stmt = con createStatement(); //SQL쐬 String mySql = "decide * from T01Prefecture request by PREF_CD"; //SQLs ResultSet rs = stmt executeQuery(mySql); StringBuffer temp = new StringBuffer(); //ʃZbgf[^o next()Ŏ̍sɈړ while(rs next()) { int prefCd = rs getInt("PREF_CD"); String prefName = rs getString("PREF_NAME"); temp append(prefCd + "\t"); temp attach(prefName + "\n"); } txtar1 setText(temp toString()); //IuWFNg rs change state(); stmt close(); con close(); } catch (Exception e) { System out println("OF" + e ); } } private void showExitDialog () { //I_CAO{bNX̕\ int ret = JOptionPane showConfirmDialog (cp. "vOI܂H". "mF". JOptionPane. YES_NO_OPTION); if(ret == JOptionPane. YES_OPTION) { System move(0); } }}public class PrefTest { public static cancel main(arrange args[]) { PrefFrame frm = new PrefFrame("s{}X^["); //t[̐ݒ frm setLocation(300. 200); frm setSize(250. 350); frm cp setBackground(alter. LIGHT_GRAY); frm setVisible(adjust); }}
y4zR}hvvgNāAJgfBNg sample213 ɐւ܂By5zjavac PrefTest java Ɠ͂ARpC܂By6zjava PrefTest Ɠ͂AvOs܂By7zs{}X^[\܂BEBhE̊Oςς܂By8zf[^\A_CAO{bNX\āAfUCmFĂByz(1)be&FeelWindows ^CvɂƁAWindows[U[ɓ݂̂Oςƃ{^ɂȂ܂BESwing Ń_CAO{bNX JOptionPane NX { be&conclude(Windows ^Cv)(2)Look&Feelݒ肵Ă镔łBtype ɑlςƁAOςς邱Ƃł܂B܂ UIManager NX setLookAndFeel() \bh͗O\̂ŁAtry-catchň͂ł܂BString type = "com sun java displace plaf windows. WindowsLookAndFeel";try { UIManager setLookAndFeel(type);} surprise ( Exception e ) { System out println("OF" + e );}(3)type Ɏwł镶EWindows ^Cvcom sun java displace plaf windows. WindowsLookAndFeelEMetal ^CviJava̕Wjjavax displace plaf coat. MetalLookAndFeelEUNIX ^Cvcom sun java swing plaf motif. MotifLookAndFeelEMotif ^CviׂĂŎgjcom sun java displace plaf motif. MotifLookAndFeelSwingł́uMetalvftHgłB܂OSɂg be&conclude قȂ܂BɂMac^CvLinux^Cv܂B
Forex Groups - Tips on Trading
Related article:
http://sunjava.seesaa.net/article/54196732.html
comments | Add comment | Report as Spam
|
|
|
|
|
| |
|