Java Swings

June 29,2016

Today i come to know about java swings to create window based applications.In java swings i learn about the Jcomponents.

Java Swings

Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java.

Hierarchy of Java Swing classes

The hierarchy of java swing API is given below.swinghierarchy

JButton class

The JButton class is used to create a button that have plateform-independent implementation.

Commonly used Constructors:

  • JButton(): creates a button with no text and icon.
  • JButton(String s): creates a button with the specified text.
  • JButton(Icon i): creates a button with the specified icon object.

JRadioButton class

The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz.

It should be added in ButtonGroup to select one radio button only.

Commonly used Constructors of JRadioButton class:

  • JRadioButton(): creates an unselected radio button with no text.
  • JRadioButton(String s): creates an unselected radio button with specified text.
  • JRadioButton(String s, boolean selected): creates a radio button with the specified text and selected status.

JComboBox class:

The JComboBox class is used to create the combobox (drop-down list). At a time only one item can be selected from the item list.

Commonly used methods of JComboBox class:

1) public void addItem(Object anObject): is used to add an item to the item list.
2) public void removeItem(Object anObject): is used to delete an item to the item list.
3) public void removeAllItems(): is used to remove all the items from the list.
4) public void setEditable(boolean b): is used to determine whether the JComboBox is editable.
5) public void addActionListener(ActionListener a): is used to add the ActionListener.
6) public void addItemListener(ItemListener i): is used to add the ItemListener.

 

Leave a comment