Je conçois un programme qui, à chaque fois que vous cliquez sur une forme, change de couleur de façon ordonnée. Si vous regardez mon code ci-dessous, je ne sais pas quoi mettre dans ma déclaration if. Je veux retourner une valeur (valeur int si possible) à ma méthode principale afin qu'elle sache passer à la question suivante. Je prendrai des suggestions, merciLorsque l'utilisateur clique sur la bonne réponse, il passe à la question suivante
public void mousePressed(MouseEvent e) { //when user clicks a button it goes in here
k++; //increases k, every time it runs
if (k == 4) //if k equal 4, it will go back to 0. Repeats the cycle
k = 0;
Point p = e.getPoint(); //get the postion of the click
Polygon[] polys = polygonPanel.polygons;
for (j = 0; j < polys.length; j++) { //check which polygon is picked
if (polys[j].contains(p)) { //if the user clicks a shape it will go in this loop to change color
polygonPanel.colors[j] = getColor(k); //bring the four colors from the method
polygonPanel.repaint(); //change the color of the polygon when clicked
/*if (rightAnswer) {
correctAnswer++;
}*/
}
}
}
Vous allez vouloir vous familiariser avec [Observer Pattern] (http://www.oodesign.com/observer-pattern.html) – MadProgrammer