1 / 9

JFC and the Swing Package

JFC and the Swing Package. Feb 10, 2000. Java Foundation Class (JFC). AWT (Abstract Window Toolkit) has been used since jdk1.0 Archaic and very poorly designed Swing is a part of JFC, which is a huge library set containing more than 300 classes. We will use JFC, especially Swing.

tyanne
Download Presentation

JFC and the Swing Package

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JFC and the Swing Package Feb 10, 2000

  2. Java Foundation Class (JFC) • AWT (Abstract Window Toolkit) has been used since jdk1.0 Archaic and very poorly designed • Swing is a part of JFC, which is a huge library set containing more than 300 classes. • We will use JFC, especially Swing. • Difference between AWT and Swing can be explained with lightweight and heavyweight component.

  3. Overview of JComponent • Control or Widget denotes the group of all the GUI things that users can press, scroll, type into and etc. • In Java, we use the term component instead of control. • Especially in Swing, the term JComponent is used. • Each component in Swing set is a subclass of javax.Swing.Jcomponent • In Java, it is a component that generate Event!!!

  4. Visual Index of Basic Swing Component

  5. How to Display Component • Component should be added into container to be used. (Topic of next lecture) • For today, we use JFrame container without detailed explanation. • However, we do not put components directly into JFrame. • Instead we put components into intermediate container. (Topic of next lecture) • For today, we use one such container in JFrame

  6. 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 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); } % 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

More Related