一、最初的试探
如何从命令行编译和运行Swing应用程序。需要按照如下步骤:
- 安装最新版本的 Java SE 平台(如果您尚未安装)。
- 创建一个使用 Swing 组件的程序。
- 编译程序。
- 运行程序。
1.1 安装最新版的Java SE平台
可以从http://www.oracle.com/technetwork/java/javase/downloads/index.html免费下载最新版本的 JDK 。
1.2 创建一个使用Swing组件的程序
一个位于包start中的HelloWorldSwing.java文件。
package start;
/*
* HelloWorldSwing.java 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() {
//Create and set up the window.
JFrame frame = new JFrame("HelloW