Presentation is loading. Please wait.

Presentation is loading. Please wait.

Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”

Similar presentations


Presentation on theme: "Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”"— Presentation transcript:

1 Swing

2 Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”

3 Introduction to Swing Java Foundation Classes (JFC) Sophisticated set of graphics and user interface API as core packages in JDK is called JFC. “ Swing is an important technology in JFC”

4 AWT vs Swings AWTSwing AWT provides classes to build user interfaces Swings also provides set of classes to build user interfaces but the classes in Swing provides more powerful and flexible components that are possible with the AWT AWT provides a wide collection of user interface components. In addition to the familiar components, such as buttons, check boxes, and labels, Swing also supplies several exciting additions, including tabbed panes, scroll panes, trees, and tables. AWT components do not have additional features. Even familiar components such as buttons have more capabilities in Swing. For example, a button may have both an image and a text string associated with it. Also, the image can be changed as the state of the button changes AWT components are implemented by platform specific code so are not purely platform independent Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and, therefore, are platform-independent AWT components are heavy weight Swing components are light weight AWT related classes are contained in java.awt package Swing related classes are contained in javax.swing package

5 Swing Components Classes AbstractButton Abstract superclass for Swing buttons. ButtonGroup Encapsulates a mutually exclusive set of buttons. ImageIcon Encapsulates an icon. JApplet The Swing version of Applet. JButton The Swing push button class. JCheckBox The Swing check box class. JComboBox Encapsulates a combo box (an combination of a drop-down list and text field). JLabel The Swing version of a label. JRadioButton The Swing version of a radio button. JScrollPane Encapsulates a scrollable window. JTabbedPane Encapsulates a tabbed window. JTable Encapsulates a table-based control. JTextField The Swing version of a text field. JTree Encapsulates a tree-based control.

6 Creating a Swing Applet and Application import javax.swing.*; import java.awt.event.*; /* */ //This is Swing Applet public class THello extends JApplet { public void init() { getContentPane().add(new JLabel("Hello Swing World !!")); }

7 Creating a Swing Applet and Application //This is to run this program as Swing application public static void main(String args[]) { JFrame f=new JFrame("THello"); THello helloApplet = new THello(); helloApplet.init(); //Add the applet to the JFrame f.getContentPane().add(helloApplet); f.addWindowListener(new WindowEventHandler()); f.setSize(500,500); f.show(); }

8 Creating a Swing Applet and Application class WindowEventHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); }

9 Swing Applet (OUTPUT)

10 Swing Application (OUTPUT)


Download ppt "Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”"

Similar presentations


Ads by Google