Home | » | Java | » | Advance Java | » | » | Swing | » | JButton |
---|
Swing buttons are embodied by the JButton class. A Swing button can feature a text label (just like AWT button), an icon label, or a combinataion of both.
The JButton class inherits the AbstractButton class. The AbstractButton class defines the inherent behavior of all Swing buttons.
Constructors of the JButton class include the following:
- JButton(String) A button with the specified text
- JButton(Icon) A button with the specified icon.
- JButton(String,Icon)A button with the specified text and icon.
Example:
The following example creates a button with Click Me as the text on the button.
Icons can be associated to buttons by creating an object of the ImageIcon class, similar to instantiating an Image object.
The constructor of the ImageIcon class takes a graphic filename or URL as the only argument.
The following table describes some of the methods provided by the JButton class
Methods | Description |
---|---|
boolean isDefaultButton() | Sets to be the default Button. |
void updateUI() | Used to Update the look and feel of the program |
The following example displays six buttons on a panel using Frames.
C:\>jdk1.4\bin>javac MasterForm.java
C:\>jdk1.4\bin>appletviwer MasterForm.java
|
||
Download Complete Program |
Java Swing-1
JFrame | JPanel | JApplet |
JButtons | JLabels | JTextFields |
JPasswordField | JTextAreas | JCheckBoxes |
JRadioButtons | JList | JComboBox |
No comments:
Post a Comment