暂不支持css
/**
* @(#)WebBrowser.java
*/
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.MouseListener;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import java.io.*;
import java.net.*;
import java.util.*;
public class WebBrowser extends JFrame implements HyperlinkListener,ActionListener{
/**
* Creates a new instance of <code>WebBrowser</code>.
*/
//.......
//.........
//建立主件
JToolBar bar =new JToolBar();//工具栏
JTextField jurl=new JTextField(60);//地址栏
JTextField jurlSource=new JTextField(60);//地址栏
JEditorPane2 jEditorPane1=new JEditorPane2();//网页框
JScrollPane scrollPane=new JScrollPane(jEditorPane1);//滚动条
JFileChooser chooser=new JFileChooser();
JFileChooser chooser1=new JFileChooser();//选择文件
String htmlSource;
JWindow window=new JWindow(WebBrowser.this);//使用指定的所有者框架创建窗口
JButton button2=new JButton("go back");
Toolkit toolkit=Toolkit.getDefaultToolkit();//获取默认工具包
JMenuBar jMenuBar1=new JMenuBar();//建立菜单栏
JMenu fileMenu=new JMenu("File(F)");//建立菜单组
JMenuItem saveAsItem=new JMenuItem("save As(S)");
JMenuItem exitItem=new JMenuItem("exit(E)");
JMenu bookMarkMenu=new JMenu("bookMark(B)");//建立菜单组
JMenuItem saveBookMarkItem=new JMenuItem("save bookmark(K)");
JMenu editMenu=new JMenu("Edit(E)");//建立菜单组
JMenuItem backItem=new JMenuItem("Back(Z)");
JMenuItem forwardItem=new JMenuItem("Forward(P)");
JMenu viewMenu=new JMenu("View(V)");//建立菜单组
JMenuItem fullscreenItem=new JMenuItem("fullscreen(U)");
JMenuItem sourceItem=new JMenuItem("source(C)");
JMenuItem reloadItem=new JMenuItem("reload(R)");
JToolBar toolBar=new JToolBar();
JButton picSave=new JButton("save as");
JButton picBack=new JButton("back");
JButton picForward=new JButton("forward");
JButton picView=new JButton("source");
JButton picExit=new JButton("exit");
//建立工具栏
JLabel label=new JLabel("Adress");
JButton button=new JButton("GO");
JLabel labelSource=new JLabel("View Source");
JButton buttonSource=new JButton("View");
Box adress=Box.createHorizontalBox(); //创建一个从左到右显示其组件
Box adressSource=Box.createHorizontalBox();
private ArrayList history=new ArrayList();
private int historyIndex;
public WebBrowser() {
setTitle("network by liujia");
setResizable(false);//设置此 frame 是否可由用户调整大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jEditorPane1.addHyperlinkListener(this);//事件监听
bookMarkMenu.setMnemonic('B');
saveBookMarkItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K,InputEvent.CTRL_MASK));
fileMenu.setMnemonic('F');
saveAsItem.setMnemonic('S');
saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
exitItem.setMnemonic('P');
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK));
//设置热键
fileMenu.add(saveAsItem);
fileMenu.addSeparator();
fileMenu.add(exitItem);
backItem.setMnemonic('B');
backItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.CTRL_MASK));
forwardItem.setMnemonic('D');
forwardItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK));
editMenu.setMnemonic('E');
editMenu.add(backItem);
editMenu.addSeparator();
editMenu.add(forwardItem);
viewMenu.setMnemonic('V');
fullscreenItem.setMnemonic('U');
fullscreenItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,InputEvent.CTRL_MASK));
sourceItem.setMnemonic('C');
sourceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
reloadItem.setMnemonic('R');
reloadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,InputEvent.CTRL_MASK));
Container contentPane=getContentPane();
scrollPane.setPreferredSize(new Dimension(100,500));
contentPane.add(scrollPane,BorderLayout.SOUTH);
adressSource.add(labelSource);
adressSource.add(jurlSource);
adressSource.add(buttonSource);
toolBar.add(picSave);
toolBar.addSeparator();
toolBar.add(picBack);
toolBar.addSeparator();
toolBar.add(picForward);
toolBar.addSeparator();
toolBar.add(picView);
toolBar.addSeparator();
toolBar.add(picExit);
toolBar.addSeparator();
toolBar.add(picExit);
toolBar.addSeparator();
toolBar.add(adressSource);
contentPane.add(bar,BorderLayout.CENTER);
contentPane.add(toolBar,BorderLayout.NORTH);
viewMenu.add(fullscreenItem);
viewMenu.addSeparator();
viewMenu.add(sourceItem);
viewMenu.addSeparator();
viewMenu.add(reloadItem);
bookMarkMenu.add(saveBookMarkItem);
jMenuBar1.add(fileMenu);
jMenuBar1.add(editMenu);
jMenuBar1.add(viewMenu);
jMenuBar1.add(bookMarkMenu);
setJMenuBar(jMenuBar1);
adress.add(label);
adress.add(jurl);
adress.add(button);
bar.add(adress);
saveAsItem.addActionListener(this);
picSave.addActionListener(this);
exitItem.addActionListener(this);
picExit.addActionListener(this);
backItem.addActionListener(this);
picBack.addActionListener(this);
forwardItem.addActionListener(this);
picForward.addActionListener(this);
fullscreenItem.addActionListener(this);
sourceItem.addActionListener(this);
picView.addActionListener(this);
reloadItem.addActionListener(this);
button.addActionListener(this);
buttonSource.addActionListener(this);
jurl.addActionListener(this);
jurlSource.addActionListener(this);
saveBookMarkItem.addActionListener(this);
}
//..................
//.....