当前位置:首页 » 编程语言 » 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-17 19:00:32 浏览:997
php判断设备 发布:2025-09-17 18:27:53 浏览:400
医院存储方案 发布:2025-09-17 18:26:38 浏览:350
用户注册java 发布:2025-09-17 18:23:40 浏览:396
centosftp不能上传 发布:2025-09-17 18:19:15 浏览:733
我的世界超平坦生存服务器 发布:2025-09-17 18:01:06 浏览:758
手机只上微信要什么配置 发布:2025-09-17 17:56:19 浏览:694
什么叫配置高的电脑 发布:2025-09-17 17:53:15 浏览:571
php考试系统源码 发布:2025-09-17 17:52:27 浏览:824
打牌的算法 发布:2025-09-17 17:37:46 浏览:174