我刚学java,学的不好,现在正在拼命的学,还请哪位路过的指教啊.
不胜感激!我想把在CheckInPanel类中的String类型的值设置为在CheckOutPanel类中的cardIdField的值,请问怎么能做到呢?
public class CheckInPanel extends JPanel {
public CheckInPanel() {  }
}public class CheckOutPanel extends JPanel {
 private JTextField cardIdField = new JTextField();
.....
  public CheckOutPanel() {
     this.add(cardIdField, null);
     cardIdField.setText("");  }
}

解决方案 »

  1.   

    public class CheckInPanel extends JPanel {
        public static String s = "hello word";  //定义一个静态的字符串 可以直接用类名调用
        public CheckInPanel() {    }
    }
    class CheckOutPanel extends JPanel //把public取掉,只能有一个public文件
    {
        private JTextField cardIdField = new JTextField();    public CheckOutPanel() {
            this.add(cardIdField, null);
            cardIdField.setText(CheckInPanel.s);
        }
    }
      

  2.   

    或者这样
    public class CheckInPanel extends JPanel {
        public String s = "hello word";
        public CheckInPanel() {    }
    }
    class CheckOutPanel extends JPanel {
        private JTextField cardIdField = new JTextField();
        CheckInPanel check=new CheckInPanel();
        public CheckOutPanel() {
            this.add(cardIdField, null);
            cardIdField.setText(check.s);
        }
    }
      

  3.   

    public class CheckInPanel extends JPanel {
        public String s = "hello word";
        public CheckInPanel() {    }
    }
    class CheckOutPanel extends JPanel {
        private JTextField cardIdField = new JTextField();
        CheckInPanel check=new CheckInPanel();
        public CheckOutPanel() {
            this.add(cardIdField, null);
            cardIdField.setText(check.s);
        }
    }我同意这一种
      

  4.   

    我试过了,不行啊,楼上能帮我写下吗?能帮我在看看吗
    public class CheckInPanel extends JPanel {
    public CheckInPanel() {
      }
    public void doCofirm(){
                       java.util.Date checkInTime;
    checkInTime = new java.util.Date();
    SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-HH:mm");
    String InTime = HMFromat.format(checkInTime);
     我是在这里得到InTime的,不是在CheckOutPanel类中调用设置cardIdField的,我想就在本类中来设置cardIdField.setText("");啊  }
    }
    ===============================================================================
    public class CheckOutPanel extends JPanel {
     private JTextField cardIdField = new JTextField();
    .....
      public CheckOutPanel() {
         this.add(cardIdField, null);
         cardIdField.setText("");  }
    }
      

  5.   

    public class CheckInPanel extends JPanel {
    public CheckInPanel() {
      }
    public void doCofirm(){
                       java.util.Date checkInTime;
    checkInTime = new java.util.Date();
    SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-HH:mm");
    String InTime = HMFromat.format(checkInTime);
    CheckOutPanel checkOutPanel=new CheckOutPanel(InTime); 
      }
    }
    //下边把构造方法重载一下
    public class CheckOutPanel extends JPanel {
     private JTextField cardIdField = new JTextField();
    .....
      public CheckOutPanel(String s) {
         this.add(cardIdField, null);
         cardIdField.setText(s);  }
    }