By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Using implements Runnable and MouseListener

P: n/a
I am fairly new to Java but have written an applet that uses 'implements
Runnable' to do some timing
eg
public class Puzzle extends Applet implements Runnable
{ etc.

and also an applet which detects left, right and double mouse clicks using
'implements MouseListener'
eg
public class TestMouse extends Applet implements
MouseListner { etc.

I would now like to write an applet that uses both of these so that I can
detect the mouse actions as well as do some timing.

Could someone show me the structure that would be used to allow both
implements Runnable and MouseListener in the same Java applet? This is
probably quite obvious to a regular Java programmer but I am an old style
programmer trying to convert to Java.

Thank you.
Doug van Vianen
co*****@shaw.ca
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Doug van Vianen wrote:
I am fairly new to Java but have written an applet that uses
'implements Runnable' to do some timing
eg
public class Puzzle extends Applet implements
Runnable
{ etc.

and also an applet which detects left, right and double mouse clicks
using 'implements MouseListener'
eg
public class TestMouse extends Applet implements
MouseListner { etc.

I would now like to write an applet that uses both of these so that
I can detect the mouse actions as well as do some timing.

Could someone show me the structure that would be used to allow both
implements Runnable and MouseListener in the same Java applet? This
is probably quite obvious to a regular Java programmer but I am an
old style programmer trying to convert to Java.

Thank you.
Doug van Vianen
co*****@shaw.ca


Hi,
Although a class can only *extend* one other class, it can *implement*
any number of interfaces:

public class MyApplet extends Applet implements Runnable,
MouseListener {
....
}

Just keep adding more and more with commas until you have everything
you need.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAJRvynwjA8LryK2IRAvcUAJ4xuNa2psgGsLgpN9+BfN Va+7AKigCgql6r
cTiNtMqFqYlkeQ55JTD83Kk=
=lTT8
-----END PGP SIGNATURE-----
Jul 17 '05 #2

P: n/a
"Doug van Vianen" <co*****@shaw.ca> wrote in message news:<hZaVb.416128$JQ1.297480@pd7tw1no>...
I am fairly new to Java but have written an applet that uses 'implements
Runnable' to do some timing
eg
public class Puzzle extends Applet implements Runnable
{ etc.

and also an applet which detects left, right and double mouse clicks using
'implements MouseListener'
eg
public class TestMouse extends Applet implements
MouseListner { etc.

I would now like to write an applet that uses both of these so that I can
detect the mouse actions as well as do some timing.

Could someone show me the structure that would be used to allow both
implements Runnable and MouseListener in the same Java applet? This is
probably quite obvious to a regular Java programmer but I am an old style
programmer trying to convert to Java.

Thank you.
Doug van Vianen
co*****@shaw.ca


The most typically, timing thread, which is your runnable, does some
sleep() and call applet's repaint() -- that is it is a controller for
some animation. MouseListener will do whatever it likes in its various
methods.
Jul 17 '05 #3

P: n/a

"Chris" <ch*******@hotmail.com> wrote in message
news:yCbVb.4075$964.1401@edtnps84...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Doug van Vianen wrote:
I am fairly new to Java but have written an applet that uses
'implements Runnable' to do some timing
eg
public class Puzzle extends Applet implements
Runnable
{ etc.

and also an applet which detects left, right and double mouse clicks
using 'implements MouseListener'
eg
public class TestMouse extends Applet implements
MouseListner { etc.

I would now like to write an applet that uses both of these so that
I can detect the mouse actions as well as do some timing.

Could someone show me the structure that would be used to allow both
implements Runnable and MouseListener in the same Java applet? This
is probably quite obvious to a regular Java programmer but I am an
old style programmer trying to convert to Java.

Thank you.
Doug van Vianen
co*****@shaw.ca


Hi,
Although a class can only *extend* one other class, it can *implement*
any number of interfaces:

public class MyApplet extends Applet implements Runnable,
MouseListener {
...
}

Just keep adding more and more with commas until you have everything
you need.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAJRvynwjA8LryK2IRAvcUAJ4xuNa2psgGsLgpN9+BfN Va+7AKigCgql6r
cTiNtMqFqYlkeQ55JTD83Kk=
=lTT8
-----END PGP SIGNATURE-----


Thank you, Chris. That is the simply, easy-to-follow answers that are
great!!

Doug
co*****@shaw.ca
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.