Swing 在JLabel上实现连接,下划线,鼠标手型变化

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Desktop;
 
 
class URLLabel extends JLabel implements MouseListener{
public URLLabel (String ustr,String ttt){
this.ustr=ustr;
this.setText("<html><u>"+ttt+"</u></html>");
this.setForeground(Color.white);//设置链接颜色
this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//设置鼠标样式
this.setToolTipText(ttt);//设置提示文字
this.addMouseListener(this);
}
//点击时打开默认浏览器浏览指定的页面。
public void mouseClicked(MouseEvent e) { 
try {
Desktop.getDesktop().browse(new URI(ustr));
} catch (Exception e1) { e.paramString();}
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
 
private String ustr;
}
 


你可能感兴趣的:(exception,swing,String,浏览器,Class,import)