JFrame.EXIT_ON_CLOSE and DISPOSE_ON_CLOSE

DISPOSE_ON_CLOSE   :   This method is used to close the current frame. But doesn’t terminate the application. EXIT_ON_CLOSE            :   This method is used to close the all frame and finally to terminate the application Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; class Frame … Read more…

JComboBox with ItemListener

When the ComboBox item is selected, an item event is generated. This is handled by itemStateChanged() method, the getItem() method gets the JComboBox object that generated the event. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JComboBox; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JComboBox jb; … Read more…

JComboBox

The JComboBox control is a new control in Swing. It is a combination of a textfield and a drop-down list. The JComboBox class extends JComponent. A combo-box initially displays one entry. However, it can and a drop-down list that allows a user to select a different entry. We can also type our selection into the text … Read more…

JRadioButton(Another Example)

setIcon( ) method possible to change the icon inside a JButton during program execution. Program       Program Source import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JButton jb; private JRadioButton jr1,jr2,jr3,jr4; private ImageIcon icon; Frame() { setTitle(“Vehicle Selection”); setLayout(new FlowLayout()); … Read more…

JRadioButton

This control is useful when we wish to represent a group of buttons in which only one can be selected at a time. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JRadioButton jr1,jr2,jr3; private JLabel jl; Frame() { … Read more…

JCheckBox(Select any one option)

The JCheckBox class provides the functionality of a check box. When the user selects or deselects a check box, an ItemEvent is generated. You canobtain a reference to the JCheckBox that generated the event by calling getItem( ) on the ItemEvent passed to the itemStateChanged( ) method defined by ItemListener. The easiest way to determine … Read more…