27-03-2012, 04:21 PM
Java AWT
chapter13.ppt (Size: 600.5 KB / Downloads: 93)
Frames
A frame is a window with a title bar and a border
The Frame class is a subclass of Container class
Container class objects may have other components (e.g. Buttons) added to them using the add method
A typical Java GUI will create and display one or more frames
To make a frame visible the message setVisbible(true) must be sent to the frame
Layout Managers
Governs how components are arranged inside a Container object
The Container method setLayout allows the programmer to specify which layout manager (e.g. FlowLayout) is desired for a particular container object
The size of a Container object should be set explicitly by the programmer as well
Can use pack() to set size to accommodate preferred sizes of components)
UML Notation
The filled diamond represents composition
This shows that the class TwoButtons contains a class Frame which contains a class Buttons
A good UML diagram only shows the classes and associations that are important to understanding the architecture
This UML diagram does not include super classes like Component or Container
Java AWT Event Model
Including reactive program components involves:
Having the class header declare itself as implementing the ActionListener interface
Typically in the class constructor the class instance registers itself as being interested in listening for events from a newly created component
One method (e.g. actionPerformed) of the ActiveListener interface is defined
Scrollbars
The leftmost position of a horizontal scrollbar corresponds to some integer value and the rightmost position corresponds to a larger integer value
Scrollbars can be displayed vertically
User movement options
Clicking either end button causes bubble to move in unit increments
Clicking the are between bubble and end button causes movement in 10 unit increments
Clicking and dragging the bubble in the desired direction
Transforming a Java Program into an Applet
Set the size you want the applet to be in the HTML file
Add the import statement to the Java code java.applet.*;
Change header from extends Frame to extends Applet
Change constructor heading to
public void start();
Eliminate any Java code that is meaningless in applets