|
-
Jan 18th, 2005, 07:19 PM
#1
Thread Starter
Addicted Member
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.
-
Jan 18th, 2005, 07:32 PM
#2
Frenzied Member
Re: Cannot resolve symbol class MouseHandler error message....
Well, first off, mouse handler class is not public. I'm not sure it makes sense to do this first. You have a super class, a class that extends that super class and then your trying to create an instanse of that subclass that extends the super class in the super class. I think the best thing to do, would be keep it in one class. I wouldn't split up simple functionalilty like that.
-
Jan 18th, 2005, 08:28 PM
#3
Thread Starter
Addicted Member
Re: Cannot resolve symbol class MouseHandler error message....
 Originally Posted by System_Error
Well, first off, mouse handler class is not public. I'm not sure it makes sense to do this first. You have a super class, a class that extends that super class and then your trying to create an instanse of that subclass that extends the super class in the super class. I think the best thing to do, would be keep it in one class. I wouldn't split up simple functionalilty like that.
huh? what do u mean?
If you were talking about that part at the end, it is a commented out section of code I was working on.
-
Jan 18th, 2005, 08:44 PM
#4
Thread Starter
Addicted Member
Re: Cannot resolve symbol class MouseHandler error message....
OH, this is the code for the original, working version of DrawSquare.java
I realized that I didnt provide this so everyone could see it working.
This thing is, I have to use an anonymous class i nthe assignment that I am doing, so I can try alot of things. I just have to make it work.
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());
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();
}
}
}
}
-
Jan 18th, 2005, 09:06 PM
#5
Frenzied Member
Re: Cannot resolve symbol class MouseHandler error message....
 Originally Posted by ddmeightball
huh? what do u mean?
If you were talking about that part at the end, it is a commented out section of code I was working on.
It's hard too explain.!!
-
Jan 18th, 2005, 09:13 PM
#6
Frenzied Member
Re: Cannot resolve symbol class MouseHandler error message....
I'll help you with splitting it up into classes, but I'm getting ready for bed right now, and I have school tomorow. The thing is, you won't get much functionality out of a secon class in this case, but that's ok, I don't think your really looking for.
-
Jan 18th, 2005, 10:07 PM
#7
Thread Starter
Addicted Member
Re: Cannot resolve symbol class MouseHandler error message....
 Originally Posted by System_Error
I'll help you with splitting it up into classes, but I'm getting ready for bed right now, and I have school tomorow. The thing is, you won't get much functionality out of a secon class in this case, but that's ok, I don't think your really looking for.
yaeh, functionality and re-usability would be the way to go. I would just put the code back to the working version that I made, but the teacher wants it the certain way.
-
Jan 19th, 2005, 06:14 AM
#8
Frenzied Member
Re: Cannot resolve symbol class MouseHandler error message....
The way you have it, were you have a super class and an inner class is probably the best way to go, if your wanting to split it up into different classes. Is this not working?
-
Jan 19th, 2005, 08:42 AM
#9
Thread Starter
Addicted Member
Re: Cannot resolve symbol class MouseHandler error message....
 Originally Posted by System_Error
The way you have it, were you have a super class and an inner class is probably the best way to go, if your wanting to split it up into different classes. Is this not working?
Yeah, i get the error message cannot resolve symbol class MouseHandler. I dont know what that means. I have never got an error like that before so I am cluess as of where to go from here.
-
Jan 19th, 2005, 10:32 AM
#10
Thread Starter
Addicted Member
Re: Cannot resolve symbol class MouseHandler error message....
I figured out the MouseHandler error. That was the name of the class that I was calling to decide whether or not the square was clicked. I changed it to MouseAdapter and it worked just fine now. Thanks everyone for your help.
-
Jan 19th, 2005, 03:27 PM
#11
Frenzied Member
Re: Cannot resolve symbol class MouseHandler error message....
your welcome, and glad you got it fixed.
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
|
Click Here to Expand Forum to Full Width
|