package text;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class text1 {
public static void main(String[] args) {
JFrame jframe = new JFrame();
//设置界面大小
jframe.setSize(600, 600);
//设置标题
jframe.setTitle("111");
//将界面顶至
jframe.setAlwaysOnTop(true);
//将其为与中间
jframe.setLocationRelativeTo(null);
//关闭窗口
jframe.setDefaultCloseOperation(3);
//取消隐藏容器
jframe.setLayout(null);
JButton jdb = new JButton("按键");
jdb.setSize(100,50);
jdb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("点击");
}
});
//将案件添加到界面当中
jframe.getContentPane().add(jdb);
//将其放在最上面
jframe.setVisible(true);
}
}
页面图形化,添加按钮
最新推荐文章于 2024-09-14 18:46:05 发布
该代码示例展示了一个使用JavaSwing库创建的基本图形用户界面(GUI),包含一个JFrame窗口和一个JButton。当用户点击按钮时,会触发ActionListener事件,打印出“点击”信息。
摘要由CSDN通过智能技术生成