My other sites |
New Summer Look :)
| Applets = small applications for the browser - placed on HTML pages - downloaded by the browser - executed on the browser's JVM - severe security restrictions - four entry point methods - characteristics of a container for components |
Gui Applications = normal applications - execute by the interpreter - no security restrictions - one "static public main(String[] argv)" entry point - need to instantiate a subclass of Frame or Window |
![]() |
- AWT stands for "Abstract Window Toolkit" - It is used for graphical user interfaces, windows, buttons, menus, toolbars etc. - As data viewer to display graphics, images, graphs - As data manipulator to alter data by direct manipulation |
![]() |
- To create platform independent gui applications and
applets - Write once and run anywhere - Native "look & feel" - Native components may behave different from Java components - JDK 1.2 contains the swing components: Plugable look & feel, platform independent, slower than AWT components |
| Roughly divided into four parts: | |
|
|
(1) Components, GUI components such as buttons, scrollbars, etc. (3) Graphics, Colors, fonts, images, drawing, etc |
|
- Every part of a GUI is a Component
|
|
![]() Can you map the list above to the components on the left and right? |
|
| - The Component class is the top-most class in AWT - All the building blocks in a GUI descend from Component (except menu components) - All AWT's primitive gui components have respective peers implemented natively - It is not possible to instantiate Component - Component has a very large number of methods |
![]() |
- Extends Component, i.e. a Container is a Component
- Contains components, allows grouping of components - Since a Container is a Component, containers can contain other containers (Composite Design Pattern) - It is impossible to instantiate Container - Window, Dialog, Frame, Panel & Applet: all are Containers |
![]() |
public class firstGUI {
private Frame f;
private Button b1, b2;
public static void main(String[] args) {
firstGUI myFirstGUI = new firstGUI();
myFirstGUI.go();
}
public void go() {
f = new Frame("First Gui Example");
f.setLayout(new FlowLayout());
b1 = new Button("Press-me");
b2 = new Button("or me! ");
f.add(b1); f.add(b2);f.pack();
f.setVisible(true);
}
}
|
![]() |
- An event signals that something happened 1. The user, using the mouse or the keyboard |
| Hierarchical, in JDK 1.02 based upon: - containment - propagation to the parent |
![]() |
|
Mouse Events
|
Keyboard Events
Event.xx (xx = UP, END, PGDN, etc) |
![]() |
![]() |
![]() |
import java.awt.*;
public class AWTDemo extends Frame {
private Panel myPanel;
private Button myButton;
public AWTDemo() {
this.setBounds(0, 0, 200, 200);
myPanel = new Panel();
myPanel.setBackground(Color.red);
this.add(myPanel);
myButton = new Button();
myButton.setBounds(50, 50, 100, 80);
myButton.setLabel("Click me!");
myPanel.add(myButton);
} // end constructor
public static void main(String args[]) {
AWTDemo myFrame;
myFrame = new AWTDemo();
myFrame.show();
} //end static main
// this is the old way to handle events
public boolean handleEvent(Event myEvent) {
if (myEvent.id == Event.WINDOW_DESTROY) {
hide();
System.exit(0);
return true;
}
if (myEvent.target==myButton &&
|
|
Delegation based, introduced in JDK 1.1 |
|