AWT Section Index | Page 3
The "trick" is to create a new thread that performs the task while the normal event thread watches for the mouse release.
If you perform the mouse-pressed action inside your mousePressed() method...more
The width and height are actually very easy. All you need to do is get a FontMetrics object for the font you used to draw the string, and ask it:
FontMetrics fm = getFontMetrics(getFont());
The java.awt.EventQueue javadocs say:
It encapsulates asynchronous event
dispatch machinery which extracts events
from the queue and dispatches them by
calling dispatchEvent method
on this Eve...more
The Component class has a getInsets() method that returns an
Insets object. The Insets object has four public fields:
top, bottom, left and right.
These insets define the area a container is r...more
The Component class defines several size accessor methods to
assist the layout process. Each of these methods returns a
Dimension object describing the requested size.
These methods are as foll...more
GridLayout respects the first non-zero row or column parameter passed to its constructor. The other value is computed based on the number of components in the container.
AWT uses the Checkbox class for both check boxes and radio buttons.
To create a radio button, you need to create check boxes, and add them to a checkbox group. For example
printerJob.printDialog() method which pops up the print options dialog returns boolean true or false.
If user clicks cancel button it returns false and you can trap it by declaring and checking a ...more
Because the preferred size of a component is usually dependent on fonts and decorations used for a specific platform, you need to "realize" the component before you can ask.
To realize a componen...more
Prior to Java 2, v1.4, unless you happened to be listening to the component for it's focusGained, you couldn't.
In Java 2, v1.4, you can ask for it using the updated focus architecture. You can f...more
SWT (Standard Widget Toolkit) is a completely independent Graphical User
Interface (GUI) toolkit from IBM. They created it for their new Eclipse
Integrated Development Environment (IDE).
The easiest way is to use RMI to start the app and check to see if it's already running.
The basic structure is this:
The main method of your app checks the RMI registry to see if the app is ...more
You're not supposed to extend it.
The AWT manager creates and passes Graphics objects to you to use to paint. It's the only thing that really knows how to set them up properly.
If you'd like to ...more
Can Images respond to mouse events?
Instead of a button, i need to use Images and want to load different images when different mouse events are fired. what i am currently doing now is drawing an im...more
With Java2D you can apply an AffineTransform to the graphics context to rotate everything that is drawn on it.