首页 > 解决方案 > 按同意时如何添加 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);

标签: javadialog

解决方案


希望对您有所帮助。

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!");  
 }

推荐阅读