How to set the main class to be run first

Hello,
I have main class, login class and mainmenu class and they are all in a same package name Myapp. When I run Myapp its listing all these three classe and asking me to select the main class.
Is there a way I can set up so that by running Myapp, it will execute the main class first without having me select from the list?
I am building this application using NetBeans and Swing

Any help would be really appreciated.
Thanks
guavamayAsked:
Who is Participating?
 
NetExpert-WarszawaConnect With a Mentor Commented:
See the example. You could put your "main" login code in a constructor of Login class too. It will be executed at new Login().
public class Main {

  Login login;

  public static void main(String[] args) {
    login = new Login();
    login.loginMainMethod();
  }
}

class Login {
  loginMainMethod() {
  }
}

Open in new window

0
 
NetExpert-WarszawaCommented:
You need main method in Main class

public static void main(String[] args) {\
...
}
0
 
guavamayAuthor Commented:
I do have that.
Also just want  to point out that my login class also has main method. So should I only have main method in my Main Class. If that the case then how can I call my login class from my main class so it will execute from main class?

Thanks.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
NetExpert-WarszawaCommented:
Have one.

You will need to call some method of Login class.
0
 
guavamayAuthor Commented:
In that case I should take out the main method from login class and add some method in my main class to call login class - correct?
Would you happen to have some sample code as a guide.

Thanks so much for your help.
0
 
guavamayAuthor Commented:
In your above sample, class Login portion of the codes, should it be in my Login class? Or in my Main Class?
In my Login class I have SubmitButtonActionPerformed where I connect to the database based  on user/password.

Thanks so much.





0
 
TheTutorialSpotDotComCommented:
NetBeans only do this if you did not select your main class. After you've selected your main class for this project NetBeans will no longer ask again if the project was saved after you've selected the main class. The main class is always the one with the main method in it because that is where all java programs starting point is.

public static void main(String[] args)
0
 
guavamayAuthor Commented:
Thanks for your help.

0
All Courses

From novice to tech pro — start learning today.