Jump to content

Grinding1.java

From EDM2
Revision as of 16:26, 20 December 2017 by Ak120 (talk | contribs)
import java.AWT.*; // The import statement allows us to make use of classes
                   // defined else where. java.AWT is a package of classes
                   // which contains many classes. All the classes in AWT
                   // can be imported by using the shortcut *. It's
                   // not recommended to do this since applets will
                   // download all the imported classes that are not on
                   // the target machine.

public class HelloAWT extends Frame  // Class Frame is a part of the AWT
                                     // package.

implements ActionListener // The ActionListener is the interface
                          // which is responsible for events.
                          // This means that this class will handle
                          // events.
{
    public static void main(String argv[])
    {
        new HelloAWT();
    }

    HelloAWT()
    {
        setLayout(new BoarderLayOut())// Sets the layout of the frame
                                      // (don't forget this is a frame
                                      // class since we extended it).
        add("South",exitButton);      // Adds the exit button to the
                                      // lower part of the screen

        add("North",exitButtonhelloAWTLabel);
        exitButton.addActionListner(this);
        pack();            // Resize the frame to fit the components
        show();            // The frame is invisible by default. Show it
    }

    public void actionPerformed(ActionEvent E)  // This method is called
    {                                           // for every registered event
        if(E.getActionCommand().equals (exitButton.getLab el()))
           // if the event has a action command that equals the label
           // of the exitButton
           System.exit(0);         // Then this method exits the program.
    }

    private Button exitButton = new Button("Exit");
    private Label  helloAWTLabel = new Label("Hello AWT");
}