当前位置:首页 » 编程语言 » 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-07-01 03:28:23 浏览:114
u盘插安卓手机上怎么加密 发布:2025-07-01 03:09:19 浏览:90
php记住我 发布:2025-07-01 02:58:51 浏览:392
流媒体服务器搭建php 发布:2025-07-01 02:54:24 浏览:371
我的世界服务器地板方块 发布:2025-07-01 02:41:35 浏览:564
魔域服务器爆满怎么进 发布:2025-07-01 02:31:42 浏览:739
c语言统计字符出现的次数 发布:2025-07-01 02:27:24 浏览:242
江铃福特主要有哪些车型以及配置 发布:2025-07-01 02:23:10 浏览:25
格式化数据库 发布:2025-07-01 02:15:03 浏览:267
苏州数据库 发布:2025-07-01 02:09:25 浏览:617