Download JFC and the Swing Package

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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.
Difference between AWT and Swing can be
explained with lightweight and heavyweight
component.
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!!!
Visual Index of Basic
Swing Component
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
import java.awt.*;
import java.awt.event.*
import javax.swing.*;
public class SwingDemo {
JFrame frame;
Container pane;
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
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
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);
}
………...
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);
}
General Structure of
Swing Application
Not used today
Related documents