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

Swing and Threads

Name: Anonymous 2010-12-13 8:48

Hey, /prog/, I could use some help with my java homework.

I'm making a turn based game against a computer and after I make my move, I create a task that shows the computer moving the piece smoothly. All the numbers are right, but it just flat out won't call my paint method when I call repaint so it ends up just pausing for a moment and then instantly moving the piece to where it should end up.

I think this problem has something to do with different threads, but I've never really worked with multithreading before.

Have any ideas? Thanks for any and all help.

Name: Anonymous 2010-12-13 9:01

public void run()
    {
        // ARE WE DONE YET?
        int dx=move[1][0]-move[0][0];
        int dy=move[1][1]-move[0][1];
        frame.getBoardPanel().updateDraggedPiece((int)(dx*scale+move[0][0]),
                                                             (int)(dy*scale+move[0][1]));
        frame.getBoardPanel() LOCATION
        frame.getBoardPanel().repaint();//LINE THAT GETS SKIPPED
        scale+=.1;
        if (scale>=1)
        {
            frame.getBoardPanel().getGameBoard().getAI().setCurrentState(ImagePlacementState.PLACING_IMAGE);   
            cancel();
        }
    }

That's the run method for my task. Is there any obvious reason why repaint wouldn't work?

Name: Anonymous 2010-12-13 9:43

I just messed up copy/pasting.

The paintComponent method works everywhere else fine. And, I'm pretty sure that nothing else is being drawn when the task is running. I basically stop my code from moving on until the task is done.

Scale is set in the constructor.

public AnimateDrag(    JFrame initFrame, int[][] initMove)
    {
        frame=initFrame;
        move=initMove;
        scale=.1;
    }

and I gave run a period of 100.

Thanks for the help so far.

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