Mouse events

Discussion in 'Java' started by Kalvin, Dec 8, 2003.

  1. Kalvin

    Kalvin Guest

    Could someone please help me understand why my mouse events don't seem
    to do anything. The mouseClicked event will fire, but the others
    don't do what I would expect. I am very new to Java and am just
    limping along, please help me understand this.

    Everything except the mouseClicked, just shows the target link when
    the applet is clicked. I have cleared my local web cache so it
    shouldn't be using an old copy of the page. I would like to see the
    status messages appear like they are coded, but more importantly, I
    want to change the cursor when the cursor is over the applet.

    Thanks for the help.

    Kalvin

    Here is what I presume to be the relevant code:

    public class StreckMarquee extends Applet implements Runnable,
    MouseListener
    {
    /* Want other cursors? Look at API constants java.awt.Cursor */
    Cursor hand = (java.awt.Cursor.getPredefinedCursor
    (java.awt.Cursor.HAND_CURSOR));
    Cursor normal=(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));

    ... other stuff

    public void init()
    {
    // store the applet width, height and font for later use.
    Width = size().width;
    //Width = (int)getSize().getWidth();
    Height = size().height;
    //Height = (int)getSize().getHeight();

    LoadParameters(); //get the parameters from the calling page
    SetFontInfo(); //find the font style, size, and name, also sent
    from the calling page
    DrawTextImage(); //draw the text into an image

    this.addMouseListener( this );

    }

    public void mousePressed( MouseEvent e ){}

    public void mouseReleased( MouseEvent e ){}

    public void mouseDragged( MouseEvent e )
    {
    showStatus( "(" + e.getX() + "," + e.getY() + ")" );
    }

    public void mouseMoved( MouseEvent e )
    {
    showStatus( "Moving mouse at: " + e.getX() + ", " + e.getY() );
    }

    public void mouseClicked( MouseEvent e )
    {
    if( Jump)
    {
    try
    {
    String newURL = new String(this.getCodeBase()+ Link);
    //URL URLLink = new URL( getCodeBase(), Link);
    //showStatus( String.valueOf(URLLink));
    //getAppletContext().showDocument(new URL(Link), Target);
    getAppletContext().showDocument(new URL(newURL), Target);


    }
    catch (MalformedURLException exc)
    {
    showStatus("Error|MalformedURLException|Target URL invalid|");
    }
    }
    }

    public void mouseEntered( MouseEvent e ) {
    this.setCursor(hand);

    //getAppletContext().showStatus(Alt_Status?Status_Msg:Link);
    if( Status )
    getAppletContext().showStatus("kalvin");
    return;
    }
    public void mouseExited( MouseEvent e ) {
    if( Status )
    getAppletContext().showStatus(" ");
    return;
    }


    String lastStatus = "";
    public void showStatus(String line)
    {
    if(line == null) line = "" ;
    super.showStatus(lastStatus = line);

    }

    public void refreshStatus()
    {
    super.showStatus(lastStatus);
    }

    .... other unrelated code
    } //end class
     
    Kalvin, Dec 8, 2003
    #1
    1. Advertising

  2. Kalvin

    nos Guest

    for move and drag you need
    MouseMotionListener


    "Kalvin" <> wrote in message
    news:...
    > Could someone please help me understand why my mouse events don't seem
    > to do anything. The mouseClicked event will fire, but the others
    > don't do what I would expect. I am very new to Java and am just
    > limping along, please help me understand this.
    >
    > Everything except the mouseClicked, just shows the target link when
    > the applet is clicked. I have cleared my local web cache so it
    > shouldn't be using an old copy of the page. I would like to see the
    > status messages appear like they are coded, but more importantly, I
    > want to change the cursor when the cursor is over the applet.
    >
    > Thanks for the help.
    >
    > Kalvin
    >
    > Here is what I presume to be the relevant code:
    >
    > public class StreckMarquee extends Applet implements Runnable,
    > MouseListener
    > {
    > /* Want other cursors? Look at API constants java.awt.Cursor */
    > Cursor hand = (java.awt.Cursor.getPredefinedCursor
    > (java.awt.Cursor.HAND_CURSOR));
    > Cursor

    normal=(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR))
    ;
    >
    > ... other stuff
    >
    > public void init()
    > {
    > // store the applet width, height and font for later use.
    > Width = size().width;
    > //Width = (int)getSize().getWidth();
    > Height = size().height;
    > //Height = (int)getSize().getHeight();
    >
    > LoadParameters(); //get the parameters from the calling page
    > SetFontInfo(); //find the font style, size, and name, also sent
    > from the calling page
    > DrawTextImage(); //draw the text into an image
    >
    > this.addMouseListener( this );
    >
    > }
    >
    > public void mousePressed( MouseEvent e ){}
    >
    > public void mouseReleased( MouseEvent e ){}
    >
    > public void mouseDragged( MouseEvent e )
    > {
    > showStatus( "(" + e.getX() + "," + e.getY() + ")" );
    > }
    >
    > public void mouseMoved( MouseEvent e )
    > {
    > showStatus( "Moving mouse at: " + e.getX() + ", " + e.getY() );
    > }
    >
    > public void mouseClicked( MouseEvent e )
    > {
    > if( Jump)
    > {
    > try
    > {
    > String newURL = new String(this.getCodeBase()+ Link);
    > //URL URLLink = new URL( getCodeBase(), Link);
    > //showStatus( String.valueOf(URLLink));
    > //getAppletContext().showDocument(new URL(Link), Target);
    > getAppletContext().showDocument(new URL(newURL), Target);
    >
    >
    > }
    > catch (MalformedURLException exc)
    > {
    > showStatus("Error|MalformedURLException|Target URL invalid|");
    > }
    > }
    > }
    >
    > public void mouseEntered( MouseEvent e ) {
    > this.setCursor(hand);
    >
    > //getAppletContext().showStatus(Alt_Status?Status_Msg:Link);
    > if( Status )
    > getAppletContext().showStatus("kalvin");
    > return;
    > }
    > public void mouseExited( MouseEvent e ) {
    > if( Status )
    > getAppletContext().showStatus(" ");
    > return;
    > }
    >
    >
    > String lastStatus = "";
    > public void showStatus(String line)
    > {
    > if(line == null) line = "" ;
    > super.showStatus(lastStatus = line);
    >
    > }
    >
    > public void refreshStatus()
    > {
    > super.showStatus(lastStatus);
    > }
    >
    > ... other unrelated code
    > } //end class
     
    nos, Dec 8, 2003
    #2
    1. Advertising

  3. Kalvin

    Kalvin Guest

    The mouseMotionListener worked great. Thanks for the education.

    Kalvin
     
    Kalvin, Dec 9, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    2
    Views:
    1,316
    Jim Corey
    Apr 23, 2004
  2. Max
    Replies:
    7
    Views:
    9,124
  3. Claus Atzenbeck
    Replies:
    1
    Views:
    1,087
    Claus Atzenbeck
    Nov 26, 2004
  4. =?Utf-8?B?am9qb2Jhcg==?=
    Replies:
    1
    Views:
    4,090
    wwwtar
    Oct 2, 2006
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    373
    Chris
    Aug 30, 2005
Loading...

Share This Page