how to solve flickering?

As I'm trying to learn to use graphics in java I've written the beginning to a small game (one where u should bounce a ball and try to hit all the bricks). So far so god but now I've encountered a problem. I can't seem to stop the ball from flickering during play. The weird part is that it moves smooth during movment of the "pad". Anyone knows why this is so, 'cause I'm completly lost.

Any thougts on the code are welcome, I'm here to learn :).

The main class only creates a new instance of window.

Window.java
[code]package pinpad;

import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;


public class Window extends JFrame implements KeyListener{
Gamepanel pane;

public Window(){
super ("Pinpad");
setBounds(400,200,510,525);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pane = new Gamepanel();
addKeyListener(this);

setContentPane(pane);
setVisible(true);

while(true) {
if (!pane.pause && !pane.finish && !pane.endGame) {
try {
Thread.sleep(2);
}
catch (InterruptedException ie) {
}
pane.move();
//repaints all if it's a hit otherwise only the ball
if (pane.hit())
pane.repaint();
else {
pane.repaintBall();
}
}
else {
repaint();
}
}
}

@Override
public void keyTyped(KeyEvent e) {
}

@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();

switch (key) {
//left Arrow
case 37:
pane.moveBarL = true;
break;
//rigth arrow
case 39:
pane.moveBarR = true;
break;
//Enter
case 10:
pane.start = true;
pane.changeSpeed(0.8);
pane.repaint();
break;
//Pause || p
case 80:
case 19:
pane.pause = !pane.pause;
pane.repaint();
break;
//F2
case 113:
pane.newGame();
}
}

@Override
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
//left Arrow
if (key == 37) {
pane.moveBarL = false;
}
//right arrow
else if (key == 39) {
pane.moveBarR = false;
}
}
}
[/code]

Gamepanel.java
[code]package pinpad;

import javax.swing.JPanel;
import java.awt.geom.*;
import java.awt.*;

public class Gamepanel extends JPanel {
private int ballx = 250;
private int bally = 460;
private int direction = 90;
private double speed = 0;
private double exBallx = 250, exBally = 460;
private int barPos = 220;
public boolean moveBarR = false, moveBarL = false;
public boolean endGame = false, start = false, pause = false, finish = false;

//Creates a set of coordinates for the bricks
int[] xCord = {0, 60, 120, 180, 240, 300, 360, 420,
0, 120, 240, 360, 460};
int[] yCord = {0, 0, 0, 0, 0, 0, 0, 0,
30, 30, 30, 30, 30};
Brick[] brick = new Brick[xCord.length];
int count = brick.length;

public Gamepanel() {
//creates the bricks
for (int i = 0; i < brick.length; i++) {
brick[i] = new Brick(xCord[i], yCord[i]);
}
}

@Override
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D) comp;
Font f = new Font ("Monospaced", Font.ITALIC, 30);
FontMetrics fm = getFontMetrics(f);
comp2D.setFont(f);

//draw background
comp2D.setColor(Color.WHITE);
comp2D.fillRect(0,0,500,500);
//draw ball
comp2D.setColor(Color.MAGENTA);
comp2D.fillOval(ballx,bally,20,20);
//draw pad
comp2D.setColor(Color.BLACK);
comp2D.fill3DRect(barPos, 480, 80, 20, true);

//draw bricks
comp2D.setColor(Color.BLUE);
for (int i = 0; i < xCord.length; i++) {
if (!brick[i].bounced()) {
comp2D.fillRect(xCord[i], yCord[i], 50, 10);
}
}

if (!start) {
String startString = "Press ENTER to start!!";
comp2D.drawString(startString, ((500-fm.stringWidth(startString))/2), 250);
}

else if (endGame) {
String over = "GAME OVER!!!";
comp2D.drawString(over, ((500-fm.stringWidth(over))/2), 250);
}

else if (pause) {
String pauseString = "PAUSED!!";
comp2D.drawString(pauseString, ((500-fm.stringWidth(pauseString))/2), 250);
}

else if (finish) {
comp2D.drawString("Congratulations,", ((500-fm.stringWidth("Congratulations,"))/2), 250);
comp2D.drawString("You made it!!!", ((500-fm.stringWidth("you made it!!!"))/2), 250 + fm.getHeight());
}
}

public void move() {
if(!start) {
exBallx = barPos + 30;
}
if (!endGame) {
//bounce if hitting the sides
if ((ballx < 0) || (ballx > 480)) {
direction = bounceVertikal(direction);
exBallx = ballx < 0 ? 0:480;
}
//bounce if hitting the top
if (bally < 0) {
direction = bounceHorizontal(direction);
exBally = 0;
}
//bounce on pad if it's a hit
else if ((bally > 460) && (ballx < (barPos + 70)) && (ballx > barPos-5) && (bally < 465)) {
direction = bouncePad(direction);
exBally = 460;
}
// end game if ball leaves picture
else if (bally > 500) {
endGame = true;
}

//calculate new ballposition
exBallx = exBallx + (speed * Math.cos(Math.toRadians(direction)));
exBally = exBally - (speed * Math.sin(Math.toRadians(direction)));

ballx = (int) exBallx;
bally = (int) exBally;


//move bar if key is pressed
if ((moveBarR) && (barPos < 460)) {
barPos = barPos + 1;
repaint(barPos -1, 480, 82, 20);
}
if ((moveBarL) && (barPos > -30)) {
barPos = barPos - 1;
repaint(barPos -1, 480, 82, 20);
}
}
}

public int bounceHorizontal (int dir) {
dir = 360 - dir;
return dir;
}

public int bounceVertikal (int dir) {
dir = 180 - dir;
if (dir < 0) {
dir = 360 + dir;
}
return dir;
}

//checks if the ball hits any bricks
public boolean hit() {
if(bally < 200) {
for(int i = 0; i < brick.length; i++) {
if(brick[i].hit(ballx, bally)) {
direction = bounceHorizontal(direction);
count--;
if (count == 0)
finish = true;
return true;
}
}
}
return false;
}

private int bouncePad (int dir) {
int x = bounceHorizontal(dir);
x = x + 40 - (ballx - barPos +10);
if (x < 0) {
x = 360 + x;
}
return x;
}

//repaints the area where the ball is
public void repaintBall() {
repaint(ballx - 20, bally - 20, 60, 60);
}

//Resets values
public void newGame() {
start = false;
speed = 0;
finish = false;
endGame = false;
exBallx = 240;
exBally = 460;
bally = 460;
ballx = 250;
direction = 90;
barPos = 220;

for (int i = 0; i < brick.length; i++) {
brick[i].resetBounced();
}
repaint();
}

public void changeSpeed(double s) {
speed = s;
}

}
[/code]

Brick.java
[code]package pinpad;

public class Brick {
private boolean bounced = false;
private int x,y;

//initiate and saves the coordinates
public Brick (int xCord,int yCord) {
x = xCord;
y = yCord;
}

//returns true if the coordinates means a hit
public boolean hit(int ballX, int ballY) {

if ((!bounced) && ((ballX-x) > -15) && ((ballX-x-50) < -5) && ((ballY-y) < 5)
&& ((ballY-y) > 0)) {
bounced = true;
return true;
}
return false;
}

//return false if the brick should be drawn
public boolean bounced () {
return bounced;
}

//resets bounced
public void resetBounced() {
bounced = false;
}
}[/code]

Comments

  • : As I'm trying to learn to use graphics in java I've written the
    : beginning to a small game (one where u should bounce a ball and try
    : to hit all the bricks). So far so god but now I've encountered a
    : problem. I can't seem to stop the ball from flickering during play.
    : The weird part is that it moves smooth during movment of the "pad".
    : Anyone knows why this is so, 'cause I'm completly lost.
    :
    : Any thougts on the code are welcome, I'm here to learn :).
    :
    : The main class only creates a new instance of window.
    :
    : Window.java
    : [code]: package pinpad;
    :
    : import javax.swing.JFrame;
    : import java.awt.*;
    : import java.awt.event.*;
    :
    :
    : public class Window extends JFrame implements KeyListener{
    : Gamepanel pane;
    :
    : public Window(){
    : super ("Pinpad");
    : setBounds(400,200,510,525);
    : setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    :
    : pane = new Gamepanel();
    : addKeyListener(this);
    :
    : setContentPane(pane);
    : setVisible(true);
    :
    : while(true) {
    : if (!pane.pause && !pane.finish && !pane.endGame) {
    : try {
    : Thread.sleep(2);
    : }
    : catch (InterruptedException ie) {
    : }
    : pane.move();
    : //repaints all if it's a hit otherwise only the ball
    : if (pane.hit())
    : pane.repaint();
    : else {
    : pane.repaintBall();
    : }
    : }
    : else {
    : repaint();
    : }
    : }
    : }
    :
    : @Override
    : public void keyTyped(KeyEvent e) {
    : }
    :
    : @Override
    : public void keyPressed(KeyEvent e) {
    : int key = e.getKeyCode();
    :
    : switch (key) {
    : //left Arrow
    : case 37:
    : pane.moveBarL = true;
    : break;
    : //rigth arrow
    : case 39:
    : pane.moveBarR = true;
    : break;
    : //Enter
    : case 10:
    : pane.start = true;
    : pane.changeSpeed(0.8);
    : pane.repaint();
    : break;
    : //Pause || p
    : case 80:
    : case 19:
    : pane.pause = !pane.pause;
    : pane.repaint();
    : break;
    : //F2
    : case 113:
    : pane.newGame();
    : }
    : }
    :
    : @Override
    : public void keyReleased(KeyEvent e) {
    : int key = e.getKeyCode();
    : //left Arrow
    : if (key == 37) {
    : pane.moveBarL = false;
    : }
    : //right arrow
    : else if (key == 39) {
    : pane.moveBarR = false;
    : }
    : }
    : }
    : [/code]:
    :
    : Gamepanel.java
    : [code]: package pinpad;
    :
    : import javax.swing.JPanel;
    : import java.awt.geom.*;
    : import java.awt.*;
    :
    : public class Gamepanel extends JPanel {
    : private int ballx = 250;
    : private int bally = 460;
    : private int direction = 90;
    : private double speed = 0;
    : private double exBallx = 250, exBally = 460;
    : private int barPos = 220;
    : public boolean moveBarR = false, moveBarL = false;
    : public boolean endGame = false, start = false, pause = false, finish = false;
    :
    : //Creates a set of coordinates for the bricks
    : int[] xCord = {0, 60, 120, 180, 240, 300, 360, 420,
    : 0, 120, 240, 360, 460};
    : int[] yCord = {0, 0, 0, 0, 0, 0, 0, 0,
    : 30, 30, 30, 30, 30};
    : Brick[] brick = new Brick[xCord.length];
    : int count = brick.length;
    :
    : public Gamepanel() {
    : //creates the bricks
    : for (int i = 0; i < brick.length; i++) {
    : brick[i] = new Brick(xCord[i], yCord[i]);
    : }
    : }
    :
    : @Override
    : public void paintComponent(Graphics comp) {
    : Graphics2D comp2D = (Graphics2D) comp;
    : Font f = new Font ("Monospaced", Font.ITALIC, 30);
    : FontMetrics fm = getFontMetrics(f);
    : comp2D.setFont(f);
    :
    : //draw background
    : comp2D.setColor(Color.WHITE);
    : comp2D.fillRect(0,0,500,500);
    : //draw ball
    : comp2D.setColor(Color.MAGENTA);
    : comp2D.fillOval(ballx,bally,20,20);
    : //draw pad
    : comp2D.setColor(Color.BLACK);
    : comp2D.fill3DRect(barPos, 480, 80, 20, true);
    :
    : //draw bricks
    : comp2D.setColor(Color.BLUE);
    : for (int i = 0; i < xCord.length; i++) {
    : if (!brick[i].bounced()) {
    : comp2D.fillRect(xCord[i], yCord[i], 50, 10);
    : }
    : }
    :
    : if (!start) {
    : String startString = "Press ENTER to start!!";
    : comp2D.drawString(startString, ((500-fm.stringWidth(startString))/2), 250);
    : }
    :
    : else if (endGame) {
    : String over = "GAME OVER!!!";
    : comp2D.drawString(over, ((500-fm.stringWidth(over))/2), 250);
    : }
    :
    : else if (pause) {
    : String pauseString = "PAUSED!!";
    : comp2D.drawString(pauseString, ((500-fm.stringWidth(pauseString))/2), 250);
    : }
    :
    : else if (finish) {
    : comp2D.drawString("Congratulations,", ((500-fm.stringWidth("Congratulations,"))/2), 250);
    : comp2D.drawString("You made it!!!", ((500-fm.stringWidth("you made it!!!"))/2), 250 + fm.getHeight());
    : }
    : }
    :
    : public void move() {
    : if(!start) {
    : exBallx = barPos + 30;
    : }
    : if (!endGame) {
    : //bounce if hitting the sides
    : if ((ballx < 0) || (ballx > 480)) {
    : direction = bounceVertikal(direction);
    : exBallx = ballx < 0 ? 0:480;
    : }
    : //bounce if hitting the top
    : if (bally < 0) {
    : direction = bounceHorizontal(direction);
    : exBally = 0;
    : }
    : //bounce on pad if it's a hit
    : else if ((bally > 460) && (ballx < (barPos + 70)) && (ballx > barPos-5) && (bally < 465)) {
    : direction = bouncePad(direction);
    : exBally = 460;
    : }
    : // end game if ball leaves picture
    : else if (bally > 500) {
    : endGame = true;
    : }
    :
    : //calculate new ballposition
    : exBallx = exBallx + (speed * Math.cos(Math.toRadians(direction)));
    : exBally = exBally - (speed * Math.sin(Math.toRadians(direction)));
    :
    : ballx = (int) exBallx;
    : bally = (int) exBally;
    :
    :
    : //move bar if key is pressed
    : if ((moveBarR) && (barPos < 460)) {
    : barPos = barPos + 1;
    : repaint(barPos -1, 480, 82, 20);
    : }
    : if ((moveBarL) && (barPos > -30)) {
    : barPos = barPos - 1;
    : repaint(barPos -1, 480, 82, 20);
    : }
    : }
    : }
    :
    : public int bounceHorizontal (int dir) {
    : dir = 360 - dir;
    : return dir;
    : }
    :
    : public int bounceVertikal (int dir) {
    : dir = 180 - dir;
    : if (dir < 0) {
    : dir = 360 + dir;
    : }
    : return dir;
    : }
    :
    : //checks if the ball hits any bricks
    : public boolean hit() {
    : if(bally < 200) {
    : for(int i = 0; i < brick.length; i++) {
    : if(brick[i].hit(ballx, bally)) {
    : direction = bounceHorizontal(direction);
    : count--;
    : if (count == 0)
    : finish = true;
    : return true;
    : }
    : }
    : }
    : return false;
    : }
    :
    : private int bouncePad (int dir) {
    : int x = bounceHorizontal(dir);
    : x = x + 40 - (ballx - barPos +10);
    : if (x < 0) {
    : x = 360 + x;
    : }
    : return x;
    : }
    :
    : //repaints the area where the ball is
    : public void repaintBall() {
    : repaint(ballx - 20, bally - 20, 60, 60);
    : }
    :
    : //Resets values
    : public void newGame() {
    : start = false;
    : speed = 0;
    : finish = false;
    : endGame = false;
    : exBallx = 240;
    : exBally = 460;
    : bally = 460;
    : ballx = 250;
    : direction = 90;
    : barPos = 220;
    :
    : for (int i = 0; i < brick.length; i++) {
    : brick[i].resetBounced();
    : }
    : repaint();
    : }
    :
    : public void changeSpeed(double s) {
    : speed = s;
    : }
    :
    : }
    : [/code]:
    :
    : Brick.java
    : [code]: package pinpad;
    :
    : public class Brick {
    : private boolean bounced = false;
    : private int x,y;
    :
    : //initiate and saves the coordinates
    : public Brick (int xCord,int yCord) {
    : x = xCord;
    : y = yCord;
    : }
    :
    : //returns true if the coordinates means a hit
    : public boolean hit(int ballX, int ballY) {
    :
    : if ((!bounced) && ((ballX-x) > -15) && ((ballX-x-50) < -5) && ((ballY-y) < 5)
    : && ((ballY-y) > 0)) {
    : bounced = true;
    : return true;
    : }
    : return false;
    : }
    :
    : //return false if the brick should be drawn
    : public boolean bounced () {
    : return bounced;
    : }
    :
    : //resets bounced
    : public void resetBounced() {
    : bounced = false;
    : }
    : }[/code]:
    :
    The flickering is due to the fact that every call to update() first clears the component, and then paints the foreground.
    Solution: Subclass ComponentUI and override its update(). Then install your newly created ComponentUI class as the renderer for the GamePanel class.
  • : The flickering is due to the fact that every call to update() first
    : clears the component, and then paints the foreground.
    : Solution: Subclass ComponentUI and override its update(). Then
    : install your newly created ComponentUI class as the renderer for the
    : GamePanel class.

    Thanks for the quick reply, I've now written a subclass for ComponentUI but how do I install it as a renderer for a JPanel?

    I also almost decided to rewrite the whole program to get better structure using multithreading. This is the new plan.

    Using a thread for the ball and subclassing it from Ellipse2d. In that way the calculations for moving the ball is in a own thread and tha ball should move whit a more even speed.

    Doing tha same thing for the pad but there subclassing Rectangel2d.

    Also I'm thinking of using a seperate thread for controlling if the ball hits something. But I still can't figure out a nice way to do these checks. Any Ideas??

    Does this new plan sounds lika a improvment or I'm a just bullshiting myself?
  • : : The flickering is due to the fact that every call to update() first
    : : clears the component, and then paints the foreground.
    : : Solution: Subclass ComponentUI and override its update(). Then
    : : install your newly created ComponentUI class as the renderer for the
    : : GamePanel class.
    :
    : Thanks for the quick reply, I've now written a subclass for
    : ComponentUI but how do I install it as a renderer for a JPanel?
    :
    : I also almost decided to rewrite the whole program to get better
    : structure using multithreading. This is the new plan.
    :
    : Using a thread for the ball and subclassing it from Ellipse2d. In
    : that way the calculations for moving the ball is in a own thread and
    : tha ball should move whit a more even speed.
    :
    : Doing tha same thing for the pad but there subclassing Rectangel2d.
    :
    : Also I'm thinking of using a seperate thread for controlling if the
    : ball hits something. But I still can't figure out a nice way to do
    : these checks. Any Ideas??
    :
    : Does this new plan sounds lika a improvment or I'm a just
    : bullshiting myself?
    :
    You can specify the renderer with setUI().
    Letting the ball have its own thread can help to get a bit more control over the speed of the game. This makes the speed of the ball and the speed of the rendering independent. A third thread to control if the ball hits something is not necessary. Wether or not the ball hits something should be part of its movement, which is already in the ball-thread.
  • : Letting the ball have its own thread can help to get a bit more
    : control over the speed of the game. This makes the speed of the ball
    : and the speed of the rendering independent. A third thread to
    : control if the ball hits something is not necessary. Wether or not
    : the ball hits something should be part of its movement, which is
    : already in the ball-thread.

    Sounds like a good idea, but I still need a better way of detecting a hit my way seem way to ineffective. Any ideas someone??

    I will return when the code is rewritten.
  • Hi,

    From my perspective, you already has a nice/good implementation in your fist example. For flickering, I believe it behaves exactly like game development has been since the DOS. You use "Double Buffering"; that works perfect for me.

    http://javaboutique.internet.com/tutorials/Java_Game_Programming/BildschirmflackernEng.html

    The update() function already run in another thread. When you call repaint() it doesn't block. Only notifies about an update. To synchronize the update() function is not easy some times because it's running in other thread.

    [red]Good luck![/red]
    [blue]Hackman[/blue]
  • : Hi,
    :
    : From my perspective, you already has a nice/good implementation in
    : your fist example. For flickering, I believe it behaves exactly like
    : game development has been since the DOS. You use "Double Buffering";
    : that works perfect for me.
    :
    : http://javaboutique.internet.com/tutorials/Java_Game_Programming/Bild
    : schirmflackernEng.html
    :
    : The update() function already run in another thread. When you call
    : repaint() it doesn't block. Only notifies about an update. To
    : synchronize the update() function is not easy some times because
    : it's running in other thread.
    :
    : [red]Good luck![/red]
    : [blue]Hackman[/blue]

    The flickering isn't a thread problem. update() runs in the same thread as paint(). When a JComponent gets repainted it executes the following code:
    [code]
    - Draw a rectangle over the visible area with the background color
    - Draw the foreground using paintComponent()
    - Draw any child components
    [/code]
    The first step causes the flickering, because it totally clears the visible component area.
  • Hi,

    Yeah, the flickering is not a thread problem, but you addressed it like a problem with responsiveness, and I address it like part of the problem, like you did. Maybe I was not clear, and it is my fault! And I have to be annoying in this case, what I meant was... I quote myself:

    [b]The update() function already run in another thread.[/b]
    [italic]It is true. You made it run in another thread already (or told to do so).[/italic]
    [b]When you call repaint() it doesn't block. Only notifies about an update.[/b]
    [italic]It is true. That doesn't wait until repaint() ends. It will be done after.[/italic]
    [b]To synchronize the update() function is not easy some times because it's running in other thread.[/b]
    [italic]It is true. When you have another thread running for painting.[/italic]

    I was trying to make a statement of what is part of the problem.
    This is all what I did for loosing the flickering thing... and it erases the whole screen, which is needed in a normally animated game. Without any threading and without loosing any responsiveness (only the normally overwhelming processor speed; which indeed happens with multiple threads also)

    [code] @Override
    public void update(Graphics g) {
    if (bufferImage == null) {
    bufferImage = createImage(getWidth(), getHeight());
    bufferGraphics = bufferImage.getGraphics();
    }
    paint(bufferGraphics);
    g.drawImage(bufferImage, 0, 0, null);
    }

    @Override
    public void paint(Graphics g) {
    g.drawImage(background, 0, 0, null);
    g.drawImage(starship01, x, y, null);
    g.etc.... and its a looong etc....
    }
    [/code]
    And you can test the repaint() note with this:
    [code] @Override
    public void paint(Graphics g) {
    super.paint(g);
    System.out.println("On Paint!");
    }

    System.out.println("Calling before painting");
    this.repaint();
    System.out.println("Calling after painting");
    [/code]
    Best Regards and Respect,

    ps:
    Or I could be wrong...
    I didn't invent this, I read it in 3 tutorials about Game Development in Java, and it's the same in all of them; it works for me.

    [red]Good luck![/red]
    [blue]Hackman[/blue]
  • : Hi,
    :
    : Yeah, the flickering is not a thread problem, but you addressed it
    : like a problem with responsiveness, and I address it like part of
    : the problem, like you did. Maybe I was not clear, and it is my
    : fault! And I have to be annoying in this case, what I meant was... I
    : quote myself:
    :
    : [b]The update() function already run in another thread.[/b]
    : [italic]It is true. You made it run in another thread already (or
    : told to do so).[/italic]
    : [b]When you call repaint() it doesn't block. Only notifies about an
    : update.[/b]
    : [italic]It is true. That doesn't wait until repaint() ends. It will
    : be done after.[/italic]
    : [b]To synchronize the update() function is not easy some times
    : because it's running in other thread.[/b]
    : [italic]It is true. When you have another thread running for
    : painting.[/italic]
    :
    : I was trying to make a statement of what is part of the problem.
    : This is all what I did for loosing the flickering thing... and it
    : erases the whole screen, which is needed in a normally animated
    : game. Without any threading and without loosing any responsiveness
    : (only the normally overwhelming processor speed; which indeed
    : happens with multiple threads also)
    :
    : [code]: @Override
    : public void update(Graphics g) {
    : if (bufferImage == null) {
    : bufferImage = createImage(getWidth(), getHeight());
    : bufferGraphics = bufferImage.getGraphics();
    : }
    : paint(bufferGraphics);
    : g.drawImage(bufferImage, 0, 0, null);
    : }
    :
    : @Override
    : public void paint(Graphics g) {
    : g.drawImage(background, 0, 0, null);
    : g.drawImage(starship01, x, y, null);
    : g.etc.... and its a looong etc....
    : }
    : [/code]:
    : And you can test the repaint() note with this:
    : [code]: @Override
    : public void paint(Graphics g) {
    : super.paint(g);
    : System.out.println("On Paint!");
    : }
    :
    : System.out.println("Calling before painting");
    : this.repaint();
    : System.out.println("Calling after painting");
    : [/code]:
    : Best Regards and Respect,
    :
    : ps:
    : Or I could be wrong...
    : I didn't invent this, I read it in 3 tutorials about Game
    : Development in Java, and it's the same in all of them; it works for
    : me.
    :
    : [red]Good luck![/red]
    : [blue]Hackman[/blue]
    I've never indicated that update() runs in another thread. I said that the update() is declared in the ComponentUI, which is a helper class to render swing components. This allows swing components to be skinnable, but it still runs in the event-dispatching thread.
    I've encountered this problem myself also, and solved it by subclassing the JComponent and overriding update() to only call paint().
  • I think we are discussing something irrelevant to the problem.
    I didn't [italic]indicated[/italic] that you [italic]indicated[/italic] that update() runs in another thread.
    Like you know, we can post for years making our own assumptions of what each other wrote.

    But never mind ... your right ...
    [italic]I hope it will be useful to sheazar.[/italic]

    Regards,

    [red]Good luck![/red]
    [blue]Hackman[/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories