• Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseListener  RSS feed

 
Jay Kamdar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making minesweeper and the buttons for it are not working correctly because its mouseclicked event or any mouse events are not working.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class BoxButton extends JButton implements MouseListener
{
private int row;
private int col;
private Environment env;

public BoxButton()
{
throw new IllegalArgumentException(�Needs to be in an array with row and height� ;
}

public BoxButton(int row, int col, Environment env)
{
this.row = row;
this.col = col;
this.env = env;
setEnabled(true);

}


public void mouseClicked(MouseEvent event)
{
Box box = (Box) env.objectAt(new Location(row,col));
if(event.getButton() == event.BUTTON2)
{
box.setFlag(!box.hasFlag());

}

if(event.getButton() == event.BUTTON1)
{
this.setEnabled(false);
System.out.println(�Mouse Listener works� ;
setSelected(false);
}
if(box.hasFlag())
{
this.setIcon(new ImageIcon(�flag.jpg� );
}
else
{
this.setIcon(null);
}
this.repaint();
}

public void mouseReleased(MouseEvent event)
{
if(event.getButton() == event.BUTTON1)
{
this.setEnabled(false);
this.setBorderPainted(false);
this.setVisible(false);
}
}

public void mousePressed(MouseEvent event)
{

}


public void mouseEntered(MouseEvent event)
{

}


public void mouseExited(MouseEvent event)
{

}
}
if you can�t figure it out from that, i can send you the rest of the files.

http://www.megaupload.com/?d=JK1WRXML

Thanks in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you implement MouseListener, but not added it to anything
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!