当前位置:首页 » 编程语言 » 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-03 10:46:38 浏览:518
神州防火墙web怎么配置代码 发布:2025-07-03 10:37:54 浏览:327
安卓看小说哪个软件免费又最好 发布:2025-07-03 10:25:30 浏览:429
linuxprofile 发布:2025-07-03 10:25:29 浏览:718
存储蓝盘 发布:2025-07-03 09:55:10 浏览:886
java必学 发布:2025-07-03 09:21:57 浏览:446
go在线编译 发布:2025-07-03 09:14:51 浏览:19
存储控制器hp 发布:2025-07-03 08:59:51 浏览:504
密码锁延安多少一条 发布:2025-07-03 08:58:14 浏览:322
linux中gcc 发布:2025-07-03 08:51:04 浏览:412