This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem in drawing a rectangle .....   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in drawing a rectangle .....   " Watch "Problem in drawing a rectangle .....   " New topic
Author

Problem in drawing a rectangle .....

sumukha kris
Greenhorn

Joined: Nov 02, 2007
Posts: 18
Hello,

I'm doing a project in java using swings ,im able to create a panel and frame but i have a problem in event handling.I have added the MouseMotionListener but it's giving some error .Here i want to draw a rectangle when the user clicks and drags the mouse button and releases a rectangle has to be drawn.can somebody help me to debug the error ASAP.

My code goes like this:


Errors i'm getting are
Multiple markers at this line
- MyListener cannot be resolved to a type
- Watchpoint:MyPanel [access and modification] - myListener
- MyListener cannot be resolved to a type

Multiple markers at this line
- Syntax error on token ")", { expected after this token
- myListener cannot be resolved to a type
- Syntax error on token "myListener", VariableDeclaratorId expected after this token


These are the errors i'm getting at line no 38 and 39 which i have written in bold letters.

Can anybody tell me what should i do?

Thanks in anticipation,

--------------------------------------------------------------------------------

Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The problem is that lines 38-40 should be inside a method (probably the constructor) but aren't - they're just inside the class.

You could leave the declaration/initialization on line 38 if you wanted to make myListener an attribute of the MyPanel class. But lines 39 and 40 definitely have to be inside a method - and line 39 shouldn't start with "void" - it's a method call, not a method declaration.

There are also some un-declared variables and methods inside your MyListener inner class: currentRect, rectToDraw, previouseRectDrawn and updateDrawableRect. The compiler hasn't reported these yet because the previous problems wouldn't let the outer class compile up to that point.

Also, please adjust your displayed name to meet the JavaRanch Naming Policy. User names must consist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in drawing a rectangle .....