HelloWorld.java
 1 import java.awt.*;
 2 import java.awt.event.*;
 3 
 4 public class HelloWorld implements MouseListener {
 5         public static void main(String [] args) {
 6                 new HelloWorld();
 7         }
 8         
 9         public HelloWorld() {
10                 Frame f = new Frame();
11                 
12                 f.setLayout(new GridBagLayout());
13                 
14                 Button b = new Button("quitter");
15                 Label l = new Label("Hello World");
16                 
17                 f.add(b);
18                 f.add(l);
19                 
20                 f.setSize(200,200);
21                 f.setVisible(true);
22                 
23                 b.addMouseListener(this);
24                 
25                 f.pack(); // rendre la fenetre la plus petite possible en affichant tous les elements
26         }
27         
28         public void mouseClicked(MouseEvent e) {
29                 System.exit(0);
30         }
31         
32         public void mouseEntered(MouseEvent e) {
33         }
34         public void mouseExited(MouseEvent e) {
35         }
36         public void mousePressed(MouseEvent e) {
37         }
38         public void mouseReleased(MouseEvent e) {
39         }
40 }
41