import javax.swing.JOptionPane;public class Test{
  public static void main(String args[]){
    optionPane MPane = new optionPane();
    MPane.showMessageDialog(null, "xxxxxx");
    System.out.println(MPane.getString());
  }
}class optionPane extends JOptionPane{
  public String getString(){
    return "String From JOptionPane";
  }
}看明白了吗?

解决方案 »

  1.   

    哦,你弄错我的意思了。showMessageDialog(null, "xxxxxx");的时候,它所在的线程会停下来,等待这个对话框被关闭才继续运行我要的是这个。System.out.println("对话框被关闭后我才显示!");这句代表其他所有后面的代码,大概不可能用 您的方法实现吧我粗粗看过 Dialog.java 代码,头大,没看出什么
      

  2.   

    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class DialogTest extends JDialog
    {
        private boolean okPressed;
        
        public DialogTest(JFrame owner, String title)
        {
            super(owner, title, true);
            initDialog();
        }    private void initDialog()
        {
            setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            
            JButton okButton = new JButton("确定");
            okButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    okPressed = true;
                    DialogTest.this.dispose();
                }
            });
            
            JButton cancelButton = new JButton("取消");
            cancelButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    okPressed = false;
                    DialogTest.this.dispose();
                }
            });
            
            JPanel panel = new JPanel();
            panel.add(okButton);
            panel.add(cancelButton);
            
            getContentPane().add(panel, BorderLayout.SOUTH);
        }    public boolean showDialog()
        {
            okPressed = false;
            setVisible(true);
            return okPressed;
        }    public static void main(String[] args)
        {
            DialogTest dlg = new DialogTest(null, "test");
            dlg.setSize(320, 240);
            dlg.setLocation(240, 180);
            if(dlg.showDialog())
                System.out.println("ok pressed");
            else
                System.out.println("cancel pressed");        System.out.println("dialog closed");
            System.exit(0);
        }
    }
      

  3.   

    cbhyk() 谢谢!分不多,很久没来了,只剩30分了 sorry