difficulty level slider bar
Hello I need to implement a slider bar to my game to be able to change its difficulty level. Right now my game is about a creature appearing and disapearing in a panel every second randomly. If I'm able to click on the creature when it appear I gain a point. I need to slider so the user can change the speed of the creature appearing and disapearing.
This is what i have.
publicclass Creatureimplements ActionListener{
private GamePanel gamePanel;
privateint x = 250;
privateint y = 250;
private ImageIcon image =new ImageIcon("creature.gif");
privateboolean visible =true;
private Random random =new Random();
private Timer timer;//= new Timer(1000, this);
//private int numberOfTimeCreatureIsCaught = 0;
public Creature(GamePanel gamePanel){
this.gamePanel = gamePanel;
timer =new Timer(1000,this);
timer.start();
}
publicvoid draw(Graphics g){
if(visible){
image.paintIcon(gamePanel, g, x, y);
}
}
publicvoid actionPerformed(ActionEvent e){
int delay = random.nextInt(1000) + 1;
timer.setDelay(delay);
if(visible)
{
visible =false;
}
else{
visible =true;
x = random.nextInt(500 - 80);
y = random.nextInt(500 - 67);
}
gamePanel.repaint();
}
publicboolean isClicked(int a,int b)
{
if(a > x + 80)returnfalse;
if(a < x)returnfalse;
if(b > y + 67)returnfalse;
if(b < y)returnfalse;
returntrue;
}
}
Thank you

