[java]代码库
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.event.*;
import javax.swing.*;
/**
* 史上最烂最精简的java版浏览器
*/
public class Explorer {
public static void main(String args[]) {
new LinkWin();
}
}
class LinkWin extends JFrame implements ActionListener, Runnable {
Button button;
URL url;
TextField text;
JEditorPane editpane;
byte b[] = new byte[118];
Thread thread;
public LinkWin() {
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(60, 60, 360, 300);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editpane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
editpane.setPage(e.getURL());
} catch (IOException e1) {
editpane.setText("" + e1);
}
}
}
});
}
public void actionPerformed(ActionEvent e) {
if (!(thread.isAlive()))
thread = new Thread(this);
try {
thread.start();
} catch (Exception ee) {
text.setText("我正在读取" + url);
}
}
public void run() {
try {
editpane.setText(null);
url = new URL(text.getText().trim());
editpane.setPage(url);
} catch (Exception e1) {
text.setText("" + e1);
return;
}
}
}
[代码运行效果截图]