Note that there are some explanatory texts on larger screens.

plurals
  1. POJFrame doesnt draw any figures, if startet from other JFrame
    primarykey
    data
    text
    <p>I'm pretty new to Java (C# programmer) and I have here a problem that I dont understand. Sorry for the crappy english. =)</p> <p>I'm working on a simple Snake game, I have different classes, enums etc.. My problem is, if I call the JFrame with the game from the Menu class, it doesnt do anything. I can debug through the code but it doesnt draw anything. If I start the Game class direct from the Main method, there is no problem.</p> <p>I think that its a simple error and im just to stupid to see it.</p> <p>Here the code:</p> <p>Mouse Event:</p> <pre><code>else if (mouseX &gt; 75 &amp;&amp; mouseX &lt; 175 &amp;&amp; mouseY &gt; 260 &amp;&amp; mouseY &lt; 285) { startGame(); </code></pre> <p>startGame method in the Menu class:</p> <pre><code>public void startGame(){ this.setVisible(false); game = new Game(); } </code></pre> <p>Game Constructor:</p> <pre><code>public Game() { super("Snake V 0.1"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(940, 620); setLocation(200, 200); addKeyListener(keyListener); setVisible(true); //this.createBufferStrategy(2); zeichnung.addFigur(new Field(0, 0)); snake = new Snake(40, 300, 1); zeichnung.addFigur(snake); zeichnung.addFigur(new Diamond()); this.getContentPane().add(jpanel); this.repaint(); this.Intervall(); } </code></pre> <p>Intervall:</p> <pre><code>public void Intervall() { while (true) { try { snake.direction = keyListener.getDirection(); zeichnung.checkCollision(snake); snake.move(); this.repaint(); Thread.sleep(150); } catch (InterruptedException e) { // TODO: handle exception } } } </code></pre> <p>As i said before. If I start the Game class direct from Main method (simple with Game game = new Game();) there is no problem.</p> <p>I hope I dont forgot any important information.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload