【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“BrowserFrame.java”一文,供大家参考学习!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* BrowserFrame.java
*
* Created on 2008-7-3, 10:39:51
*/
package com.lzw;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import com.lzw.Browser.Browser;
import com.lzw.extClass.MyMap;
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
/**
*
* @author lzwJava
*/
public class BrowserFrame extends javax.swing.JFrame {
private TabbedModel tabModel = new TabbedModel(this);
private URL homePage;
private MyMap favorite;
private javax.swing.JMenuItem addFavoriteMenuItem;
private javax.swing.JTextField address;
private javax.swing.JButton backButton;
private javax.swing.JMenuItem backMenuItem;
private javax.swing.JMenuItem bottomTabMenuItem;
private com.lzw.BrowserPanel broserPanel1;
private javax.swing.JTabbedPane browserTabbedPane;
private javax.swing.JMenu favoriteMenu;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton forwardButton;
private javax.swing.JMenuItem forwardMenuItem;
private javax.swing.JButton goButton;
private javax.swing.JMenu goMenu;
private javax.swing.JButton homePageButton;
private javax.swing.JMenuItem homePageMenuItem;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenuItem exitItem;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JToolBar jToolBar1;
private JPanel addressBar;
private javax.swing.JMenuItem leftTabMenuItem;
private javax.swing.JMenuBar menuBar;
private javax.swing.JButton printButton;
private javax.swing.JMenuItem printMenuItem;
private javax.swing.JButton refreshButton;
private javax.swing.JMenuItem refreshMenuItem;
private javax.swing.JMenuItem rightTabMenuItem;
private javax.swing.JMenuItem sortFavoriteMenuItem;
private javax.swing.JLabel statusLabel;
private javax.swing.JButton stopButton;
private javax.swing.JMenuItem stopMenuItem;
private javax.swing.JMenu tabMenu;
private javax.swing.JMenuItem topTabMenuItem;
/** Creates new form BrowserFrame */
public BrowserFrame() {
try {
initComponents();
favorite = new MyMap(favoriteMenu.getText());
homePage = new URL("http://www.mingribook.com");
reloadFavorite();
} catch (Exception ex) {
Logger.getLogger(BrowserFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
}
/**
* 装载收藏夹内容的方法
*/
public void reloadFavorite() {
// 创建序列化的文件对象
File file = new File("data/favorite.data");
if (file.exists()) { // 如果文件存在
try {
// 创建文件的输入流
FileInputStream fis = new FileInputStream(file);
// 使用对象输入流封装文件输入流
ObjectInputStream ois = new ObjectInputStream(fis);
favorite = (MyMap) ois.readObject(); // 读取收藏夹的集合对象
homePage = (URL) ois.readObject(); // 读取主页URL对象
ois.close(); // 关闭对象输入流
fis.close(); // 关闭文件输入流
addFavoriteItem(); // 添加收藏夹菜单
} catch (Exception ex) {
Logger.getLogger(BrowserFrame.class.getName()).log(
Level.SEVERE, null, ex);
}
}
}
/**
* 保存收藏夹的方法
*/
public void storeFavorite() {
try {
// 创建序列化的文件对象
File file = new File("data/favorite.data");
if (!file.exists()) { // 如果文件不存在
file.getParentFile().mkdirs();// 创建存放文件的文件夹
file.createNewFile(); // 创建新的文件
}
// 获取文件输出流
FileOutputStream fout = new FileOutputStream(file);
// 使用对象输出流封装文件输出流
ObjectOutputStream out = new ObjectOutputStream(fout);
out.writeObject(favorite);// 将收藏夹的集合对象序列化到文件中
out.writeObject(homePage);// 将主页的URL对象序列化到文件中
out.flush();
out.close();// 关闭对象输出流
fout.close();// 关闭文件输出流
} catch (Exception e) {
e.printStackTrace();
}
}
// 创建浏览器选项卡的方法
public void createBrowserTab(URL url) {
// 创建浏览器面板对象
final BrowserPanel browserPanel = new BrowserPanel(url, this);
// 将浏览器面板添加到选项卡面板中
browserTabbedPane.addTab("空", browserPanel);
// 设置浏览器面板为选项卡面板当前被选择的组件
browserTabbedPane.setSelectedComponent(browserPanel);
}
// 获取当前浏览器对象的方法
public Browser getSelBrowser() {
// 获取选项卡面板当前选择的浏览器面板组件
BrowserPanel selBrowserPanel = (BrowserPanel) browserTabbedPane
.getSelectedComponent();
// 获取浏览器面板组件中的浏览器组件
Browser browser = selBrowserPanel.getBrowser();
// 返回浏览器组件实例
return browser;
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jToolBar1 = new javax.swing.JToolBar();
jToolBar1.setFloatable(false);
backButton = new javax.swing.JButton();
backButton.setIcon(new ImageIcon(getClass().getResource("/res/backBtn.png")));
forwardButton = new javax.swing.JButton();
forwardButton.setIcon(new ImageIcon(getClass().getResource("/res/forwardBtn.png")));
stopButton = new javax.swing.JButton();
stopButton.setIcon(new ImageIcon(getClass().getResource("/res/stopBtn.png")));
refreshButton = new javax.swing.JButton();
refreshButton.setIcon(new ImageIcon(getClass().getResource("/res/refreshBtn.png")));
homePageButton = new javax.swing.JButton();
homePageButton.setIcon(new ImageIcon(getClass().getResource("/res/homePageBtn.png")));
printButton = new javax.swing.JButton();
printButton.setIcon(new ImageIcon(getClass().getResource("/res/printBtn.png")));
addressBar = new JPanel();
addressBar.setLayout(new BorderLayout());
jLabel1 = new javax.swing.JLabel();
address = new javax.swing.JTextField();
address.addKeyListener(new
上一篇:
Browser1.java
下一篇:
秋天是疼痛的