Tuesday, September 8, 2015

Sample Objects of different Classes

Classes used to create the above components are as follows:

Component NameClass Name
FrameJFrame
PanelJPanel
ButtonJButton
LabelJLabel
TextFieldJTextField
RadioButtonJRadioButton
ChekBoxJCheckBox
ComboBoxJComboBox



JFrame frame = new JFrame("Welcome");

JPanel panel = new JPanel();

JLabel lblusername = new JLabel("User Name");

JTextField txtusername = new JTextField(30);

JButton btnOk = new JButton("OK");

JRadioButton rbMale = new JRadioButton();

JCheckBox cbHobby = new JCheckBox();

JComboBox cbxCity = new JComboBox();

How to create a object of button class in java


JButton btnOk = new JButton("OK");

here JButton is a class, btnOk is a object of the class JButton.


new is a keyword which allocate memory to btnOk object after taking it from Constructor (JButton()).

here constructor is passing parameter as "OK" which will be displayed on the button.

Basic Java Interface

Let's understand simple Java interface


In the above picture we have create a Frame using JFrame class of Java.
Other components add are like as follows
  1. Frame
  2. Panel
  3. Button
  4. Label
  5. TextField
Classes used to create the above components are as follows:

Component NameClass Name
FrameJFrame
PanelJPanel
ButtonJButton
LabelJLabel
TextFieldJTextField
RadioButtonJRadioButton
ChekBoxJCheckBox
ComboBoxJComboBox