Grinding1.java: Difference between revisions
Appearance
m Ak120 moved page Grinding Java - Enhancing the AWT:grinding1.java to Grinding1.java |
mNo edit summary |
||
Line 38: | Line 38: | ||
{ // for every registered event | { // for every registered event | ||
if(E.getActionCommand().equals (exitButton.getLab el())) | if(E.getActionCommand().equals (exitButton.getLab el())) | ||
// if the event has | // if the event has an action command that equals the label | ||
// of the exitButton | // of the exitButton | ||
System.exit(0); // Then this method exits the program. | System.exit(0); // Then this method exits the program. |
Latest revision as of 02:28, 20 March 2018
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 an 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"); }