Mouse listener not working


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Mouse listener not working

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    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;
        }

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    well what's it doing and what's it suppose to do instead?

  3. #3
    Join Date
    Jun 2006
    Posts
    2
    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

  1. Disable keyboard, keep mouse working
    By Andrew in forum VB Classic
    Replies: 7
    Last Post: 06-25-2009, 10:55 PM
  2. Replies: 10
    Last Post: 09-26-2005, 08:43 PM
  3. button listener not working
    By DrunkinP in forum Java
    Replies: 0
    Last Post: 03-31-2005, 09:36 AM
  4. Capturing Mouse Movements outside of screen resolution
    By Chris Eastwood in forum VB Classic
    Replies: 4
    Last Post: 03-28-2002, 01:26 PM
  5. Disable keyboard, keep mouse working
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center