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