Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:01+00:00 2026-05-26T13:43:01+00:00

Short and sweet : I’d like to be able to run another .java file,

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:43:02+00:00Added an answer on May 26, 2026 at 1:43 pm

    You should try implementing an MVC pattern. Take a look at spring: http://www.springsource.org/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'l be short and sweet! How can I put an object like JSplitPane in
Short and sweet summary: When changing a class from View -derived to ViewGroup -derived,
Short and sweet, Is it ok to use (current version) Ruby 1.9.1 with Rails
Short and sweet version: On one machine out of around a hundred test machines
Ok, I'll try and keep this short, sweet and to-the-point. We do massive GeoIP
Short of putting a UIWebView as the back-most layer in my nib file, how
Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short of copying the entire .netbeans directory is there any way to transfer custom
Short and sweet version: Is there a single web service method that would return
Short and sweet question: I've inherited a Pylons site with a bunch of models.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.