Ok well i want to make this simple game, and basically all it does is count how many times you clicked, and i made it, but its running too slow. The problem is that its not counting all the clicks, it might have something to do with the way i coded it but idk…
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
public class Countdown extends Applet implements Runnable, MouseListener
{
Thread th;
int i = 200;
int count = -2;
public void init()
{
setSize(300,300);
setBackground(Color.black);
addMouseListener(this);
}
public void paint(Graphics g)
{
g.setColor(Color.gray);
g.drawString("SECONDS LEFT "+i,30,30);
if(i == 0)
{
g.setColor(Color.blue);
g.drawString("YOU CLICKED "+count+" TIMES!",10,200);
}
if(i <= 0)
{
g.setColor(Color.red);
g.drawRect(10,5,150,150);
stop();
}
}
public void run()
{
while(th == Thread.currentThread())
{
i--;
repaint();
try{Thread.sleep(50); }
catch(InterruptedException e){}
}
}
public void start()
{
if(th == null) th = new Thread(this);
th.start();
}
public void stop()
{
if(th != null) th = null;
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
count++;
}
ps. im not new to java its just i dont know why its not getting my clicks fast enought and i want to know what i can do…
