1.1

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package one_ten;

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

public class GUI_1_1 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("changeBagColor");
//设置窗口的布局方式
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
//设置初始位置和大小
frame.setBounds(100, 200, 300, 300);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建按钮对象
JButton button_green = new JButton("green");
JButton button_red = new JButton("red");
//添加进窗口
frame.add(button_green);
frame.add(button_red);
}
}

运行检测:

1.2

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package one_ten;

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

public class GUI_1_2 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("changeBagColor");
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 300, 300);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板对象
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
//设置面板位置和大小
panel1.setBounds(0, 0, 300, 40);
panel2.setBounds(0, 40, 180, 100);
//将面板插入窗口
frame.add(panel1);
frame.add(panel2);

//创建按钮对象
JButton button1 = new JButton("按钮1");
JButton button2 = new JButton(" 按钮2 ");
//添加进窗口
panel1.add(button1);
panel2.add(button2);
}
}

运行检测:

1.3

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package one_ten;

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

public class GUI_1_3 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("changeBagColor");
//设置窗口的布局方式
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
//设置初始位置和大小
frame.setBounds(100, 200, 160, 150);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建按钮对象
JButton button_green = new JButton("Green");
JButton button_red = new JButton("Red");
//添加进窗口
frame.add(button_green);
frame.add(button_red);

button_green.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
frame.setBackground(Color.GREEN);
}
});

button_green.addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
frame.setBackground(Color.WHITE);
}
});
}
}

其实是个半成品,知识储备不足,写不出来

运行检测:

1.4

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package one_ten;

import java.awt.*;

import javax.swing.*;

public class GUI_1_4 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame();
//设置窗口的布局方式
frame.setLayout(new FlowLayout(FlowLayout.CENTER));
//设置初始位置和大小
frame.setBounds(100, 200, 260, 75);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


//创建标签
JLabel label = new JLabel("+");
//创建文本
JTextField text1 = new JTextField(5);
JTextField text2 = new JTextField(5);
JTextField text3 = new JTextField(5);
//创建按钮
JButton button = new JButton("=");
//插入窗口
frame.add(text1);
frame.add(label);
frame.add(text2);
frame.add(button);
frame.add(text3);

}
}

运行检测:

1.5

任务要求:

代码实现:

知识储备不足,写不出来

运行检测:

1.6

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package one_ten;

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

public class GUI_1_6 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame();
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 320, 240);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板对象
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel4 = new JPanel(new FlowLayout(FlowLayout.CENTER));
//设置各面板的位置
panel1.setBounds(0, 0, 150, 100);
panel2.setBounds(150, 0, 150, 100);
panel3.setBounds(0, 100, 150, 100);
panel4.setBounds(150, 100, 150, 100);
//将面板插入窗口
frame.add(panel1);
frame.add(panel2);
frame.add(panel3);
frame.add(panel4);
//创建按钮对象
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("1");
JButton button5 = new JButton("2");
JButton button6 = new JButton("1");
JButton button7 = new JButton("2");
JButton button8 = new JButton("1");
JButton button9 = new JButton("2");
//设置按钮的大小
button1.setPreferredSize(new Dimension(40,90));
button2.setPreferredSize(new Dimension(40,90));
button3.setPreferredSize(new Dimension(40,90));
button4.setPreferredSize(new Dimension(65,90));
button5.setPreferredSize(new Dimension(65,90));
button6.setPreferredSize(new Dimension(65,90));
button7.setPreferredSize(new Dimension(65,90));
button8.setPreferredSize(new Dimension(140,45));
button9.setPreferredSize(new Dimension(140,45));

//将组件插入窗口
panel1.add(button1);
panel1.add(button2);
panel1.add(button3);
panel2.add(button4);
panel2.add(button5);
panel3.add(button6);
panel3.add(button7);
panel4.add(button8);
panel4.add(button9);

}
}

运行检测:

2.1

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package one_ten;

import java.awt.*;

import javax.swing.*;

public class GUI_2_1 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("登录窗口");
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 300, 175);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
//设置面板位置
panel1.setBounds(25, 0, 250, 75);
panel2.setBounds(0, 75, 300, 50);
//插入窗口
frame.add(panel1);
frame.add(panel2);

//创建标签
JLabel label1 = new JLabel("用户名:");
JLabel label2 = new JLabel("密 码:");
//创建文本
JTextField text1 = new JTextField(15);
JTextField text2 = new JTextField(15);
//创建按钮
JButton button1 = new JButton("登录");
JButton button2 = new JButton("重置");
//组件插入面板
panel1.add(label1);
panel1.add(text1);
panel1.add(label2);
panel1.add(text2);
panel2.add(button1);
panel2.add(button2);

}
}

运行检测:

2.2

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package one_ten;

import java.awt.*;

import javax.swing.*;

public class GUI_2_2 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("登录窗口");
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 300, 175);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
//设置面板位置
panel1.setBounds(25, 0, 250, 75);
panel2.setBounds(0, 75, 300, 50);
//插入窗口
frame.add(panel1);
frame.add(panel2);

//创建标签
JLabel label1 = new JLabel("用户名:");
JLabel label2 = new JLabel("密 码:");
//创建文本
JTextField text1 = new JTextField(15);
JTextField text2 = new JTextField(15);
//创建按钮
JButton button1 = new JButton("确定");
JButton button2 = new JButton("取消");
//组件插入面板
panel1.add(label1);
panel1.add(text1);
panel1.add(label2);
panel1.add(text2);
panel2.add(button1);
panel2.add(button2);
}
}

运行检测:

3

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package one_ten;

import java.awt.*;

import javax.swing.*;

public class GUI_3 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("简易计算器");
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 570, 625);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel panel2 = new JPanel(new GridLayout(5, 4, 5, 5));
//设置面板位置
panel1.setBounds(0, 0, 550, 75);
panel2.setBounds(0, 75, 550, 500);
//插入窗口
frame.add(panel1);
frame.add(panel2);

//创建文本
JTextField text = new JTextField("0");
//设置文本大小
text.setPreferredSize(new Dimension(540, 60));

//创建按钮对象
JButton button1 = new JButton("CE");
JButton button2 = new JButton("C");
JButton button3 = new JButton("Back");
JButton button4 = new JButton("%");
JButton button5 = new JButton("7");
JButton button6 = new JButton("8");
JButton button7 = new JButton("9");
JButton button8 = new JButton("/");
JButton button9 = new JButton("4");
JButton button10 = new JButton("5");
JButton button11 = new JButton("6");
JButton button12 = new JButton("*");
JButton button13 = new JButton("1");
JButton button14 = new JButton("2");
JButton button15 = new JButton("3");
JButton button16 = new JButton("+");
JButton button17 = new JButton("0");
JButton button18 = new JButton(".");
JButton button19 = new JButton("=");
JButton button20 = new JButton("-");
//组件插入面板
panel1.add(text);
panel2.add(button1);
panel2.add(button2);
panel2.add(button3);
panel2.add(button4);
panel2.add(button5);
panel2.add(button6);
panel2.add(button7);
panel2.add(button8);
panel2.add(button9);
panel2.add(button10);
panel2.add(button11);
panel2.add(button12);
panel2.add(button13);
panel2.add(button14);
panel2.add(button15);
panel2.add(button16);
panel2.add(button17);
panel2.add(button18);
panel2.add(button19);
panel2.add(button20);

}
}


运行检测:

4

任务要求:

代码实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package one_ten;

import java.awt.*;

import javax.swing.*;

public class GUI_4 {
public static void main(String[] args) {
//创建一个窗口对象,并添加标题
JFrame frame = new JFrame("信息表");
//设置窗口的布局方式
frame.setLayout(null);
//设置初始位置和大小
frame.setBounds(100, 200, 300, 250);
//设置窗口是否可以伸缩
frame.setResizable(false);
//设置窗口是否显示
frame.setVisible(true);
//设置关闭方式
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//创建面板
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));

//设置面板位置
panel.setBounds(35, 0, 230, 250);
//插入窗口
frame.add(panel);

//创建标签
JLabel label1 = new JLabel("姓名:");
JLabel label2 = new JLabel("性别:");
JLabel label3 = new JLabel("学号:");
JLabel label4 = new JLabel("专业:");
JLabel label5 = new JLabel("班级:");
JLabel label6 = new JLabel("籍贯:");
//创建文本
JTextField text1 = new JTextField(15);
JTextField text2 = new JTextField(15);
JTextField text3 = new JTextField(15);
JTextField text4 = new JTextField(15);
//创建下拉列表框
JComboBox<String> box1 = new JComboBox<String>();
JComboBox<String> box2 = new JComboBox<String>();
JComboBox<String> box3 = new JComboBox<String>();
//添加下拉内容
box1.addItem("男");
box1.addItem("女");
box2.addItem("河北省");
box2.addItem("河南省");
box2.addItem("湖南省");
box2.addItem("湖北省");
box3.addItem("邢台市");
box3.addItem("邯郸市");
box3.addItem("石家庄市");
box3.addItem("廊坊市");
box1.setPreferredSize(new Dimension(150, 20));
//创建按钮
JButton button1 = new JButton("确定");
JButton button2 = new JButton("取消");
//组件插入面板
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(box1);
panel.add(label3);
panel.add(text2);
panel.add(label4);
panel.add(text3);
panel.add(label5);
panel.add(text4);
panel.add(label6);
panel.add(box2);
panel.add(box3);
panel.add(button1);
panel.add(button2);
}
}

运行检测: