Java does not recognize my constructor

Java, it seems, cannot find my constructor, I have no idea what is wrong. Is there a problem with InterruptedException entanglement? 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(); } } 
+4
source share
4 answers

A constructor is called exactly the same as its class, and does not have a return type. If you specify a return type, even void , you will create a method called GameLoop . What you are looking for is

 public GameLoop() 

but not

 public void GameLoop() 
+6
source

This is not a constructor - it is:

 public GameLoop() throws InterruptedException 

A constructor cannot have a return type ( void in your code), if you add it, Java will interpret it as a regular method - even if it is called exactly the same as the class!

+4
source

You need public GameLoop() constructors do not have return types

+3
source

The constructor has a return type, so it is treated like any other method

+3
source

Source: https://habr.com/ru/post/1501570/


All Articles