public class welcomepage extends javax.swing.JFrame {
backendcode bec;
String username;
public welcomepage() {
initComponents();
username=null;
backendcode bec= new backendcode("dummy");
System.out.println("bec created "+ bec);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("bec created "+ bec);
bec.back_login_credentials(username);
}
/*
and other private methods(not mentioned here) which also needs to access bec object
*/
}
public class backendcode {
public backendcode(String dummy) {
//some code
}
public void back_login_credentials(String username, String password) {
//some code
}
}
我已经将 bec(后端代码对象,以便它对整个类可见)声明为 Welcomepage 类中的成员数据并在其构造函数中进行了初始化,但它是在该构造函数中通过一些初始化创建的,但 jButton1ActionPerformed 方法中的 bec 对象值将为空。为什么会这样.. 获得初始化对象实例的解决方案是什么?