I have a jFrame form called "gui.java" and basically im passing it to user class in user package like so:
import user.User;
public class gui extends javax.swing.JFrame {
public gui() {
initComponents();
}
private void userFormRegisterBtnActionPerformed(java.awt.event.ActionEvent evt) {
// passed "this" to user class in another package but cannot access it's components
User.registerUser(this);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
gui a = new gui();
a.setVisible(true);
}
});
}
}
And here is the User Class:
import shopproject.gui;
public class User {
public static void registerUser(gui mainFrame) {
System.out.println("checking registration credentials");
// cannot access component of mainFrame called "userFormUsernameField".
mainFrame.userFormUsernameField.getText();
}
}
Here i cannot access userFormUsernameField or other components of the mainframe like JPanels JLabels etc.