JAVA实现简易浏览器
发布日期:2021-05-07 06:46:22 浏览次数:20 分类:精选文章

本文共 1387 字,大约阅读时间需要 4 分钟。

在这里插入图片描述

在这里插入图片描述

package Browser;import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;import javax.swing.*;import javax.swing.event.*;public class Browsertest extends JFrame {   	private JTextField enterfield;	private JEditorPane contentsArea;	public Browsertest()	{   		super("Web浏览器");		Container container = getContentPane();		enterfield = new JTextField("http://www.google.com");		enterfield.addActionListener(				new ActionListener() {   					public void actionPerformed(ActionEvent event)					{   						getThePage(event.getActionCommand());					}				} );		container.add(enterfield,BorderLayout.NORTH);		contentsArea = new JEditorPane();		contentsArea.setEditable(false);		contentsArea.addHyperlinkListener(				new HyperlinkListener() {   					public void hyperlinkUpdate(HyperlinkEvent event)					{   						if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)							getThePage(event.getURL().toString());					}				});		container.add(new JScrollPane(contentsArea),BorderLayout.CENTER);		setSize(1000,800);		setVisible(true);	}	private void getThePage(String location) {   		try {   			contentsArea.setPage(location);			enterfield.setText(location);		}catch(IOException ioException) {   			System.out.println("Bad URL");		}			}		public static void main(String args[]) {   		Browsertest app = new Browsertest();		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	}}
上一篇:物理层传输总结
下一篇:Java读入中文文件乱码现象的解决方案|java

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月05日 10时03分06秒