简单的网页浏览器

时间:2016-12-24 09:30:16
【文件属性】:

文件名称:简单的网页浏览器

文件大小:3KB

文件格式:CLASS

更新时间:2016-12-24 09:30:16

网页浏览器

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.JWindow; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; public class WebBrowser extends JFrame implements HyperlinkListener,ActionListener{ JToolBar bar=new JToolBar(); JTextField jurl=new JTextField(60); JEditorPane jEditorPanel=new JEditorPane(); JScrollPane scrollPane=new JScrollPane(jEditorPanel); // JWindow window=new JWindow(WebBrowser.this); // Toolkit toolkit=Toolkit.getDefaultToolkit(); JLabel label=new JLabel("地址"); JButton button=new JButton("转向"); Box adress=Box.createHorizontalBox(); public WebBrowser(){ this.setSize(1000,800); setResizable(false); this.setDefaultCloseOperation(EXIT_ON_CLOSE); Container contentPane=getContentPane(); scrollPane.setPreferredSize(new Dimension(100,500)); contentPane.add(scrollPane,BorderLayout.CENTER); bar.add(label); bar.add(jurl); bar.add(button); contentPane.add(bar,BorderLayout.NORTH); button.addActionListener(this); jurl.addActionListener(this); } public static void main(String[] args) { try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); } catch (Exception e) { } WebBrowser webBrowser=new WebBrowser(); webBrowser.pack(); webBrowser.setVisible(true); } @Override public void hyperlinkUpdate(HyperlinkEvent e) { // TODO Auto-generated method stub } @Override public void actionPerformed(ActionEvent e) { String url=""; if(e.getSource()==button){ url=jurl.getText(); if(url.length()>0&&url.startsWith("http://")){ try { jEditorPanel.setPage(url); jEditorPanel.setEditable(false); jEditorPanel.revalidate(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }


网友评论