home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / os2 / edm2 / 0506 / grinding1.java < prev    next >
Encoding:
Java Source  |  1997-06-01  |  2.0 KB  |  47 lines

  1. import java.AWT.*; // The import statement allows us to make use of classes
  2.                    // defined else where. java.AWT is a package of classes
  3.                    // which contains many classes. All the classes in AWT
  4.                    // can be imported by using the shortcut *. It's
  5.                    // not recommended to do this since applets will
  6.                    // download all the imported classes that are not on
  7.                    // the target machine.
  8.  
  9. public class HelloAWT extends Frame  // Class Frame is a part of the AWT
  10.                                      // package.
  11.  
  12. implements ActionListener // The ActionListener is the interface
  13.                           // which is responsible for events.
  14.                           // This means that this class will handle
  15.                           // events.
  16. {
  17.     public static void main(String argv[])
  18.     {
  19.         new HelloAWT();
  20.     }
  21.  
  22.     HelloAWT()
  23.     {
  24.         setLayout(new BoarderLayOut())// Sets the layout of the frame
  25.                                       // (don't forget this is a frame
  26.                                       // class since we extended it).
  27.         add("South",exitButton);      // Adds the exit button to the
  28.                                       // lower part of the screen
  29.  
  30.         add("North",exitButtonhelloAWTLabel);
  31.         exitButton.addActionListner(this);
  32.         pack();            // Resize the frame to fit the components
  33.         show();            // The frame is invisible by default. Show it
  34.     }
  35.  
  36.     public void actionPerformed(ActionEvent E)  // This method is called
  37.     {                                           // for every registered event
  38.         if(E.getActionCommand().equals (exitButton.getLab el()))
  39.            // if the event has a action command that equals the label
  40.            // of the exitButton
  41.            System.exit(0);         // Then this method exits the program.
  42.     }
  43.  
  44.     private Button exitButton = new Button("Exit");
  45.     private Label  helloAWTLabel = new Label("Hello AWT");
  46. }
  47.