Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java: infinite loop problem

Name: Anonymous 2010-04-27 6:56

So I have a game. The first thing the program does, is to create a JFrame and make a new object that extends JPanel. In this window, I enter some values and send them through the constructor of a new object (Game), after disposing the first frame. In this constructor, I create a few objects used in the game, then I open another JFrame and create a new object (Panel) that extends JPanel, from a completely different class than the last one. This object has a public void paintComponent(Graphics g) method, which I use to draw the game. The last line of the constructor of Game calls a method I have called private void steps(). It goes as follows:

private void steps () {
    double fps = 30;
    long wait = (long)(1000/fps);
    while (true) {
        update();
        getPanel().repaint();
        System.out.print(".");
        try {
            Thread.sleep(wait);
        } catch (InterruptedException e) {}
    }
}

The update() method calls a different step() method in each of my object that I use in the game, one of those could for example move the object two pixels to the right.

The getPanel() method just returns the Panel object I created earlier.

My problem is that while the new JFrame and JPanel opens, and I know the passing of values went fine because I can use them to set the title of the frame, nothing is drawn. The window won't respond to anything, not even closing, so it is obvious that it is stuck in some infinite loop. I know that it runs my steps() loop, and that it is stuck here. I just don't understand why it won't respond to my actions. My key listener won't respond, and it will not draw anything in the window.

Another aspect; this all worked before I added the very first JFrame and object extending JPanel. Is the problem maybe that I cannot use them twice in the same program? If so, how can I make it possible? I am really stuck here, and I wouldn't come on here if it was something I could solve by myself.

Name: Anonymous 2010-04-27 7:13

HEY IM OP IM TOO MUCH OF A CRETIN TO REALIZE THAT CODE GOES IN [code] TAGS BUT THE TOOLS AT PROG WILL STILL HELP ME ALTERNATIVELY IM FV

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List