📄 example5_14.java
字号:
/* 显示确认对话框 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MDialog extends JFrame implements ActionListener
{
MDialog()
{
super("显示确认信息对话框");
setSize(200,200);
setVisible(true);
Container con=getContentPane();
con.setLayout(new FlowLayout());
JButton jbtn=new JButton("退出");
con.add(jbtn);
jbtn.addActionListener(this);
validate();
}
public void actionPerformed(ActionEvent e)
{
String msg="你确定退出吗?";
int type=JOptionPane.YES_NO_OPTION;
String tite="确认对话框";
int choice=0;
choice=JOptionPane.showConfirmDialog(null,msg,tite,type);
if (choice==0)
{ System.exit(0); }
else
System.out.println(choice);
}
}
//主类
public class Example5_14
{
public static void main(String[] args)
{ new MDialog();}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -