當前位置:首頁 » 編程語言 » 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();
}
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:547
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:832
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:537
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:717
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:639
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:955
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:211
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:68
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:761
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:666