Results 1 to 11 of 11

Thread: Cannot resolve symbol class MouseHandler error message....

Threaded View

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Resolved Cannot resolve symbol class MouseHandler error message....

    I am getting that error message when I compile my java program that I am writing. It is at Line 23. I am trying to put this code, in the first block there,
    into an anonymous class in the second block of code. Can I put an anonymous class there or not?

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
     * Title:        Assign 1
     * @author       Matthew Davis
     * 				 SECC
     */
    
    
    public class DrawSquare extends JPanel{
    
      Point location;
      Point mouseLocation;
      //constructor 
      
      public DrawSquare()
      {
    
        this.setPreferredSize(new Dimension(200,150));
        this.addMouseListener(
        	new MouseHandler(){//cannot resolve symbol class MouseHandler error
        		  public void mouseClicked(MouseEvent e)
        			{//e.getPoint MouseClicked method redraws image or shape.
       				mouseLocation=e.getPoint();
    
    				if (location.x<=mouseLocation.x && location.y<=mouseLocation.y)
    					{
    						location.x = (int)(Math.random()* 100);
    						location.y = (int)(Math.random()* 100);
    						repaint();
    					}//end if statement
    		
       				}//end mouseclicked
        		
        		
        		
        		
        		
        			});//end mousehandler
        location = new Point(50,50);
        
      }
      
      //use the graphics context to draw
      public void paintComponent(Graphics g)
      {
      	int x=50;
      	int y=50;
        super.paintComponent(g);
        System.out.println("The red square should be moving ...");
        g.setColor(Color.red);
    	g.drawRect(location.x, location.y, x, y);
      }
        
     /* class MouseHandler extends MouseAdapter
      	{//use MouseAdapter Class
    
        	
        	    	public void mouseClicked(MouseEvent e)
        	{//e.getPoint MouseClicked method redraws image or shape.
       		mouseLocation=e.getPoint();
    
    		if (location.x<=mouseLocation.x && location.y<=mouseLocation.y)
    			{
    				location.x = (int)(Math.random()* 100);
    				location.y = (int)(Math.random()* 100);
    				repaint();
    			}
    		
       		}
        	
        	
        	
        	
        	
        	
       }*/
    }
    I added the file to a ZIP if you would rather look at it there.

    Oh, just a basic description of what the program does(it has another file with it in the zip file i attached). It draws a shape (a square in this case) and invite the user to click on it. When the user clicks on the shape, move it to a new random location.



    <Moderator added green checkmark in the first thread>
    Last edited by NoteMe; Feb 17th, 2005 at 07:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width