Results 1 to 4 of 4
  1. #1
    garrym is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default 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!");
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default

    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");
        }
    }

  3. #3
    garrym is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    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?

  4. #4
    garrym is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

Similar Threads

  1. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 08:30 AM
  2. Main method
    By vibaviattigala in forum New To Java
    Replies: 2
    Last Post: 11-07-2010, 02:29 PM
  3. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 11:03 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  5. main method
    By eva in forum New To Java
    Replies: 5
    Last Post: 12-19-2007, 09:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •