飘凌大杂烩手机 → 一个简单的网页浏览器
查看完整版本:一个简单的网页浏览器
2010/2/7 20:34:56
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.net.*;
class LinkFollower implements HyperlinkListener
{
private JEditorPane pane;
public LinkFollower(JEditorPane pane)
{
this.pane=pane;
}
public void hyperlinkUpdate(HyperlinkEvent evt)
{
if (evt.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
try
{
pane.setPage(evt.getURL());
}
catch(Exception e){}
}
}
}

public class simple
{
public static void main(String[] args)
{
String initialPage="http://www.oreilly.com";
if (args.length>0) initialPage=args[0];
JEditorPane jep=new JEditorPane();
jep.setEditable(false);
jep.addHyperlinkListener(new LinkFollower(jep));

try{
jep.setPage(initialPage);
}
catch(IOException e){
System.err.println("java simple url");
System.err.println(e);
System.exit(-1);
}
JScrollPane scrollPane=new JScrollPane(jep);
JFrame f=new JFrame("simple web browser");
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.setContentPane(scrollPane);
f.setSize(512,342);
f.show();
}
}
Powered by BBSXP 2007 ACCESS © 1998-2025
Processed in 0.01 second(s)