超链接问题
为什么下面的程序不能打开超链接import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.JEditorPane;
import javax.swing.*;
import javax.swing.event.*;
public class Example11_2 {
public static void main(String args[])
{
new Win();
}
}
class Win extends JFrame implements ActionListener,Runnable
{
Button button;
URL url;
TextField text;
JEditorPane editPane;
byte b[]=new byte[118];
Thread thread;
public Win()
{
text=new TextField(20);
editPane=new JEditorPane();
editPane.setEditable(false);
button=new Button("确定");
button.addActionListener(this);
thread=new Thread(this);
Panel p=new Panel();
p.add(new Label("输入网址:"));
p.add(text);
p.add(button);
ScrollPane scroll=new ScrollPane();
scroll.add(editPane);
add(scroll,BorderLayout.CENTER);
add(p,BorderLayout.NORTH);
setBounds(160,60,360,300);
setVisible(true);
validate();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent e)
{
if(e.getSource()==HyperlinkEvent.EventType.ENTERED)
{
try{
editPane.setPage(e.getURL());
}
catch(IOException e2){
System.out.println(e2);
}
}
}
});
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
{
thread=new Thread(this);
}
try{
thread.start();
}
catch(Exception ee){}
}
public void run()
{
try{
editPane.setText(null);
url=new URL("http://"+text.getText().trim());
editPane.setPage(url);
}
catch(Exception e1){
return;
}
}
}
----------------解决方案--------------------------------------------------------
我试了下,可以打开啊
----------------解决方案--------------------------------------------------------