当前位置:首页 » 编程语言 » java内嵌浏览器

java内嵌浏览器

发布时间: 2022-12-17 02:28:11

⑴ 用java编写一个简单的浏览器程序

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.event.*;
@SuppressWarnings("serial")
class Win3 extends JFrame implements ActionListener,Runnable
{
JButton button;
URL url;
JTextField text;
JEditorPane editPane;
byte b[]=new byte[118];
Thread thread;
public Win3()
{
text=new JTextField(20);
editPane=new JEditorPane();
editPane.setEditable(false);
button=new JButton("确定");
button.addActionListener(this);
thread=new Thread(this);
JPanel p=new JPanel();
p.add(new JLabel("输入网址:"));
p.add(text);
p.add(button);
Container con=getContentPane();
con.add(new JScrollPane(editPane),BorderLayout.CENTER);
con.add(p,BorderLayout.NORTH);
setBounds(60,60,400,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 {
int n=-1;
editPane.setText(null);
url=new URL(text.getText().trim());
editPane.setPage(url);
}
catch(MalformedURLException e1)
{
text.setText(""+e1);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return;
}
}
}
public class Example3
{
public static void main(String args[])
{
new Win3();
}
}

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:568
制作脚本网站 发布:2025-10-20 08:17:34 浏览:857
python中的init方法 发布:2025-10-20 08:17:33 浏览:556
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:737
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:659
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:978
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:231
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:89
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:781
python股票数据获取 发布:2025-10-20 07:39:44 浏览:684