Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:42:26+00:00 2026-06-17T04:42:26+00:00

I’m pretty new to Java (C# programmer) and I have here a problem that

  • 0

I’m pretty new to Java (C# programmer) and I have here a problem that I dont understand. Sorry for the crappy english. =)

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.

I think that its a simple error and im just to stupid to see it.

Here the code:

Mouse Event:

else if (mouseX > 75 && mouseX < 175 && mouseY > 260
                && mouseY < 285) {
            startGame();

startGame method in the Menu class:

public void startGame(){
    this.setVisible(false);
    game = new Game();
}

Game Constructor:

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

Intervall:

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
        }
    }
}

As i said before. If I start the Game class direct from Main method (simple with Game game = new Game();) there is no problem.

I hope I dont forgot any important information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:42:27+00:00Added an answer on June 17, 2026 at 4:42 am

    It shouldn’t work at all in any Swing GUI.

    Thread.sleep() kills repainting and listening.

    see final post here for example of problem

    http://www.coderanch.com/t/600642/GUI/java/update-getGraphics

    use a Swing Timer instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unable to fix a problem with Java Unicode and encoding. The
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.