Download presentation
Presentation is loading. Please wait.
1
JFC and the Swing Package Feb 10, 2000
2
Java Foundation Class (JFC) zAWT (Abstract Window Toolkit) has been used since jdk1.0 Archaic and very poorly designed zSwing is a part of JFC, which is a huge library set containing more than 300 classes. zWe will use JFC, especially Swing. zDifference between AWT and Swing can be explained with lightweight and heavyweight component.
3
Overview of JComponent zControl or Widget denotes the group of all the GUI things that users can press, scroll, type into and etc. zIn Java, we use the term component instead of control. zEspecially in Swing, the term JComponent is used. zEach component in Swing set is a subclass of javax.Swing.Jcomponent zIn Java, it is a component that generate Event!!!
4
Visual Index of Basic Swing Component
5
How to Display Component zComponent should be added into container to be used. (Topic of next lecture) zFor today, we use JFrame container without detailed explanation. zHowever, we do not put components directly into JFrame. zInstead we put components into intermediate container. (Topic of next lecture) zFor today, we use one such container in JFrame
6
import java.awt.*; import java.awt.event.* import javax.swing.*; public class SwingDemo { JFrame frame; Container pane; SwingDemo(int w, int h) { frame = new JFrame(); frame.setSize(w,h); pane = frame.getContentPane(); pane.setLayout(new FlowLayout()); frame.setVisible(true); } public static void main(String args[]) { int w = Integer.parseInt(args[0]); int h = Integer.parseInt(args[1]); SwingDemo demo = new SwingDemo(w,h); } } // End of SwingDemo % java SwingDemo 400 300
7
SwingDemo(int w, int h) { frame = new JFrame(); frame.setSize(w,h); pane = frame.getContentPane(); pane.setLayout(new FlowLayout()); JButton b= new JButton(“click me”); pane.add(b); frame.setVisible(true); } ………... ImageIcon icon = new ImageIcon(“duke.gif”); JLable label = new JLabel(“I am Duke”, icon, JLabel.CENTER) pane.add(label); frame.setVisible(true); }
8
………... ImageIcon icon = new ImageIcon(“duke.gif”); JLable label = new JLabel(“I am Duke”, icon, JLabel.CENTER); pane.add(label); JTextField text = new JTextField(10); text.setBackground(Color.yellow); pane.add(text); frame.setVisible(true); } ………... ImageIcon icon = new ImageIcon(“duke.gif”); JLable label = new JLabel(“I am Duke”, icon, JLabel.CENTER); label.setToolTipText(“Leave me alone!!!”); pane.add(label); …………. frame.setVisible(true); }
9
General Structure of Swing Application Not used today
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.