Napravio sam aplet koji simulira bacanje kockica kada se klikne na aplet. Hoću da izbacuje poruku kada se pojave iste kockice tj. kada je x = y, i da pokaže koliko puta je kliknuto dok se to nije desilo. Ne znam kako da izbrojim klikove. Unapred hvala. Evo koda:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Aplet extends Applet implements MouseListener
{
public void paint(Graphics g){
addMouseListener(this);
g.setColor(Color.white);
g.fillRect(100,100,40,40);
g.setColor(Color.black);
g.drawRect(100,100,39,39);
g.setColor(Color.white);
g.fillRect(200,100,40,40);
g.setColor(Color.black);
g.drawRect(200,100,39,39);
int x,y;
x = (int) (Math.random() * 6 + 1);
y = (int) (Math.random() * 6 + 1);
if (x == 1) {
g.fillOval(115, 115, 10, 10);
}
if (x == 2) {
g.fillOval(105, 105, 10, 10);
g.fillOval(125, 125, 10, 10);
}
if (x == 3) {
g.fillOval(115, 115, 10, 10);
g.fillOval(105, 105, 10, 10);
g.fillOval(125, 125, 10, 10);
}
if (x == 4) {
g.fillOval(105, 105, 10, 10);
g.fillOval(105, 125, 10, 10);
g.fillOval(125, 105, 10, 10);
g.fillOval(125, 125, 10, 10);
}
if (x == 5) {
g.fillOval(105, 105, 10, 10);
g.fillOval(105, 125, 10, 10);
g.fillOval(125, 105, 10, 10);
g.fillOval(125, 125, 10, 10);
g.fillOval(115, 115, 10, 10);
}
if (x == 6) {
g.fillOval(105, 105, 10, 10);
g.fillOval(105, 125, 10, 10);
g.fillOval(125, 105, 10, 10);
g.fillOval(125, 125, 10, 10);
g.fillOval(105, 115, 10, 10);
g.fillOval(125, 115, 10, 10);
}
if (y == 1) {
g.fillOval(215, 115, 10, 10);
}
if (y == 2) {
g.fillOval(205, 105, 10, 10);
g.fillOval(225, 125, 10, 10);
}
if (y == 3) {
g.fillOval(215, 115, 10, 10);
g.fillOval(205, 105, 10, 10);
g.fillOval(225, 125, 10, 10);
}
if (y == 4) {
g.fillOval(205, 105, 10, 10);
g.fillOval(205, 125, 10, 10);
g.fillOval(225, 105, 10, 10);
g.fillOval(225, 125, 10, 10);
}
if (y == 5) {
g.fillOval(205, 105, 10, 10);
g.fillOval(205, 125, 10, 10);
g.fillOval(225, 105, 10, 10);
g.fillOval(225, 125, 10, 10);
g.fillOval(215, 115, 10, 10);
}
if (y == 6) {
g.fillOval(205, 105, 10, 10);
g.fillOval(205, 125, 10, 10);
g.fillOval(225, 105, 10, 10);
g.fillOval(225, 125, 10, 10);
g.fillOval(205, 115, 10, 10);
g.fillOval(225, 115, 10, 10);
}
}
public void mousePressed(MouseEvent e)
{
repaint();
}
public void mouseReleased(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
}