Java Reference
In-Depth Information
L ISTING 11.2 The JNLPLabel Class
11
package com.marinilli.b2.c11.util;
import javax.swing.JLabel;
import java.awt.event.*;
import java.util.*;
import java.awt.Cursor;
import java.net.URL;
import javax.swing.event.*;
/**
* Chapter 11 - A Label that launches a browser
* @author Mauro Marinilli
* @version 1.0
*/
public class JNLPLabel extends JLabel implements MouseListener {
private String text = “”;
private URL url= null;
private static final String COLOR_BEFORE_CLICKING = “blue”;
private static final String COLOR_AFTER_CLICKING = “purple”;
private boolean alreadyClicked = false;
private transient Vector hListeners;
public JNLPLabel() {
addMouseListener(this);
}
public void mouseClicked(MouseEvent e) {
alreadyClicked=true;
java.awt.Toolkit.getDefaultToolkit().beep();
fireHyperlinkUpdate(new HyperlinkEvent
(this, HyperlinkEvent.EventType.ACTIVATED,url));
Utilities.getBasicService().showDocument(url);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
if (!alreadyClicked)
super.setText(“<html><font color=”+COLOR_BEFORE_CLICKING+” >
<u>”+text+”</u></font>”);
else
super.setText(“<html><font color=”+COLOR_AFTER_CLICKING+” >
<u>”+text+”</u></font>”);
Search WWH ::




Custom Search