import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Date;
public class Test extends Applet implements WindowListener, ActionListener {
public static void main(String[] args) {
Frame F=new Frame("GUI Event Handling");
Test BD=new Test();
F.setSize(420, 350);
F.addWindowListener(BD);
F.add(BD);
BD.init();
BD.start();
F.setVisible(true);
}
TextField TF;
Button BS;
Checkbox CB;
TextArea TA;
Button BC;
public void init() {
setLayout(new BorderLayout());
Panel NO=new Panel();
NO.setLayout(new GridLayout(5,1, 10,10));
Label l=new Label("GUI Event Handling",Label.CENTER);
l.setFont(new Font("Helvetica",Font.BOLD,16));
NO.add(l);
NO.add(new Label("System Input",Label.CENTER));
TF=new TextField(30);
BS=new Button(" Submit ");
BS.addActionListener(this);
CB=new Checkbox("overwrite", false);
Panel SU=new Panel();
SU.setLayout(new FlowLayout());
SU.add(TF);
SU.add(BS);
SU.add(CB);
NO.add(SU);
NO.add(new Label("System LOG",Label.CENTER));
add("North",NO);
TA=new TextArea("", 60, 10, TextArea.SCROLLBARS_VERTICAL_ONLY);
TA.setEditable(false);
add("Center", TA);
BC=new Button("Clear");
BC.addActionListener(this);
add("South", BC);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==BS) {
BS.setLabel("Processing");
Date d=new Date();
if (CB.getState()) TA.setText("");
TA.append(d+"\t"+TF.getText()+"\n");
TF.setText("");
BS.setLabel(" Submit ");
} else if (e.getSource()==BC) {
TA.setText("");
}
}
public void start() { }
public void stop() { }
public void windowClosing(WindowEvent e) { stop(); System.exit(0); }
public void windowClosed(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
}