要怎样定义xmsgbox才能让他返回一个 int ?
 
对, 不要将它定义为构造函数。

解决方案 »

  1.   

    我知道构造函数没有返回值,但是定义一个public int getresult(int lc_box_type,String lc_box_messagestring)
    那调用时岂不是要int lc_result;
    xmsgbox box1 = new xmsgbox();
    lc_result = box1.getresult(21,"请决定你的命运吧?");不知道我说的对不对?
      

  2.   

    TO : cutelion(MADEinCNNC)
    我试了把他定义成:
    public int xmsgbox(int lc_box_type,String lc_box_messagestring)
    {
       box_type = lc_box_type;
       box_messagestring = lc_box_messagestring;
       theChoice = JOptionPane.showConfirmDialog( null,box_messagestring, "提示信息",
    JOptionPane.YES_NO_OPTION ,
    JOptionPane.WARNING_MESSAGE );
       return theChoice;
    }
    调用时:
    int lc_result;
    xmsgbox box1 = new xmsgbox();
    lc_result = box1.getresult(21,"请决定你的命运吧?");
    编译出错啊
      

  3.   

    试试:import java.lang.*;
    import javax.swing.*;public class xmsgbox 
    {
    int box_type;
    String box_messagestring;
    public int theChoice; public xmsgbox(String lc_box_messagestring)
    {
    JOptionPane.showMessageDialog(null,lc_box_messagestring);
    }

    public xmsgbox(int lc_box_type,String lc_box_messagestring)
    {
    box_type = lc_box_type;
    box_messagestring = lc_box_messagestring;
    theChoice = JOptionPane.showConfirmDialog( null,box_messagestring,
                                                           "提示信息",
    JOptionPane.YES_NO_OPTION ,
    JOptionPane.WARNING_MESSAGE );
    } public int getTheChoice(){
    return this.theChoice;
    }
    }调用xmsgbox的Jsample.java部分代码如下:
    ....................
    public void windowOpened(WindowEvent e)
    {
        xmsgbox box1 = new xmsgbox(21,"请决定你的命运吧?");
        if (box1.getTheChoice() == JOptionPane.YES_OPTION)
        {
          JOptionPane.showMessageDialog(null,"我选了YES");
          xmsgbox box2 = new xmsgbox("^_^,你选对了,我给你一个代号吧:ASC");
          T1.setText("asc");
        }
        else
        {
          JOptionPane.showMessageDialog(null,"我选了NO");
          xmsgbox box3 = new xmsgbox("为什么我选择NO,你就不给我代号");
          T1.setText("");
        }
    }