aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes beginner / mouse listener, ears are plugged Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "beginner / mouse listener, ears are plugged" Watch "beginner / mouse listener, ears are plugged" New topic

beginner / mouse listener, ears are plugged

ed jones

Joined: Oct 01, 2008
Posts: 11
I've read alot of code on mouse listeners, and I'm still stuck

I've created a rectangle, and when the mouse is inside, and I click, I should see a response in the rectangle, but I don't?

thanks for your time

heres some of the code

[edit]Add code tags. CR[/edit]
[ October 17, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36599
I can't see anything wrong with the code.

What you are doing is setting xpos and ypos, but you are not doing anything with them.

Try putting this is your mousePressed() method, press your mouse, and see what happensPlease find the code button and use tags to maintain your indentation. This sort of thing is usually discussed in the Swing forum, so I think I ought to move you there.

[/edit]Spelling errors and change mouseDragged to mousePressed[/edit]
[ October 17, 2008: Message edited by: Campbell Ritchie ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
a lot depends on what your classes are i.e. components etc.
assuming they are, the program is unlikely to print anything that can be seen.

you add a mouseListener to outsideFrame
you also add the mouseListener to 'extends GraphicsProgram' (whatever that is)
then you add outsideFrame to 'extends GraphicsProgram'

so the mouse will be clicking outsideFrame, but repaint() and paint()
belong to 'extends GraphicsProgram' which is perhaps covered by outsideFrame
I agree. Here's the link:
subject: beginner / mouse listener, ears are plugged
Similar Threads
AWT Applet Instantiation Error
Comparing co-ordinates
placing images in applets
Instantiation Error in AWT Applet code
[new user!] I've got an undecorated window, how can I make it resizable?