I'm working on a assignment for university. The program use server/client(through sockets) along with a Model-View-Controller approach.
I'm creating a login screen with a JFrame, this login screen must call another JFrame depending on who just logged in. As the title says, I'm trying to pass the controller from the Login JFrame to another JFrame. With a JInternalFrame I would do it like this with a button:
NOTE: I want the second frame to be independent, I don't want to add JInternalFrames to a JDesktopPane
JFrame (I remove most of the autogenerated code):
package javaapplication1;
import Controller.Controller;
/**
*
* @author invitado
*/
public class MyFrame extends javax.swing.JFrame {
private Controller controller;
/**
* Creates new form myFrame
*/
public MyFrame() {
controller = new Controller();
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
MyInternalFrame internal = new MyInternalFrame(controller);
MyDesktopPane.add(internal);
internal.setVisible(true);
}
}
InternalFrame:
package javaapplication1;
import Controller.Controller;
/**
*
* @author invitado
*/
public class MyInternalFrame extends javax.swing.JInternalFrame {
private Controller c;
/**
* Creates new form MyInternalFrame
*/
public MyInternalFrame(Controller c) {
this.c = c;
initComponents();
}
}
This works for me all the time, but when I try it with a JFrame instead of a JInternalFrame a line gives me an error on new MyFrame2().setVisible(true);
public static void main(String args[]) {
/* Set the Nimbus look and feel */
. . .
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyFrame2().setVisible(true);
}
});
}
Should I put the parameter controller in MyFrame2().setVisible(true);
or there is another way to do it?