test.java

来自「《Java2图形设计卷II:Swing》配套光盘源码」· Java 代码 · 共 65 行

JAVA
65
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Test extends JFrame {
	public Test() {
		Container contentPane = getContentPane();
		JPanel panel = new JPanel();

		panel.setBorder(BorderFactory.createEtchedBorder());
		contentPane.add(panel,BorderLayout.CENTER);
		contentPane.add(GJApp.getStatusArea(),BorderLayout.SOUTH);

		GJApp.showStatus(GJApp.getResource("statusAreaText"));
	}
	public static void main(String args[]) {
		GJApp.launch(new Test(),"Status Area",300,300,450,300);
	}
}
class GJApp {
	static private JPanel statusArea = new JPanel();
	static private JLabel status = new JLabel("");
	static private ResourceBundle resources;

	static {
		resources = ResourceBundle.getBundle(
									"GJApp", Locale.getDefault());
	};

	private GJApp() {}  // defeat instantiation
	
	public static void launch(final JFrame f, String title,
							  final int x, final int y, 
							  final int w, int h) {
		f.setTitle(title);
		f.setBounds(x,y,w,h);
		f.setVisible(true);

		statusArea.setBorder(BorderFactory.createEtchedBorder());
		statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		statusArea.add(status);
		status.setHorizontalAlignment(JLabel.LEFT);

		f.setDefaultCloseOperation(
							WindowConstants.DISPOSE_ON_CLOSE);

		f.addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
		});
	}
	static public JPanel getStatusArea() {
		return statusArea;
	}
	static public void showStatus(String s) {
		status.setText(s);
	}
	static String getResource(String key) {
		return (resources == null) ? null : 
								     resources.getString(key);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?