forked from liujiboy/Java_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAWTFrame.java
More file actions
36 lines (36 loc) · 1.05 KB
/
AWTFrame.java
File metadata and controls
36 lines (36 loc) · 1.05 KB
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
package cqu.gui;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
public class AWTFrame extends Frame{
private Button button=new Button("按键");
public AWTFrame()
{
setSize(300,300); //设置窗体大小
setLocation(400, 400); //设置窗体显示位置
setTitle("AWTFrame"); //设置窗体标题栏
//设置窗体关闭事件
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
setLayout(new FlowLayout()); //设置布局管理器
//添加按键事件
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, "点击了按键!");
}
});
add(button); //添加按键
}
public static void main(String[] args) {
AWTFrame frame=new AWTFrame();
frame.setVisible(true); //显示窗体
}
}