Mouse events

K

Kalvin

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
 
N

nos

for move and drag you need
MouseMotionListener


Kalvin said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top