Swing With Even Handling
Swing With Even Handling
Kuldeep Yogi
Banasthali University
Swing
• Swing is super changed alternative of awt.
• Some swing components are provide additional
functionality, like image association with them.
• Most of the swing components are written
completely in java, so they provide a greater
portability and flexibility than the original GUI
components from package java.awt
• Awt components are platform dependent
• Some swing components are still platform
dependent. E.g, JFrame
Difference Between AWT & Swing
AWT SWING
Heavyweight Lightweight
Look and feel is OS based Look and feel is OS independent
Platform specific limitation for some Fewer platform limitation for components
components
Applet portability : web browser supports Applet portability: A plug-in is required
for applet
Does not support features like icons and Supports features like icons and tool-tips
tool-tips
The default Layout manager for Applet: The default layout manager for content
flowLayout and Frame is BorderLayout pane is BorderLayout
Swing Continue………
java.lang.Object
java.awt.Component
java.awt.Container
Javax.swing,JComponent
• Component class
– Operations common to most GUI components are found in Component
class.
• Container class
– Two important methods originates in this class
• add — adds components to a container.
• setLayout — enables a program to specify the layout manager that helps a
Container position and size its components.
JLabel
Method
void addTab(String s,Component c)
Example
JTabbedPane jtp=new JTabbedPane();
Jtp.addTab(“Color”,new ColorClass());
getContentPane().add(jtp);
JScrollPane
Constructor
» JScrollPane( Component c)
» JScrollPane( int vsb , int hsb)
» JScrollPane( Component c , int vsb , int hsb)
Example
JPanel jp =new JPanel();
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
JTable
Constructor
JTable(Object data[][] , Object colHeads[]
To Make an Interactive GUI Program
ActionEvent ContainerEvent
ComponentEvent InputEvent
MouseEvent
ItemEvent PaintEvent
TextEvent WindowEvent
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JButton javax.swing.ToggleButton
javax.swing.JCheckBox javax.swing.JRadioButton