我无法将变量class main
传递给另一个类class members
...我尝试使用 getter-setter 但它只返回一个null
值,我该如何解决?这是我的代码:
主.java
public class Main extends JFrame{
JTextField txt = new JTextField(10);
String value;
Main(){
getContentPane().add(txt);
this.value = txt.getText();
setLayout(new FlowLayout());
setSize(300,200);
setVisible(true);
}//constructor of main
public String getValue(){
return this.value;
}//getValue
public static void main(String args[]){
new Main();
}//psvm
}//class main
成员.java
public class Members extends JFrame{
JLabel lbl = new JLabel("");
Main main = new Main();
Members(){
getContentPane().add(lbl);
main.setVisible(false);
lbl.setText(main.getValue());
setLayout(new FlowLayout());
setSize(300,200);
setVisible(true);
}//constructor of main
public static void main(String args[]){
new Members();
}//psvm
}//class members