纯尺猜JFrame 做型f = this
// 里面这样写困孙
f.setVisible(false)
用到模伍JOptionPane.showConfirmDialog方法,showConfirmDialog 的返回类型是int,定义一个int类型的变量接收返回值,然后根据业务逻辑判断,代码看不懂,可以自行百度搜搏轮索或问同事,编程注重思想。import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.JFrame
import javax.swing.JOptionPane
public class JButtonTest extends JFrame
{
public static void main ( String[] args )
{
JButtonTest b = new JButtonTest ()
b.addWindowListener (new WindowAdapter ()
{
@Override
public void windowClosing ( WindowEvent e )
{
int exi = JOptionPane.showConfirmDialog (null, "要退出该程序吗?", "友情基码信提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
if (exi == JOptionPane.YES_OPTION)
{
System.exit (0)
}
else
{
return
}
}
})
b.setSize (300, 300)
b.setLocationRelativeTo (null)
b.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE)
b.setVisible (true)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)