public class HelloGUIApp3
class GUI3
1: //HelloGUIApp3.java
2: //An application to display "Hello, world!" in a window, in color,
3: //with a window that closes when its close box is clicked, or also
4: //when the Quit button of the application is clicked.
6: import java.awt.*;
7: import java.awt.event.*;
9: public class HelloGUIApp3
10: {
11: public static void main(String[] args)
12: {
13: GUI3 application = new GUI3();
14: application.setSize(300, 100);
15: application.setVisible(true);
16: }
17: }
18:
20: class GUI3
21: extends Frame
22: implements ActionListener, WindowListener
23: {
24: private Button button;
26: GUI3()
27: {
28: setTitle("Hello with Quit Button");
30: setLayout(new FlowLayout());
31: button = new Button("Quit");
32: add(button);
33: button.addActionListener(this);
34: addWindowListener(this);
35: }
38: public void actionPerformed(ActionEvent event)
39: {
40: System.exit(0);
41: }
44: public void windowClosed(WindowEvent event) {}
45: public void windowDeiconified(WindowEvent event) {}
46: public void windowIconified(WindowEvent event) {}
47: public void windowActivated(WindowEvent event) {}
48: public void windowDeactivated(WindowEvent event) {}
49: public void windowOpened(WindowEvent event) {}
50: public void windowClosing(WindowEvent event)
51: {
52: System.exit(0);
53: }
56: public void paint(Graphics g)
57: {
58: g.drawString("Hello, world!", 120, 80);
59: }
60: }