Short and sweet: I’d like to be able to run another .java file, from the click of a button in a GUI in Netbeans for Mac.
A little more explanation:
I am recreating a project I created when I started with java, to make it cleaner. I have done a lot of improvement, though one problem I had with it is that I had too many panels in one JFrame, and I ended up having large amounts of code setting visibilities whenever I change panel.
Eg:
jPanel1.setVisible(false);
jPanel2.setVisible(false);
jPanel3.setVisible(true);
I know I could just live with it, but I’d like to see if there is a way to separate the code/panels a bit more, as described in the following.
My first thought was to have multiple files; one for each page. Similar to how you would in html.
Therefore, I have LoginPage.java, and GuestMainPage.java.
If it is possible, I’d like to be able to link them, like: close LoginPage.java and open GuestMainPage.java, on the click of a button.
Basically, I want to be able to make it compile or open another .java file, when I click a button on my GUI.
(In case it helps, the file would be in the same project.)
Example If there is a way to open another file. Possibly by accessing terminal commands?
public class LoginPage extends javax.swing.JFrame {
//Excluded a bunch of generated code from Netbeans
private void Login(java.awt.event.MouseEvent evt) {
//Code executed on Mouse Click of a Button labeled Login.
if(username.equalsIgnoreCase("guest")){
//A bit of pseudocode
open(GuestMainPage.java);
close(LoginPage.java);
}
if(username.equalsIgnoreCase("admin")){
open(AdminMainPage.java);
close(LoginPage.java);
}
}
}
From research and experience, I know you can access other files, or other classes within the same project – thus the use of objects and such – but I don’t know if you can physically run the other file. I’d be able to live with the possibility of being able to access terminal through java. (And then have the power to do basically anything, I just cannot find how to do that either.)
I have looked through a lot of stackoverflow topics to try and find an answer, as well as a lot of googling, but I cannot find one that really answers my question. However, if there really is no way to do this, then I am perfectly happy with an answer confirming that, and if that is the case, I will just have to cope with multiple panels.
Thank you
-Ewan
You should try implementing an MVC pattern. Take a look at spring: http://www.springsource.org/