我想做一个提示框,就是能提供确定,是,否按钮的那种,怎么样让这个框能有返回值,就像api里的JFileChooser里的showDialog一样,只有当点击了提示框中的按钮,才能返回一个值,程序才继续往下走!

解决方案 »

  1.   

    不是,比如要关闭一个窗体,应该要弹出一个对话框,问是否退出,我怎么样才能让他点击按钮返回值,这样好判断是点击了是还是点击了否,不用api里的showDialog什么的,想自己写一个这样的窗体,怎么做?
      

  2.   

    我也不知道怎么捕获弹出的对话框的按钮的动作。
    只知道JOpionPane里有个showConfirmDialog()方法,调出带有选项 Yes、No 和 Cancel 的对话框;标题为 Select an Option。
      

  3.   

    那个我知道了,我想自己写一个那样的,看JOptionPane里的代码没看懂
      

  4.   

    showMessageDialog
    public static void showMessageDialog(Component parentComponent,
                                         Object message,
                                         String title,
                                         int messageType)
                                  throws HeadlessException调出对话框,它显示使用由 messageType 参数确定的默认图标的 message。 参数:
    parentComponent - 确定在其中显示对话框的 Frame;如果为 null 或者 parentComponent 不具有 Frame,则使用默认的 Frame
    message - 要显示的 Object
    title - 对话框的标题字符串
    messageType - 要显示的消息类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE 或 PLAIN_MESSAGE 
    抛出: 
    HeadlessException - 如果 GraphicsEnvironment.isHeadless 返回 true
    另请参见:
    GraphicsEnvironment.isHeadless()
      

  5.   

    package jtable;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;import javax.swing.*;public class Test1 {
    public static JFrame frame;
    public static void main(String []args){
    frame=new JFrame("test");
    Container con=frame.getContentPane();
    con.setLayout(new BorderLayout());
    JButton button=new JButton("ok");
    button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent evt){
    int m=JOptionPane.showConfirmDialog(null, "nihao");
    if(m==0){
    frame.setTitle("nihao");
    }
    if(m==1){
    frame.setTitle("buhao");
    }
    if(m==2)
    frame.setTitle("douhao");
    }
    });
    frame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent evt){
    System.exit(0);
    }
    });
    con.add(button,BorderLayout.NORTH);
    frame.setSize(200, 300);
    frame.setVisible(true);
    }
    }