Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

difficulty level slider bar

807600Jun 14 2007 — edited Jun 22 2007
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.
public class Creature implements ActionListener{

	private GamePanel gamePanel;
	private int x = 250;
	private int y = 250;
	private ImageIcon image = new ImageIcon("creature.gif");
	private boolean 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();
	}
	
	public void draw(Graphics g){
		if(visible){
		image.paintIcon(gamePanel, g, x, y);
		}
	}
	public void 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();
	}
	public boolean isClicked(int a, int b)
	{
		if(a > x + 80) return false;
		if(a < x) return false;
		if(b > y + 67) return false;
		if(b < y) return false;
		return true;
	}
}
Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2007
Added on Jun 14 2007
4 comments
120 views