Posts

Action Listener - Practice(simple calculator)

Action Listener - Practice(simple calculator) Example 1 - Process oriented programming package com . LILRICH . lesson2 ; ​ import java . awt . * ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; ​ public class CalOPP {     public static void main ( String [] args ) {         new OppFrame ();   } } ​ //Frame class OppFrame extends Frame {     public OppFrame () {         //1. TextField         TextField num1 = new TextField ( 10 );         TextField num2 = new TextField ( 10 );         TextField num3 = new TextField ( 20 ); ​         //2. Label         Label label = new Label ( "+" ); ​         //3. Button & action listener         Button button = new Button ( "=" );         O...

Action Listener - Text Field

Action Listener - Text Field Example package com . LILRICH . lesson2 ; ​ import javax . swing . * ; import java . awt . * ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import java . awt . event . WindowAdapter ; import java . awt . event . WindowEvent ; ​ public class listener03 {     public static void main ( String [] args ) {     new MyFrame ();   } } class MyFrame extends Frame {     public MyFrame (){         TextField textField = new TextField ();         TextListener textListener = new TextListener ();         textField . addActionListener ( textListener ); ​         textField . setEchoChar ( '*' ); //password simulation         add ( textField );         setSize ( 200 , 200 );         setVisible ( true ); ​     ...

Action Listener - Button

Action Listener - Button Event listener - what happens when the is key pressed Example 1 - one button package com . LILRICH . lesson2 ; ​ import java . awt . * ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import java . awt . event . WindowAdapter ; import java . awt . event . WindowEvent ; ​ public class listener01 {     public static void main ( String [] args ) {         Frame frame = new Frame ();         Button button = new Button ( "Test" );         Listener mylistener = new Listener ();         button . addActionListener ( mylistener );         frame . add ( button );         frame . pack ();         frame . setVisible ( true );         cl ( frame );   }   //close window     private static void cl ( Frame fra...