The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

simple problem w/ appelets which i cant figure out

Im trying to figure out the mouse classes for a larger project im working on. This is a really simple applet i wrote, and based off of the sun micro systems tutorial it seems like it should work. The program should simply redraw the square where ever the mouse clicks. However it doesnt do it. As i undersatnd the applet should draw, wait for a mouse command, then redraw right? but in my program my mouseUp fires (i have console out to tell me every time it fires) but then it does fire paint again, so i must be mistaken about the way applets work. What am i missing, how do i get it to redraw? and how would i get this app to work?

Re: simple problem w/ appelets which i cant figure out

also, normally i dont have the "addMouseListener(this);" line there. i know it wont compile like it is now(i dont know why), but i was trying to figure out why it wont work and forgot to take the line out.

Re: simple problem w/ appelets which i cant figure out

It'll compile now. I had assumed that java.awt.*; wouldcover it but i forgot that it wont go two deep.

That however makesmy program worse not better. The mouseUp wont even call now where before it would.
What exactly does the addMouseListener(this); do?
And why doesnt paint(g) get called again after the mouseUp is called, and how do i make it do so because i cant call paint inside the mouseUp method.

Re: simple problem w/ appelets which i cant figure out

addMouseListener(this) will register this as in your current class as a mouse listener and all events for the mouse will be sent to the methods that you had to implement. In these methods you can then get a hold of the information you need.