时间:2022-03-02 09:07:26 | 栏目:JAVA代码 | 点击:次
先在该窗体的initUI()中初始化中写一句
// 关闭的事件 this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
该语句作用就是让窗体关闭时不作为,而是启动下面的方法,下面的方法必须写在bindevent中的监听器中


可以使用JoptionPane:
有几种提示框:
JOptionPane.showMessageDialog(jPanel, "提示消息", "标题",JOptionPane.WARNING_MESSAGE);

int n = JOptionPane.showConfirmDialog(null, "你高兴吗?", "标题",JOptionPane.YES_NO_OPTION);//返回的是按钮的index i=0或者1

Object[] obj2 ={ "足球", "篮球", "乒乓球" };
String s = (String) JOptionPane.showInputDialog(null,"请选择你的爱好:\n", "爱好", JOptionPane.PLAIN_MESSAGE, new ImageIcon("icon.png"), obj2, "足球");
