Using implements Runnable and MouseListener

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug van Vianen

    Using implements Runnable and MouseListener

    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
    courses@shaw.ca


  • Chris

    #2
    Re: Using implements Runnable and MouseListener

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Doug van Vianen wrote:
    [color=blue]
    > 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
    > courses@shaw.ca[/color]

    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)

    iD8DBQFAJRvynwj A8LryK2IRAvcUAJ 4xuNa2psgGsLgpN 9+BfNVa+7AKigCg ql6r
    cTiNtMqFqYlkeQ5 5JTD83Kk=
    =lTT8
    -----END PGP SIGNATURE-----

    Comment

    • hiwa

      #3
      Re: Using implements Runnable and MouseListener

      "Doug van Vianen" <courses@shaw.c a> wrote in message news:<hZaVb.416 128$JQ1.297480@ pd7tw1no>...[color=blue]
      > 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
      > courses@shaw.ca[/color]

      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.

      Comment

      • Doug van Vianen

        #4
        Re: Using implements Runnable and MouseListener


        "Chris" <chris2k01@hotm ail.com> wrote in message
        news:yCbVb.4075 $964.1401@edtnp s84...[color=blue]
        > -----BEGIN PGP SIGNED MESSAGE-----
        > Hash: SHA1
        >
        > Doug van Vianen wrote:
        >[color=green]
        > > 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
        > > courses@shaw.ca[/color]
        >
        > 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)
        >
        > iD8DBQFAJRvynwj A8LryK2IRAvcUAJ 4xuNa2psgGsLgpN 9+BfNVa+7AKigCg ql6r
        > cTiNtMqFqYlkeQ5 5JTD83Kk=
        > =lTT8
        > -----END PGP SIGNATURE-----[/color]

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

        Doug
        courses@shaw.ca


        Comment

        Working...