公司java培训教材分享(2)-----JFC简介
2006-10-19 17:46
405 查看
JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. JFC was first announced at the 1997 JavaOneSM developer conference. It is defined as containing the features shown in the table below.
The Swing API is powerful, flexible--and immense. In release 1.4 of the Java platform, the Swing API has 17 public packages:
javax.accessibility javax.swing.plaf javax.swing.text.html
javax.swing javax.swing.plaf.basic javax.swing.text.parser
javax.swing.border javax.swing.plaf.metal javax.swing.text.rtf
javax.swing.colorchooser javax.swing.plaf.multi javax.swing.tree
javax.swing.event javax.swing.table javax.swing.undo
javax.swing.filechooser javax.swing.text
Fortunately, most programs use only a small subset of the API. This trail sorts out the API for you, giving you examples of common code and pointing you to methods and classes you're likely to need. Most of the code in this trail uses only one or two Swing packages:
javax.swing
javax.swing.event (not always required)
Example One: Your First Swing Program
/*
* HelloWorldSwing.java is a 1.4 example that
* requires no other files.
*/
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
This is one of the simplest Swing applications you can write. It doesn’t do much, but the code demonstrates the basic code in every Swing program:
1. Import the pertinent packages.
2. Set up a top-level container.
3. Display the container.
4. Be thread-safe.
Every program with a Swing GUI must have at least one top-level Swing container. A top-level Swing container provides the support Swing components need for painting and event handling. There are three commonly used top-level Swing containers: JFrame, JDialog, and (for applets) JApplet. Each JFrame object implements a single main window, and each JDialog implements a secondary window (a window dependent on another window). Each JApplet object implements an applet’s display area within a browser window
The HelloWorldSwing example has only one top-level container, a JFrame. Imple-mented as an instance of the JFrame class, a frame is a window that, by default, has dec-orations such as a border, a title, and buttons for iconifying and closing the window. Applications with a GUI typically use at least one frame.
Here is the code that sets up and shows the frame:
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("HelloWorldSwing");
...
frame.pack();
frame.setVisible(true);
With the exception of top-level containers, such as JFrame, all Swing components descend from the JComponent class. HelloWorldSwing uses a JComponent descendant called JLabel, which displays the text Hello World. These two lines of code construct and then add the JLabel component to the frame:
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
To make the program exit when the Close button
is clicked, we include this code:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
The final bit of code in HelloWorldSwing—-and in all of our examples—-looks like this:
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
/* create and show the GUI */
}
});
You can copy this code and use it as-is. It might look daunting, but we recommend it because it ensures that the GUI won’t have a thread-safety problem that could break the UI before it even appears onscreen. For more information, you can read How to Use Threads.
The Swing API is powerful, flexible--and immense. In release 1.4 of the Java platform, the Swing API has 17 public packages:
javax.accessibility javax.swing.plaf javax.swing.text.html
javax.swing javax.swing.plaf.basic javax.swing.text.parser
javax.swing.border javax.swing.plaf.metal javax.swing.text.rtf
javax.swing.colorchooser javax.swing.plaf.multi javax.swing.tree
javax.swing.event javax.swing.table javax.swing.undo
javax.swing.filechooser javax.swing.text
Fortunately, most programs use only a small subset of the API. This trail sorts out the API for you, giving you examples of common code and pointing you to methods and classes you're likely to need. Most of the code in this trail uses only one or two Swing packages:
javax.swing
javax.swing.event (not always required)
Example One: Your First Swing Program
/*
* HelloWorldSwing.java is a 1.4 example that
* requires no other files.
*/
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
This is one of the simplest Swing applications you can write. It doesn’t do much, but the code demonstrates the basic code in every Swing program:
1. Import the pertinent packages.
2. Set up a top-level container.
3. Display the container.
4. Be thread-safe.
Every program with a Swing GUI must have at least one top-level Swing container. A top-level Swing container provides the support Swing components need for painting and event handling. There are three commonly used top-level Swing containers: JFrame, JDialog, and (for applets) JApplet. Each JFrame object implements a single main window, and each JDialog implements a secondary window (a window dependent on another window). Each JApplet object implements an applet’s display area within a browser window
The HelloWorldSwing example has only one top-level container, a JFrame. Imple-mented as an instance of the JFrame class, a frame is a window that, by default, has dec-orations such as a border, a title, and buttons for iconifying and closing the window. Applications with a GUI typically use at least one frame.
Here is the code that sets up and shows the frame:
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("HelloWorldSwing");
...
frame.pack();
frame.setVisible(true);
With the exception of top-level containers, such as JFrame, all Swing components descend from the JComponent class. HelloWorldSwing uses a JComponent descendant called JLabel, which displays the text Hello World. These two lines of code construct and then add the JLabel component to the frame:
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
To make the program exit when the Close button
is clicked, we include this code:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
The final bit of code in HelloWorldSwing—-and in all of our examples—-looks like this:
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
/* create and show the GUI */
}
});
You can copy this code and use it as-is. It might look daunting, but we recommend it because it ensures that the GUI won’t have a thread-safety problem that could break the UI before it even appears onscreen. For more information, you can read How to Use Threads.
相关文章推荐
- 公司java培训教材分享(1)-----进阶
- 公司java培训教材分享(3)-----Layout介绍
- 传智播客JAVA培训--Android书籍分享
- 别人传来的一个Sybase培训教材,还不错,分享给大家。
- 公司培训https的pdf分享
- 公司内部培训SQL Server传统索引结构PPT分享
- 别人传来的一个Sybase培训教材,还不错,分享给大家,另一部份
- [置顶] 【正式发布】火星人敏捷开发手册2012-02-24(基于Scrum的敏捷开发免费培训教材及公司内部宣传材料)
- Java培训你的发射台公司的世界
- 中远公司JAVA培训资料
- 【Java就业培训教材】——集合的学习
- 2015年Java后台开发面试问题分享汇总(主流互联网公司面试经历)
- [置顶] 【正式发布】火星人敏捷开发手册2012-02-24(基于Scrum的敏捷开发免费培训教材及公司内部宣传材料)
- 【Java教程】分享Java培训的9个知识点
- “2013SARscape干涉雷达桂林培训班”分享之:培训教材
- 项目管理系列分享(三)——如何提高公司培训的效果
- [置顶] 【正式发布】火星人敏捷开发手册2012-02-24(基于Scrum的敏捷开发免费培训教材及公司内部宣传材料)
- 分享某公司JAVA实习生招聘代码面的一道题
- 张孝祥JAVA培训视频教材下载全集
- 【正式发布】火星人敏捷开发手册2012-12-25(基于Scrum的敏捷开发免费培训教材及公司内部宣传材料)