Results 1 to 4 of 4
- 04-12-2011, 10:48 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Using main method to start off app
I'm stuck on how to use the main method. Before I noved the project to another computer it just kept telling me that all the methods I put couldn't run as they weren't static. How are you meant to initialize the main method.
Also now it's stopped working since I moved the project. Netbeans keeps saying I have no main class. Here's the code:
Java Code:import java.util.ArrayList; //import java.util.Iterator; import java.awt.*; import java.awt.event.*; import java.net.*; import javax.swing.*; public class TicTacToe extends Panel implements ActionListener { // the money inside a money bag //public static int REWARD = 1000; // the cost of opening an empty bag // p//ublic static int COST = 250; // the size of the game board and total number of money bags public static int ROW_COUNT = 3; public static int COLUMN_COUNT = 3; //public static int BAG_COUNT = 10; // the fields that report how a player’s doing //private JTextField moneyField; //private JTextField foundField; // the restart button public JButton restart; // a player’s money and the number of money bags found //public int money; //public int found; // the game board private Board board; public int numPlayers = 2; public Player currPlayer; ArrayList<Player> players = new ArrayList<Player>(); //ArrayList player = new ArrayList(); //public Player[] player; // create the app public static void main(String[] args) { System.out.println("Hello world!"); }
- 04-12-2011, 11:05 PM #2
There are several ways to do it.
Java Code:class Foo { public Foo() {} public Foo(String s) { run(s); } public void run(String s) { System.out.println(s); } public static void main(String[] args) { new Foo("Hello World"); new Foo().run("Hello World"); Foo f = new Foo(); f.run("Hello World"); } }
- 04-12-2011, 11:07 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
I've sorted the no main class problem - it was the IDE trying to open a different file/project from a previous project that was left open but I'm still stuck on how to initialize a desktop application.
Any tips please?
- 04-12-2011, 11:17 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Running main method class from another main class
By tlrocketman in forum New To JavaReplies: 3Last Post: 12-06-2010, 08:30 AM -
Main method
By vibaviattigala in forum New To JavaReplies: 2Last Post: 11-07-2010, 02:29 PM -
Calling The main method from another method
By SwissR in forum New To JavaReplies: 3Last Post: 07-27-2010, 11:03 AM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
main method
By eva in forum New To JavaReplies: 5Last Post: 12-19-2007, 09:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks