java写的一个简易的浏览器
2009-07-21 09:13
267 查看
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class HTTPBrowserDemo extends JFrame {
private JLabel jlAddress,jlInfo;
private JTextField jtfAddress;
private JEditorPane jtpShow;
private JPanel panel;
private JButton btnGO;
public static void main(String[] args) {
HTTPBrowserDemo hbd=new HTTPBrowserDemo();
}
HTTPBrowserDemo(){
jlAddress=new JLabel("地址");
jlInfo=new JLabel();
jtpShow=new JEditorPane();
panel=new JPanel();
jtfAddress=new JTextField(20);
btnGO=new JButton("转到");
add(panel,BorderLayout.NORTH);
add(jtpShow,BorderLayout.CENTER);
add(jlInfo,BorderLayout.SOUTH);
panel.add(jlAddress);
panel.add(jtfAddress);
panel.add(btnGO);
setVisible(true);
setSize(350, 280);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnGO.addActionListener(new ShowHTMLListener());
jtpShow.setEditable(false);
jtpShow.addHyperlinkListener(new MyHyperlinkListener());
}
class ShowHTMLListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String str=jtfAddress.getText();
try {
if (!str.startsWith("http://")){
str="http://"+str;
}
jlInfo.setText("连接中...");
URL address=new URL(str);
jtpShow.setPage(address);
jlInfo.setText("完成");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO: handle exception
}
}
}
class MyHyperlinkListener implements HyperlinkListener{
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
JEditorPane pane=(JEditorPane)e.getSource();
try {
pane.setPage(e.getURL());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
import java.awt.event.*;
import java.io.IOException;
import java.net.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class HTTPBrowserDemo extends JFrame {
private JLabel jlAddress,jlInfo;
private JTextField jtfAddress;
private JEditorPane jtpShow;
private JPanel panel;
private JButton btnGO;
public static void main(String[] args) {
HTTPBrowserDemo hbd=new HTTPBrowserDemo();
}
HTTPBrowserDemo(){
jlAddress=new JLabel("地址");
jlInfo=new JLabel();
jtpShow=new JEditorPane();
panel=new JPanel();
jtfAddress=new JTextField(20);
btnGO=new JButton("转到");
add(panel,BorderLayout.NORTH);
add(jtpShow,BorderLayout.CENTER);
add(jlInfo,BorderLayout.SOUTH);
panel.add(jlAddress);
panel.add(jtfAddress);
panel.add(btnGO);
setVisible(true);
setSize(350, 280);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnGO.addActionListener(new ShowHTMLListener());
jtpShow.setEditable(false);
jtpShow.addHyperlinkListener(new MyHyperlinkListener());
}
class ShowHTMLListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String str=jtfAddress.getText();
try {
if (!str.startsWith("http://")){
str="http://"+str;
}
jlInfo.setText("连接中...");
URL address=new URL(str);
jtpShow.setPage(address);
jlInfo.setText("完成");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO: handle exception
}
}
}
class MyHyperlinkListener implements HyperlinkListener{
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
JEditorPane pane=(JEditorPane)e.getSource();
try {
pane.setPage(e.getURL());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
相关文章推荐
- 使用XML布局文件和java代码共同控制UI界面做一个简易图片浏览器
- [Java]一个简易的生成流水号的类
- 继上一个三级联动的补充--使用jQuery编写各种浏览器兼容简易项目
- 一个简易的Java爬虫程序
- 用Java实现的一个本地文件浏览器
- 使用JAVA写的一个简易通讯程序(一)
- Java 实现的简易浏览器
- 用java实现一个简易编译器1-词法解析入门
- 根据JAVA的CS模型框架做了一个简易的分布式文件系统
- 用java写的一个简易记事本
- Java 设计一个贷款计算器 简易
- 使用java创建一个简易的视屏播放器
- 34.UIWebView(做一个简易的浏览器)
- 如何开发一个java开源框架-----Jvn框架之实现浏览器传参后台转成Bean(第四)
- Java+MySql+Servlet+Ajax实现单态登陆,说白了就是一个账号只能在一个浏览器中登陆。
- 一个简易的java自带的观察者模式实现
- 写一个简易浏览器、ASP.NET核心知识(3)
- 用WPF做一个简易浏览器
- 【JAVA】43、编写一个简易录入系统
- 用JAVA写一个简易图片防篡改