Key API's:
currently active threads: 4 0: Thread[main,5,main] 1: Thread[AWT-EventQueue-0,6,main] 2: Thread[SunToolkit.PostEventQueue-0,5,main] 3: Thread[AWT-Motif,5,main]
Appearance is controlled by the invisible agent that notices that the window needs repainting. The programmer must override paint and created the appearance of the entire area (or cobble widgets together that take the responsiblity for their area upon themeselves). Many of the earlier applet examples were of this simple form where paint was overriden.
It is usually better to call repaint() then to call paint() directly, because if you call repaint() 10 times before the screen updater actually gets around to doing the painting, your paint method will only get called once, which is more efficient.
Updating a component while not executing in an event handler could possiblilty cause a deadlock. To avoid this problem use one of two SwingUtilities: invokeLater or invokeAndWait.
UI delegate = User-Interface delegate.
A combination of a graphic symbol and some program code to perform a specific function, e.g., a scroll-bar or button. In the PC world a widget is sometimes known as a control. Windowing systems usually provide widget libraries containing commonly used widgets drawn in a certain style and with consistent behavior.
AWT are said to be "heavyweight" because they have "peers" (platform specific constructs) that do the real work. Swing components are said to be "lightweight" most of the work is done by Java.
Button, Checkbox, Choice, Label, List, TextComponent, Scrollbar, Canvas MenuComponent: MenuBar, MenuItem Container: Panel, Window
JButton, JCheckBox, JComboBox, JLabel, JList, JTextComponent, JSlider, JScrollBar, JProgressBar Menus: JMenuBar Fancy: JTable, JTree, JInternalFrame
Containers: JPanel, JWindow, JFrame, JApplet, Specialty Containers: JScrollPane, JLayeredPane, JSplitPane, JTabbedPane
Dialogs: JDialog, JFileChooser, JColorChooser Other: Borders
java -jar demo/jfc/SwingSet/SwingSet.jar
java -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel JWidgets
java -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel JWidgets
java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel JWidgets
See all the Java SwingSet demo.
Notice that a container is a (extends a) component in the usual inheritance hierarchy. Some are containers --- they extend . Others components are widgets -- fundamental GUI units.
A particular GUI is orgainized by putting some set of widgets in a container. These containers (which are components) may be put in other containers and so on.
You only need one container (the window) and you can put all the widgets in it. But is far better to orgainize the widgets in small groups in their own containers. This leads to a second hierarchy.
All the components in a Java GUI will print themselves to System.err if you press control+shift+F1.
java.awt.geom
package define common
graphics primitives, such as points, lines, curves, arcs, rectangles,
and ellipses.
Arc2D |
Ellipse2D |
QuadCurve2D |
Area |
GeneralPath |
Rectangle2D |
CubicCurve2D |
Line2D |
RectangularShape |
Dimension2D |
Point2D |
RoundRectangle2D |
Arc2D, Ellipse2D, Rectangle2D, RoundRectangle2D all extend RectangularShape. They are also specified using x, y, width, and height.
public abstract class Graphics extends Object { public void draw3DRect (int x, int y, int width, int height, boolean raised) public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) public void drawLine (int x1, int y1, int x2, int y2) public void drawOval (int x, int y, int width, int height) public void drawPolygon (int[] xs, int[] ys, int n) public void drawRect (int x, in y, int width, int height) public void drawString (string str, int x, in y) public void drawImage (image img, int x, int y, int width, int height, ImageObserver obs }
Color white = new Color(255, 255, 255); Color lightGray = new Color(192, 192, 192); Color gray = new Color(128, 128, 128); Color darkGray = new Color(64, 64, 64); Color black = new Color(0, 0, 0); Color red = new Color(255, 0, 0); Color pink = new Color(255, 175, 175); Color orange = new Color(255, 200, 0); Color yellow = new Color(255, 255, 0); Color green = new Color(0, 255, 0); Color magenta = new Color(255, 0, 255); Color cyan = new Color(0, 255, 255); Color blue = new Color(0, 0, 255);
brighter () is RGB / 0.7 (ie., 1.42 * RGB) darker () is RGB * 0.7
Dialog Helvitica TimesRoman Courier DialogInput ZapfDingbats
style: PLAIN, BOLD, ITALIC, Font.BOLD|Font.ITALICStarting with J2SDK 1.2.1, Java applications require a font property file to properly display the application's AWT windowing and Java2D components. This file contains mappings of Java logical font names to physical fonts on the X server. Previous versions of the JDK 1.1.n did not require this file. Instead of using Java default fonts, which were resolved at run-time by the X server to physical fonts on the display side, the font.properties file provides a mapping of the Java logical font names to fonts on the system.
Available Fonts: Akhbar MT ...
You can specify a different selection mode by calling the
setSelectionMode
method on the list.
The following table describes the three list selection modes:
Mode | Description | Example |
---|---|---|
SINGLE_SELECTION
|
Only one item can be selected at a time. When the user selects an item, any previously selected item is deselected first. | |
SINGLE_INTERVAL_SELECTION
|
Multiple, contiguous items can be selected. When the user begins a new selection range, any previously selected items are deselected first. | |
MULTIPLE_INTERVAL_SELECTION
|
The default. Any combination of items can be selected. The user must explicitly deselect items. |
AWTEvents
Event Category | Description |
---|---|
action | initiated by, e.g., buttons, to indicate a command should be performed |
adjustment | initiated by, e.g., scrollbars, to indicate a value has been changed |
ancester | initiated by any component when it has been reparented |
component | initiated by any component when it has been moved or resized |
focus | initiated by any component when it has lost or gained the focus |
item | initiated by, e.g., list boxes, to indicate the state of an item has changed |
input method | If the text component that's currently using the input method is an active client, the event is dispatched to that component. Otherwise, it is dispatched to a separate composition window. |
internal frame | support for Swing JInternaFrame |
invocation | An event which executes the run() method on a Runnable when dispatched by the AWT event dispatcher thread |
key | initiated by a key press or release |
mouse | initiated by a mouse movements or clicks |
text | initiated by text componentes to indicate a change in the text |
window | initiated by windows when closed, iconfied, etc. |
ActionEvent | ActionListener actionPerformed(ActionEvent) | Button List TextField MenuItem |
AdjustmentEvent | AdjustmentListener adjustmentValueChanged(AdjustedEvent) | Component |
ComponentEvent | ComponentListener componentMoved(ComponentEvent) componentHidden(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) | Component |
FocusEvent | FocusListener focusGained(FocusEvent) focusLost(FocusEvent) | Scrollbar |
ItemEvent | ItemListener itemStateChanged(ItemEvent) | Checkbox MenuItem Choice List |
KeyEvent | KeyListener keyPressed(KeyEvent) keyReleased(KeyEvent) keyTyped(KeyEvent) | Component |
MouseEvent | MouseListener mousePressed(MouseEvent) mouseReleased(MouseEvent) mouseClicked(MouseEvent) mouseEntered(MouseEvent) mouseExited(MouseEvent) | Component |
MouseMotionListener mouseDragged(MouseEvent) mouseMoved(MouseEvent) | Component | |
TextEvent | TextListener textValueChanged(TextEvent) | TextComponent |
WindowEvent | WindowListener windowClosing(WindowEvent) windowOpened(WindowEvent) windowIconified(WindowEvent) windowDeiconified(WindowEvent) windowClosed(WindowEvent) windowActivated(WindowEvent) windowDeactivated(WindowEvent) | Window |
Adapter classes for java.awt (JDK 1.3)
Event Class | Listener Interface | Adapter Class |
---|---|---|
ComponentEvent | ComponentListener | ComponentAdapter |
ContainerEvent | ContainerListener | ContainerAdapter |
FocusEvent | FocusListener | FocusAdapter |
HierarchyBoundsEvent | HierarchyBoundsListener | HierarchyBoundsAdapter |
KeyEvent | KeyListener | KeyAdapter |
MouseEvent | MouseListener | MouseAdapter |
MouseMotionEvent | MouseMotionListener | MouseMotionAdapter |
WindowEvent | WindowListener | WindowAdapter |
Event Class | Listener Interface | Adapter Class |
---|---|---|
InternalFrameEvent | InternalFrameListener | InternalFrameAdapter |
MouseInputEvent | MouseInputListener | MouseInputAdapter |