用JAVA编写一个简单的浏览器程序

用JAVA编写一个简单的浏览器程序,第1张

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,浏览器支持的脚本语言是javascript,和java没有一毛钱关系。

有个很古老的东东,叫javaapplet,在浏览器插件支持的情况下,可以从网页启动java程序,但只是启动,程序并不在浏览器内部运行睁世。目前主流的悉绝肢浏览器逐渐放弃这种方式,因为太过古老,宏薯而且会带来安全性问题。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/12500450.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存