bad flicker on applet drawing

iv never drawn images using java befor and seam to be getting quite bad flicker when images r changing like flashing / been updated

i have main applet class that has a thread that calls these methods

below is my code for drawing images

what am i doing wrong to cause this nasty flicker im guessing its auto redrawing the whole screen or some thing every time some image changing

it does not need to redraw the background images at all just the images on top that are changing

any idea what im doing wrong or better way to code this thanks

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.applet.*;

import java.io.*;

publicclass drawSlot{

private Applet parrentapp;

int id = 0;

intoffset = 93;

JLabel imageLabel;

ImageIcon ImageIcon;

JLabel imageLabel0;

ImageIcon ImageIcon3;

JLabel imageLabel3;

ImageIcon ImageIcon4;

JLabel imageLabel4;

ImageIcon ImageIcon0;

ImageIcon[][] ImageIcon1;

JLabel[][] imageLabel1;

ImageIcon[] ImageIcon2;

JLabel[] imageLabel2;

JLabel bank =new JLabel("000.00");

JLabel credit =new JLabel("00.00");

JLabel status =new JLabel("null");

InputStream is = getClass().getResourceAsStream("LCD-BOLD.TTF");

public drawSlot(Applet parrent,int maxSlots,int idx){

parrentapp = parrent;

id = idx;

ImageIcon1 =new ImageIcon[9][4];

imageLabel1 =new JLabel[9][4];

ImageIcon2 =new ImageIcon[2];

imageLabel2 =new JLabel[2];

Font font =null;

try{

font = Font.createFont(Font.TRUETYPE_FONT, is);

}catch (Exception e){

e.printStackTrace();

}

Font font0 = font.deriveFont(26.0f);

Font font1 = font.deriveFont(18.0f);

// slot overlay

ImageIcon4 =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/slotoverlay.png"));

imageLabel4 =new JLabel(ImageIcon4);

imageLabel4.setBounds(187*id, offset, 187, 288);

parrentapp.add(imageLabel4);

// bank display

bank.setBounds((187*id)+56, 5+offset ,100, 50);

bank.setFont(font0);

bank.setForeground(Color.red);

parrentapp.add(bank);

// credit display

credit.setBounds((187*id)+123, 31+offset ,100, 50);

credit.setFont(font1);

credit.setForeground(Color.red);

parrentapp.add(credit);

// status

status.setBounds((187*id)+8, 251+offset ,200, 50);

status.setFont(new Font("Courier ", Font.PLAIN, 12));

//status.setForeground(Color.black);

parrentapp.add(status);

// reel overlay

ImageIcon3 =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/overlay.png"));

imageLabel3 =new JLabel(ImageIcon3);

imageLabel3.setBounds((187*id)+9, 230, 125, 72);

parrentapp.add(imageLabel3);

// reel symbols - 3 reels, 3 symbols per reel, 4 images per symbol

// 2,5,8

// 1,4,7

// 0,3,6

for (int i=0; i<9; i++){

for (int j=0; j<4; j++){

ImageIcon1[i][j] =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/symbol"+j+".GIF"));

imageLabel1[i][j] =new JLabel(ImageIcon1[i][j]);

parrentapp.add(imageLabel1[i][j]);

imageLabel1[i][j].setVisible(false);

switch (i){

case 0: imageLabel1[i][j].setBounds((187*id)+9, 278, 36, 24);break;

case 1: imageLabel1[i][j].setBounds((187*id)+9, 254, 36, 24);break;

case 2: imageLabel1[i][j].setBounds((187*id)+9, 230, 36, 24);break;

case 3: imageLabel1[i][j].setBounds((187*id)+53, 278, 36, 24);break;

case 4: imageLabel1[i][j].setBounds((187*id)+53, 254, 36, 24);break;

case 5: imageLabel1[i][j].setBounds((187*id)+53, 230, 36, 24);break;

case 6: imageLabel1[i][j].setBounds((187*id)+97, 278, 36, 24);break;

case 7: imageLabel1[i][j].setBounds((187*id)+97, 254, 36, 24);break;

case 8: imageLabel1[i][j].setBounds((187*id)+97, 230, 36, 24);break;

}

}

}

// reel spin effect

ImageIcon0 =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/spin.GIF"));

imageLabel0 =new JLabel(ImageIcon0);

imageLabel0.setBounds((187*id)+9, 230, 125, 72);

parrentapp.add(imageLabel0);

imageLabel0.setVisible(false);

// awards

for (int i=0; i<2; i++){

ImageIcon2[i] =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/award"+i+".gif"));

imageLabel2[i] =new JLabel(ImageIcon2[i]);

imageLabel2[i].setBounds((187*id)+17, 170, 114, 46);

parrentapp.add(imageLabel2[i]);

imageLabel2[i].setVisible(false);

}

// background

ImageIcon =new ImageIcon(parrentapp.getImage(parrentapp.getCodeBase(),"Images/slot.gif"));

imageLabel =new JLabel(ImageIcon);

imageLabel.setBounds(187*id, offset, 187, 288);

parrentapp.add(imageLabel);

parrentapp.setLayout(null);

}

//***************************

//*displayReels*

//***************************

publicvoid displayReels(int set,int pos,int [][]band){

// 0=O

// 1=X

// 2=Bar

// 3=Pot

switch (set){

case 0:

imageLabel1[0][band[0][(pos + 1) % band[0].length]].setVisible(true);

imageLabel1[1][band[0][pos]].setVisible(true);

imageLabel1[2][band[0][(pos + (band[0].length - 1)) % band[0].length]].setVisible(true);

break;

case 1:

imageLabel1[3][band[1][(pos + 1) % band[1].length]].setVisible(true);

imageLabel1[4][band[1][pos]].setVisible(true);

imageLabel1[5][band[1][(pos + (band[1].length - 1)) % band[1].length]].setVisible(true);

break;

case 2:

imageLabel1[6][band[2][(pos + 1) % band[2].length]].setVisible(true);

imageLabel1[7][band[2][pos]].setVisible(true);

imageLabel1[8][band[2][(pos + (band[2].length - 1)) % band[2].length]].setVisible(true);

break;

}

}

//***************************

//*clearReels*

//***************************

publicvoid clearReels(){

for (int i=0; i<9; i++){

for (int j=0; j<4; j++)

imageLabel1[i][j].setVisible(false);

}

}

//***************************

//*displaySpin*

//***************************

publicvoid displaySpinEffect(boolean onOff){

imageLabel0.setVisible(onOff);

}

//***************************

//*flashAward*

//***************************

publicvoid flashAward(int award,int amount,int delay){

for (int i = 0; i < amount; i++){

imageLabel2[award].setVisible(true);

try{

Thread.sleep(delay);

}catch(InterruptedException e){

}

imageLabel2[award].setVisible(false);

try{

Thread.sleep(delay);

}catch(InterruptedException e){

}

}

}

//***************************

//*lightAward*

//***************************

publicvoid lightAward(int award,boolean bothOff){

for (int i = 0; i < 2; i++)

imageLabel2[i].setVisible(false);

if(!bothOff)

imageLabel2[award].setVisible(true);

}

//***************************

//*setOverlay*

//***************************

publicvoid setOverlay(boolean onoff){

imageLabel4.setVisible(!onoff);

}

//***************************

//*displayCredit*

//***************************

publicvoid displayCredit(double value){

credit.setText(String.valueOf(value) +"0");

}

//***************************

//*displayBank*

//***************************

publicvoid displayBank(double value){

bank.setText(String.valueOf(value) +"0");

}

//***************************

//*displayBankClear*

//***************************

publicvoid displayBankClear(){

bank.setText("");

}

//***************************

//*displayStatus*

//***************************

publicvoid displayStatus(String statusx){

status.setText(statusx);

}

}

maxslots is the amout of THREADS

idx is the current id of the thread been drawing

using this info i can draw the image on the correct part of the screen

[15911 byte] By [russdxa] at [2007-11-26 20:21:13]
# 1
http://www.auba18.dsl.pipex.com/slotgame.JPGwhat the result is
russdxa at 2007-7-10 0:45:45 > top of Java-index,Java Essentials,New To Java...
# 2
any ideas :(
russdxa at 2007-7-10 0:45:46 > top of Java-index,Java Essentials,New To Java...
# 3
got it sorted using some double buffering code in the main update function on the main applet class
russdxa at 2007-7-10 0:45:46 > top of Java-index,Java Essentials,New To Java...