java - 按同意时如何添加 JOptionPane
问题描述
我想创建一个自定义 jOptionPane 没有 YES/NO 但 AGREE/DISAGREE。当我按下同意时,我想要一个 showMessageDialog 框。你能帮我吗?
JFrame frame = new JFrame();
String[] options = new String[2];
options[0] = "Agree";
options[1] = "DISAGREE";
JOptionPane.showOptionDialog(frame.getContentPane(),"Would you like to
continue?","Message",
0,JOptionPane.INFORMATION_MESSAGE,null,options,null);
解决方案
希望对您有所帮助。
JFrame frame = new JFrame();
String[] options = new String[2];
options[0] = "Agree";
options[1] = "DISAGREE";
int result= JOptionPane.showOptionDialog(frame.getContentPane(),"Would you like to continue?","Message",
0,JOptionPane.INFORMATION_MESSAGE,null,options,null);
if(result==1){//when disagree
JOptionPane.showMessageDialog(frame, "Disagree!");
}else if(result==0){//when agree
JOptionPane.showMessageDialog(frame, "Agree!");
}
推荐阅读
- javascript - Await 仅在异步函数中有效
- excel - 如何验证电子邮件地址格式?
- google-cloud-platform - 在 GCP 中查询项目列表
- string - 恐慌:运行时错误:切片超出范围 [2:1]
- c# - C#:运行程序并用 if 语句回答输入后,我如何让程序继续提问?
- kubernetes - 如何在 GCP 中启用 Kubernetes API?没有按照文档在这里整理
- nginx - 使用 Terraform 在没有“remote_exec”的情况下安装 NGINX
- python - 从 div 类中收集链接
- mysql - 无法从我的 Mac 使用 SQLAlchemy 连接到 mysql:// 实例
- python - 使用 pandas 过滤和计数组