gpt4 book ai didi

java - 使用两个按钮确认 Swing 对话框

转载 作者:行者123 更新时间:2023-11-30 02:23:21 25 4
gpt4 key购买 nike

以下是我的swing程序代码

import javax.swing.*;  
import java.awt.event.*;
public class OptionPaneExample extends WindowAdapter{
JFrame f;
OptionPaneExample(){
f=new JFrame();
f.addWindowListener(this);
f.setSize(300, 300);
f.setLayout(null);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
int a=JOptionPane.showConfirmDialog(f,"Are you sure?");
if(a==JOptionPane.YES_OPTION){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new OptionPaneExample();
}
}

在输出中我只需要两个按钮"is"和“否”。但在输出中我得到了取消按钮。如何删除它请告诉我。

I'm getting this output. But i want only two buttons Yes and No.

最佳答案

int a=JOptionPane.showConfirmDialog(f,"Are you sure?", "Question", YES_NO_OPTION );

请阅读 JOptionPane 的文档.

关于java - 使用两个按钮确认 Swing 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46260980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com