当前位置:首页 » 编程语言 » 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();
}
}

热点内容
火车头密码指纹锁多少钱 发布:2025-09-18 23:16:55 浏览:127
雪佛兰最高配置长什么样 发布:2025-09-18 23:16:54 浏览:161
网络通话源码 发布:2025-09-18 23:07:23 浏览:80
asp如何购买服务器 发布:2025-09-18 22:46:24 浏览:664
网页加密代码 发布:2025-09-18 21:56:12 浏览:165
安卓targz解压 发布:2025-09-18 21:45:58 浏览:802
怎么设置手机屏幕密码怎么设置 发布:2025-09-18 21:44:18 浏览:819
直线插补算法 发布:2025-09-18 21:22:49 浏览:656
矩阵内的算法 发布:2025-09-18 20:55:07 浏览:573
android网络优化 发布:2025-09-18 20:53:19 浏览:219