當前位置:首頁 » 編程語言 » 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-11 14:18:06 瀏覽:220
佳能相機格式化存儲卡 發布:2025-07-11 14:18:02 瀏覽:314
蛾群演算法 發布:2025-07-11 14:10:36 瀏覽:109
互聯網java 發布:2025-07-11 14:08:47 瀏覽:388
伺服器程序設計是什麼 發布:2025-07-11 14:07:58 瀏覽:283
html5壓縮圖片上傳 發布:2025-07-11 13:50:02 瀏覽:691
奧迪上傳FD 發布:2025-07-11 13:49:58 瀏覽:705
ktv套餐配置比較重要的是哪些 發布:2025-07-11 13:48:37 瀏覽:116
安卓平板的游戲在哪裡下載 發布:2025-07-11 13:41:58 瀏覽:567
ssd緩存win10 發布:2025-07-11 13:36:44 瀏覽:968