Java The Complete Reference, Seventh Edition
To avoid problems (including the potential for deadlock), all Swing GUI components must be created and updated from the event di ...
// Handle an event in a Swing program. import java.awt.; import java.awt.event.; import javax.swing.*; class EventDemo { JLabel ...
jfrm.setVisible(true); } public static void main(String args[]) { // Create the frame on the event dispatching thread. SwingUtil ...
Chapter 29: Introducing Swing 871 Next, event listeners for the button’s action events are added by the code shown here: // Add ...
872 Part III: Software Development Using Java Here is an example of a Swing applet. It provides the same functionality as the pr ...
Chapter 29: Introducing Swing 873 // Set the applet to use flow layout. setLayout(new FlowLayout()); // Make two buttons. jbtnAl ...
applications that need this capability. To write output directly to the surface of a component, you will use one or more drawing ...
Compute the Paintable Area When drawing to the surface of a component, you must be careful to restrict your output to the area t ...
876 Part III: Software Development Using Java // Paint lines to a panel. import java.awt.*; import java.awt.event.*; import java ...
// Demonstrate painting directly onto a panel. class PaintDemo { JLabel jlab; PaintPanel pp; PaintDemo() { // Create a new JFram ...
Borderis the Swing interface that encapsulates a border. You can obtain a border by calling one of the factory methods defined b ...
30 Exploring Swing T he previous chapter described several of the core concepts relating to Swing and showed the general form of ...
880 Part III: Software Development Using Java Here,strandiconare the text and icon used for the label. Thealignargument specifie ...
Chapter 30: Exploring Swing 881 ); } catch (Exception exc) { System.out.println("Can't create because of " + exc); } } private v ...
also possible. In many cases, your program will not need to handle these events. Instead, you will simply obtain the string curr ...
The Swing Buttons Swing defines four types of buttons:JButton,JToggleButton,JCheckBox, andJRadioButton. All are subclasses of th ...
In the preceding chapter, you saw an example of a text-based button. The following demonstrates an icon-based button. It display ...
Chapter 30: Exploring Swing 885 jb.addActionListener(this); add(jb); ImageIcon japan = new ImageIcon("japan.gif"); jb = new JBut ...
JToggleButtonuses a model defined by a nested class calledJToggleButton .ToggleButtonModel. Normally, you won’t need to interact ...
Chapter 30: Exploring Swing 887 } private void makeGUI() { // Change to flow layout. setLayout(new FlowLayout()); // Create a la ...
«
41
42
43
44
45
46
47
48
49
50
»
Free download pdf