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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
NetExpert-WarszawaCommented:
Have one.

You will need to call some method of Login class.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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
NetExpert-WarszawaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.