日期:2014-05-20  浏览次数:20853 次

用java设计一个简单浏览器
我 的 代码如下:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
import java.awt.event.*;
public class IE implements HyperlinkListener
{
  JLabel jl=new JLabel("请输入网址",new ImageIcon("1.jpg"),JLabel.CENTER);
JFrame jf= new JFrame("MY IE");
JTextField tf=new JTextField(25);
URL url=null;
String s;
JEditorPane html;
public static void main(String aa[])throws Exception
{
IE e=new IE();
e.go();
}
public void go()throws Exception
{
try{
  jf.setLayout(new FlowLayout());
  jf.getContentPane().add(jl);
jf.getContentPane().add(tf);
jf.getContentPane().add(html);
}catch(Exception s){}
jf.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);

});
 
  tf.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String s;
s=e.getActionCommand();
}
  });
  try
  {
  url=new URL(s);
html= new JEditorPane(url);
html.setEditable(false);
html.addHyperlinkListener(this);
}
catch(Exception a){}
jf.setSize(1000,1000);
jf.setVisible(true);
}
public void hyperlinkUpdate(HyperlinkEvent h)
{
if(h.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
{
try{
URL url=h.getURL();
html.setPage(url);
}
catch(Exception u){}
Container parent=html.getParent();
parent.repaint();
 
  }
  }
}

运行时输入网站打不开,求高手帮忙

------解决方案--------------------
JEditorPane 又不支持 JAVAScript 

还不如用SWT 来写,
------解决方案--------------------
用SWT 做的浏览器 很漂亮
要不就用jdic 做浏览器也不错