import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class GameFrame extends JFrame{
public void launchFrame(){
JButton button = new JButton("按钮");
this.setSize(200, 200);
this.setTitle("测试");
this.getContentPane().add(button);
this.setLocation(200, 100);
this.setResizable(false);
this.setVisible(true);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "用户单击了按钮", "INFORMATION_MESSAGE",JOptionPane.INFORMATION_MESSAGE);
}
});
}
public static void main(String[] args) {
new GameFrame().launchFrame();
}
}
在屏幕上显示一个带标题的窗口,并添加一个按钮
最新推荐文章于 2021-02-12 10:46:30 发布