我刚学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( " ");
}
}
------解决方案--------------------
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);
}
}
------解决方案--------------------
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);
}
}我同意这一种