Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Mouse events (http://www.velocityreviews.com/forums/t129430-mouse-events.html)

Kalvin 12-08-2003 04:11 PM

Mouse events
 
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.a wt.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_Ms g: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 12-08-2003 06:59 PM

Re: Mouse events
 
for move and drag you need
MouseMotionListener


"Kalvin" <ktuel@streck.com> wrote in message
news:879688dc.0312080811.293c7bbf@posting.google.c om...
> 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.a wt.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_Ms g: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 12-09-2003 03:51 PM

Re: Mouse events
 
The mouseMotionListener worked great. Thanks for the education.

Kalvin


All times are GMT. The time now is 02:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.