import java.awt.*; import java.awt.event.*; import javax.swing.*; class Spelleke extends JFrame { public Spelleke() { Container c = getContentPane(); c.setLayout(new GridLayout(3, 3)); Shared s = new Shared(); for (int i=0; i < 9; i++) { CoolLabel l = new CoolLabel(s); Thread t = new Thread(l); t.start(); c.add(l); } setSize(200, 200); setVisible(true); } public static void main(String[] args) { Spelleke app = new Spelleke(); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class CoolLabel extends JLabel implements Runnable, MouseListener { private Shared s; private int count = 0; public CoolLabel(Shared s) { this.s = s; addMouseListener(this); } public void run() { try { while(s.gameBusy) { if (count == 10) { s.gameBusy = false; } else { setText("" + count); count++; Thread.sleep(1000); } } } catch(Exception e){} } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseClicked(MouseEvent e) { if (s.gameBusy) { count--; setText("" + count); } } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} } class Shared { public boolean gameBusy = true; }