Events Handling / ActionListener and AWT
 
Here is a piece of code for you to see, how the Java Event Handling works, together with the Java AWT!
Enjoy!

import java.awt.*;
import java.awt.event.*;

public class MainWindow extends Frame implements ActionListener {
  
  static TextArea textarea = new TextArea("Hello World");;
  
  public MainWindow () {
    //textarea.setEditable( false );
    add(textarea);
    
    Button button1 = new Button ("Write");
    add (button1);
    button1.addActionListener (this);
    
    Button button2 = new Button ("Quit");
    add (button2);
    button2.addActionListener (this);
 }

  public static void main(String[] args) {
    MainWindow frame = new MainWindow ();
    frame.setTitle ("Window Title");
    frame.setResizable(false);
    frame.setSize(450,250);
    frame.setLayout (new FlowLayout());
    frame.setVisible (true);
  }
  
  public void actionPerformed (ActionEvent a) {
   if(a.getActionCommand().equals("Quit")) { System.exit(1); }
   if(a.getActionCommand().equals("Write")) { textarea.append("Hello"); }
 }
}
 
admin / Dec 02, 2004
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch