In this chapter we will discuss about component in java. At bellow is component in swing libarary:
1. JLabel
->Have a utility to display a message, display tittle of component, and show picture.
Example :
Declaration-> JLabel _label=new JLabel("Hello Word");
or
JLabel _label=new JLabel();
_label.setText("Hello Word");
2. JButton
->Have a utility to handle event after click.
Example :
Declaration -> JButton _button=new JButton("Click Me");
or
JButton _button=new JButton();
_button.setText("Click Me");
3. JFrame
->Have a utility to display a form.
Example :
Declaration-> JFrame _frame=new JFrame();
//Set property in Java Frame
_frame.setVisible(true); (Display frame)
_frame.setTitle("Exercise User Interface"); (Tittle of frame)
_frame.setExtendedState(_frame.MAXIMIZED_BOTH); (Maximize frame)
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE); (Close Event)
Add Component in Frame -> JFrame _frame=new JFrame();
//Set property in Java Frame
_frame.setVisible(true); (Display frame)
_frame.setTitle("Exercise User Interface"); (Tittle of frame)
_frame.setExtendedState(_frame.MAXIMIZED_BOTH); (Maximize frame)
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE); (Close Event)
//Component
JPanel _panel= new JPanel();
//Add Panel to Frame
_frame.add(_panel);
4. JPanel
->A place to collect all component so all component can display together in monitor.
Example :
Declaration -> JPanel _panel=new JPanel();
Add Component to Panel -> JPanel _panel=new JPanel();
//Component
JLabel _label=new JLabel("Hello Word");
//Add Label to Panel
_panel.add(_label);
5. JRadioButton
-> Have a utility to make group radio button.
Example :
Declaration -> JRadioButton _radio=new JRadioButton("Chili");
Add Group RadioButton -> ButtonGroup _group=new ButtonGroup();
//Component Radio Button
JRadioButton _radioCar=new JRadioButton("Car");
JRadioButton _radioMotor=new JRadioButton("MotorCycle");
JRadioButton _radioJet=new JRadioButton("Jet");
//Add RadioButton to Button Group
_group.add(_radioCar);
_group.add(_radioMotor);
_group.add(_radioJet);
6. JBorder
->Add border decoration at form.Border in swing:
1. Line Border
2. Empty Border
3. Bevel Border
4. Compound Border
5. Etched Border
6. Lowered Bevel Border
7. Matte Border
8. Raised Bevel Border
Example:
Declaration -> JPanel _panel=new JPanel();
Border take = BorderFactory.createEtchedBorder();
take = BorderFactory.createTitledBorder("Transaction - Save Money");
_frame.setBorder(take);
7. JTextArea
->Use to entry data in application.
Example:
Declaration -> JTextArea _txtArea=new JTextArea();
8. JScroll Bar
Example:
Declaration -> JTable _table=new JTable();
JScrollPane _pane;
_pane=new JScrollPane(_table,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
9. JCheckBox
Example :
Declaration -> JCheckBox _box=new JCheckBox("Test");
Okay that's is is and finnaly congratulation you have know about a little component in java. Thank you for see this tutorial i hope with this tutorial can help you...^^
Thursday, January 20, 2011
Component in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment