The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Links In Applets

Posted by Sanjay Ambardar on February 05, 2001 at 1:18 AM

> You can still use it. Just use Label instead of JLabel. YOu can change the color of the text in Label so that it may look different. I don't know how to underline a text in JDK v1.1 . You can also try to underline the text. Or, you can try it by dwawing a the text on a panel and th edraw a line of the same size as the text below it and write the same clicked event

>
> ////////////////////////

> import java.net.* ;
> import java.awt.*;
> import java.awt.event.*;
> import java.applet.* ;

>
> public class Applet1 extends Applet {
> Label lb = new Label ( "Go to Yahoo" ) ;
>
> public void init ( ) {
> add ( lb ) ;
> add ( new Button ( "Does nothing" ) ) ;
> // Change the mouse cursor
> lb.setCursor ( new Cursor ( Cursor.HAND_CURSOR )) ;
>
> // Set the color of label as blue and underline it so that
> // it looks as a link
> lb.setForeground ( Color.blue ) ;
>
> lb.addMouseListener (
> new MouseAdapter ( ) {
> public void mouseClicked ( MouseEvent e ) {
> try {
> AppletContext ac = Applet1.this.getAppletContext ( ) ;
> URL url = new URL ( "http://www.yahoo.com" ) ;
> ac.showDocument ( url ) ;
> }
> catch ( Exception ex ) { }
> }
> }
> );
> }

> }

Thanks Kishori,

I just want to know why have you used add ( new Button ( "Does nothing" ) ) in the code. Also when I move the mouse I don't get the events for the label but instead I get them when I move the mouse in and out of the frame in which they are painted!! Why so

Thanks a lot
Sanjay





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us