⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingwork.java

📁 图形界面设计
💻 JAVA
字号:

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

/*
 * Created on 2005-4-6
 *
 *	题目:
 *	分别编程使用五种布局方式显示一个容器和其中的
 *	三个Button、三个CheckBox和、三个TextArea。
 *
 */

/**

 * Preferences - Java - Code Style - Code Templates
 */
public class SwingWork extends JFrame {
	private static final long serialVersionUID = 1L;

	private JButton button = new JButton("改变状态");

	private JPanel jp1 = new JPanel();

	private JPanel jp2 = new JPanel();

	private JPanel jp3 = new JPanel();

	private JPanel jp4 = new JPanel();

	private JPanel jp5 = new JPanel();

	static int i = 0;

	public SwingWork() {

		Container cp = getContentPane();
		cp.setLayout(new GridLayout(1, 5));
		//	添加组件
		cp.add(jp1);
		cp.add(jp2);
		cp.add(jp3);
		cp.add(jp4);
		cp.add(jp5);
		//	设置边框和边框标题
		jp1.setLayout(new BorderLayout());
		jp1.setBorder(new TitledBorder("1"));
		for (int k = 0; k < 3; k++) {
			jp1.add(BorderLayout.NORTH, new JButton("button" + k));
			jp1.add(BorderLayout.SOUTH, new JCheckBox("checkBox" + k));
			jp1.add(BorderLayout.CENTER, new JTextArea("textArea " + k));
		}
		jp2.setBorder(new TitledBorder("2"));
		jp2.setLayout(new FlowLayout());
		for (int k = 0; k < 3; k++) {
			jp2.add(new JButton("button" + k));
			jp2.add(new JCheckBox("checkBox" + k));
			jp2.add(new JTextArea("textArea " + k));
		}
		jp3.setBorder(new TitledBorder("3"));
		jp3.setLayout(new GridLayout(5, 3));
		for (int k = 0; k < 3; k++) {
			jp3.add(new JButton("button" + k));
			jp3.add(new JCheckBox("checkBox" + k));
			jp3.add(new JTextArea("textArea " + k));
		}
		jp4.setBorder(new TitledBorder("4"));
		jp4.setLayout(new GridBagLayout());
		for (int k = 0; k < 3; k++) {
			jp4.add(new JButton("button" + k));
			jp4.add(new JCheckBox("checkBox" + k));
			jp4.add(new JTextArea("textArea " + k));
		}
		jp5.setBorder(new TitledBorder("5"));
		jp5.setLayout(new BoxLayout(jp5, BoxLayout.Y_AXIS));
		for (int k = 0; k < 3; k++) {
			jp5.add(new JButton("button" + k));
			jp5.add(new JCheckBox("checkBox" + k));
			jp5.add(new JTextArea("textArea " + k));
		}
		//	设置可见和大小
		this.setSize(800, 600);
		this.setVisible(true);
	}

	public static void main(String[] args) {
		SwingWork Test = new SwingWork();
	}
}

⌨️ 快捷键说明

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