當前位置:首頁 » 編程語言 » 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 09:46:15 瀏覽:543
編譯原理re不能描述的串 發布:2025-07-01 09:34:24 瀏覽:75
本地電腦怎麼用伺服器ip 發布:2025-07-01 09:10:03 瀏覽:830
有趣的python代碼 發布:2025-07-01 09:10:02 瀏覽:361
威龍奇兵ftp 發布:2025-07-01 09:07:38 瀏覽:694
linuxedit 發布:2025-07-01 09:03:36 瀏覽:424
跑分平台腳本 發布:2025-07-01 08:40:17 瀏覽:600
手機上的中文編程軟體 發布:2025-07-01 08:39:13 瀏覽:822
7z解壓縮linux 發布:2025-07-01 08:37:47 瀏覽:321
sybase資料庫字元集 發布:2025-07-01 08:37:03 瀏覽:349