Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need Help with Game

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Need Help with Game

    I am trying to start a new thread to call main() but i can't understand the error.

    package button_game;
     
    import javax.swing.*; 
    import java.awt.*;
    import java.awt.event.*;
    public class Button_Game {
        static int k;
    //A1 and B1 contain what to do when they are clicked. Right now they terminate the program until i figure out how to loop it.
        private static class A1 implements ActionListener{
        public void actionPerformed(ActionEvent e){
             k = 1;
              }
                                                  }
     
     
     private static class B1 implements ActionListener {
            public void actionPerformed(ActionEvent e){  
                System.exit(0);
                                                      }  
                                                       }
     //addComponentsToPane positions the buttons on the screen randomly
       public static void addComponentsToPane(Container pane){
           do {
                     int x; 
          x = (int)(200*Math.random());
          int y;
          y = (int)(200*Math.random());
            pane.setLayout(null);
           int a = (int)(1000*Math.random());
            int b = a%2;
            if (b == 0){
                String c = Integer.toString(a);
        JButton A2 = new JButton(c);
        JButton B2 = new JButton();
        A1 listener = new A1();
        A2.addActionListener(listener);                
        B2.addActionListener(listener);
        pane.add(B2);
        pane.add(A2);
        Insets insets = pane.getInsets();
        Dimension size = B2.getPreferredSize();
        B2.setBounds(x + insets.left, x + insets.top, size.width, size.height);
        size = A2.getPreferredSize();
        A2.setBounds(y + insets.left, y + insets.top, size.width, size.height);
                       }
            else if(b != 0);
            int c = a +1;
            String d = Integer.toString(c);
     JButton A2 = new JButton(d);
        JButton B2 = new JButton();
        A1 listener = new A1();
        A2.addActionListener(listener);                
        B2.addActionListener(listener);
        pane.add(B2);
        pane.add(A2);
        Insets insets = pane.getInsets();
        Dimension size = B2.getPreferredSize();
        B2.setBounds(x + insets.left, x + insets.top, size.width, size.height);
        size = A2.getPreferredSize();
        A2.setBounds(y + insets.left, y + insets.top, size.width, size.height); 
                                                              } while ( k == 1);
                   } 
        //this runs the game
     
        private static void runGUI(){
     
            JFrame window = new JFrame("Button Game");
            addComponentsToPane(window.getContentPane());
     
            window.setSize(300,300);
            window.setVisible(true);
     
     
        }
        public class Loop implements Runnable {
            public void run(){
                main();
            }
        }
     
    //this part runs the subroutine which runs the game
     
       public static void main(String Args[]){
    do{
      javax.swing.SwingUtilities.invokeLater(new Runnable(){
          public void run(){
              runGUI();
                           }
                                                });
    } while (k == 1);
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Help with Game

    i can't understand the error.
    What error? You forgot to post the full text of the error message.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Need Help with Game

    sorry this is the error: method main in class button_game.Button_Game cannot be applied to given types;
    required: java.lang.String[]
    found: no arguments
    reason: actual and formal argument lists differ in length
    ----

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need Help with Game

    The compiler can't see a main() method with no arguments. The only one it sees takes a String array as an argument. You need to add a String array as an argument in your method call.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Shivam24 (July 18th, 2011)

Similar Threads

  1. Game
    By aneeeeen in forum Paid Java Projects
    Replies: 2
    Last Post: April 16th, 2011, 08:32 AM
  2. Help me with My Game.
    By jtvd78 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 13th, 2011, 04:14 PM
  3. Game !
    By Ahmed.Ibrahem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 08:01 PM
  4. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM
  5. Job offers to program Hobo Wars
    By MooncakeZ in forum Paid Java Projects
    Replies: 7
    Last Post: September 17th, 2009, 09:41 PM