Alright I was assigned to make a program very similar to mine sweeper. I developed a 10*10 grid, I have a random int for Column and a random int for row. The program tells you where you clicked although it seems a little off(example: you click in the square 5,2 it tells you 5,3.) My question is i've set a value for mouseX and mouseY to draw the you win but no matter where i click the string isn't working. Any general advice would help me on where to go from here. I've been messing around with it but some advice from more practiced hands is appreciated.
import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class bunnyfoofoostart extends Applet implements MouseListener, KeyListener { int mouseX; int mouseY; int secretcol=(int)(Math.random()*900+101); int secretrow=(int)(Math.random()*900+101); public void init() { addMouseListener(this); addKeyListener(this); } public void paint(Graphics g) { for(int col=1; col<=10; col++) { for(int row=1; row<=10; row++) { int x=col*50; int y= row*50; g.setColor(Color.green); g.fillRect(x,y,25,25); } } if (mouseX !=0|| mouseY !=0) g.drawString("You clicked at"+mouseX/50+","+ (1+mouseY/50),600,200); if (mouseX > (secretrow-30) && mouseX < (secretrow + 30)&& mouseY > (secretcol-30) && mouseY < (secretcol+30)) //win { g.setColor(Color.black); g.drawString("You Win",700,600); } if (mouseX>600 && mouseY<200) { System.out.println("Secret col is"+secretcol/100); System.out.println("Secret row is"+secretrow/100); } } public void mouseExited(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mousePressed(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseClicked(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); repaint(); } public void keyPressed(KeyEvent ke) { } public void keyReleased(KeyEvent ke) { } public void keyTyped(KeyEvent ke) { repaint(); } }