-
Mouse listener not working
Hi all,
Having a little trouble with getting this mouse listener to work, and I am ripping my hair out cause I can't see what in the world the problem is, any help would be appreciated!
Code:
public class MainWindow extends JFrame implements MouseListener
{
private Canvas renderCanvas;
/** Creates a new instance of Main */
public MainWindow()
{
super( "Game" );
// Exit the program when we close the window for god's sake!
setDefaultCloseOperation( EXIT_ON_CLOSE );
// We don't want to repaint when the OS says we need to
setIgnoreRepaint( true );
addMouseListener( this );
//addMouseMotionListener(myListener);
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
// Setup the Canvas
renderCanvas = new Canvas()
{
public Dimension getPreferredSize()
{
return new Dimension( 1024, 768 );
}
};
add( "Center", renderCanvas );
pack();
// Put the window in the center of the screen
Point cp = ge.getCenterPoint();
cp.translate( -getWidth()/2, -getHeight()/2 );
setLocation( cp.x, cp.y );
setResizable( false );
setVisible( true );
renderCanvas.createBufferStrategy( 2 );
}
public BufferStrategy getBufferStrategy()
{
return (renderCanvas == null) ? super.getBufferStrategy()
: renderCanvas.getBufferStrategy();
}
public Dimension getDimensions()
{
return (renderCanvas == null) ? super.getSize()
: renderCanvas.getSize();
}
public void mouseClicked(MouseEvent event)
{
int test = 0;
}
public void mouseEntered(MouseEvent event)
{
int test = 0;
}
public void mouseExited(MouseEvent event)
{
}
public void mousePressed(MouseEvent event)
{
}
public void mouseReleased(MouseEvent event)
{
int test = 0;
}
-
well what's it doing and what's it suppose to do instead?
-
Figured it out, when using a Canvas, you cannot just say addMouseListener( this ), you have to do canvasObject.addMouseListener( this ). So there ya have it.
Similar Threads
-
By Andrew in forum VB Classic
Replies: 7
Last Post: 06-25-2009, 10:55 PM
-
Replies: 10
Last Post: 09-26-2005, 08:43 PM
-
By DrunkinP in forum Java
Replies: 0
Last Post: 03-31-2005, 09:36 AM
-
By Chris Eastwood in forum VB Classic
Replies: 4
Last Post: 03-28-2002, 01:26 PM
-
By Andrew in forum VB Classic
Replies: 0
Last Post: 04-28-2000, 10:33 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|