Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java isn't recognizing my constructor

Tags:

java

Java can't seem to find my constructor, I have no idea whats wrong. Is there a problem with having the throuws InterruptedException? Any Help would be appreciated, Thanks!

    package gameloop;

    import javax.swing.*;

    public class GameLoop extends JFrame {
        private boolean isRunning;
        public int drawx = 0;
        public int drawy = 0;

        public void GameLoop() throws InterruptedException{   
            setSize(700, 700);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setVisible(true);

            while(isRunning){
                doGameUpdate();
                render();
                Thread.sleep(1);
                if (isRunning){
                    GameLoop();
                }
            } 
        }

        private void doGameUpdate() {
            GameUpdate GU = new GameUpdate();
        }

        private void render() {
            Draw dr = new Draw();
        }

       public static void main(String[] args) {
            GameLoop GL = new GameLoop();
        }
    }
like image 604
user2766847 Avatar asked Sep 11 '13 00:09

user2766847


2 Answers

A constructor is named exactly like its class, and has no return type. If you provide a return type, even void, you create a method called GameLoop. What you are looking for is

public GameLoop()

rather than

public void GameLoop()
like image 161
Jan Dörrenhaus Avatar answered Sep 28 '22 06:09

Jan Dörrenhaus


You need public GameLoop() constructors don't have return types

like image 31
Scary Wombat Avatar answered Sep 28 '22 07:09

Scary Wombat