1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
// JSwat Tutorial example program.
// $Id: tutorial.java 1113 2004-01-25 22:25:32Z nfiedler $
import java.awt.*;
import java.awt.event.*;
public class tutorial implements ActionListener {
/** Number of times the button was pushed. */
protected int pushCount;
public void actionPerformed(ActionEvent e) {
pushCount++;
Button button = (Button) e.getSource();
StringBuffer label = new StringBuffer("Pushed ");
label.append(Integer.toString(pushCount));
label.append(" times");
button.setLabel(label.toString());
}
protected Frame buildWindow(String title) {
Frame fr = new Frame(title);
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
fr.setSize(150, 100);
return fr;
}
public static void main(String[] args) {
System.out.println("Hello world!");
tutorial me = new tutorial();
Frame frame = me.buildWindow("tutorial");
Button button = new Button("Push me");
button.addActionListener(me);
frame.add(button);
frame.setVisible(true);
}
}
|