A friendly place for programming greenhorns!
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
Author
MouseListener
Jay Kamdar
Greenhorn
Joined: Sep 02, 2005
Posts: 22
posted
May 20, 2006 12:46:00
0
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
posted
May 20, 2006 14:53:00
0
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
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter