File: tutorial.java

package info (click to toggle)
jswat 1.7-2
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 5,656 kB
  • ctags: 3,210
  • sloc: java: 24,683; xml: 130; makefile: 59; sh: 21
file content (40 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download
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.
// $Author: nfiedler $ $Date: 2002-10-13 00:03:33 -0700 (Sun, 13 Oct 2002) $ $Rev: 604 $

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.show();
    }
}