jQuery in Action, 2nd edition
The moose likes Swing / AWT / SWT and the fly likes MouseListener Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "MouseListener" Watch "MouseListener" New topic
Author

MouseListener

Jay Kamdar
Greenhorn

Joined: Sep 02, 2005
Posts: 22
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

Joined: Jun 09, 2003
Posts: 4632
you implement MouseListener, but not added it to anything
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MouseListener
 
Similar Threads
JLabel setIcon() not working...
The x,y coordinates are not working
Jtable mouse header cursor
Prevent selection of certain JTable cells
cannot find symbol