?? swingwork.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 + -