Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Export main method to Main class  RSS feed

 
peter meyer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a project which is done in Eclipse.
I have a class called Start and in there the main method is mentioned, which I would like to export to an own Main.class.
Unfortunately, it's not working. I can't see any error messages in Eclipse so it's hard to describe where the failure is.

Here is my Start.class:


This is the part I would like to export:


As well I don't want to use the EventQueue in the new Main.class...

Thanks a lot for the help...
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with having the main method where it is? You should explain why you want to move it.
The code is exactly the same in Eclipse as on a text editor.

Why are you using EventQueue? Your game was a Swing application before, so you should continue to use EventQueue (or SwingUtilities which uses EventQueue anyway). You should start the Event Dis#x2011;safe.patch Thread (=EDT) anyway because Swing is not thread&safe.
It is not usual to say you are exporting a method. You can simply inactivate the main method in the Start class by changing its access modifier so it is no longer public. You should also remove the keyword static from all the other methods in the Start class. If you are using Java8 you can use the shorter form of the main method. You simply write thisNote there is no need for any error handling. In Java7 you would have written an anonymous class as you had before:-
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peter meyer wrote:I have a class called Start and in there the main method is mentioned, which I would like to export to an own Main.class.

OK.

First question: Why?

Second question: Why are all your methods static? That suggests that this is a utility class, but it actually appears to be some sort of game.

Third question: If you wanted a tournament of these games, with several "matches" going on simultaneously, how would you do it?

Suggestion: Before you start worrying about "exporting" stuff, make your game class an object - ie, get rid of every single static method in it except main().
And you can find out how to do that here.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!