Eastsun,你的代码前一部份我看起比较轻松,后一部份看起就困难了:
class LinkLabel extends JLabel{
private String text,url;
private boolean isSupported;
public LinkLabel(String text,String url){
this.text =text;
this.url =url;
try{
this.isSupported = Desktop.isDesktopSupported()&&Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
}catch(Exception e){
this.isSupported = false;
}
setText(false);
addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e){
setText(isSupported);
if(isSupported) setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e){
setText(false);
}
public void mouseClicked(MouseEvent e){
try{
Desktop.getDesktop().browse(new java.net.URI(LinkLabel.this.url));
}catch(Exception ex){
}
}
});
}
private void setText(boolean b){
if(!b) setText("<html><font color=black>"+text);
else setText("<html><font color=blue><u>"+text);
}
}
你这段代码是希望实现什么功能?是不是前部份要new LinkLabel(),所以你在下面写了一个LinkLabel类,希望版主将你这段代码加点注释,分别起到什么功能,好吗?谢谢,最后还有个问题就是在最后的setText()方法里为什么还有HTML的标签出现?