/*
MenuBar.java
Menu bar for the program to hold options
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MenuBar extends JMenuBar implements ActionListener, ItemListener{
//Private data members: Mostly menu components
private JMenu jmFile = new JMenu("File");
private JMenu jmBookmarks = new JMenu("Bookmarks");
private JMenu jmHelp = new JMenu("Help");
//Items for file
private JMenuItem jmiExit = new JMenuItem("Exit");
//Items for help
private JMenuItem jmiAbout = new JMenuItem("About Shogun");
//Items for bookmark
private JMenuItem jmiAddBookmark = new JMenuItem("Add Bookmark");
private JCheckBoxMenuItem jmiRemoveBookmark = new JCheckBoxMenuItem("Remove Bookmark");
//Boolean to control the removal of bookmarks
private boolean bRemove = false;
//Reference to the BrowserFrame
private BrowserFrame bfRef;
//BookmarkList: List to contain all the bookmarks
private BookmarkList bl = new BookmarkList();
public MenuBar() {
//Default constructor
this(new BrowserFrame());
}
public MenuBar(BrowserFrame bf) {
//Constructor with reference back to the main frame
bfRef = bf;
//Adds the components to the menus
jmFile.add(jmiExit);
jmHelp.add(jmiAbout);
jmBookmarks.add(jmiAddBookmark);
jmBookmarks.add(jmiRemoveBookmark);
jmBookmarks.addSeparator();
add(jmFile);
add(jmBookmarks);
add(jmHelp);
//Add listeners so the items are usefull
jmiExit.addActionListener(this);
jmiAbout.addActionListener(this);
jmiAddBookmark.addActionListener(this);
jmiRemoveBookmark.addItemListener(this);
//Add saved bookmarks to the list
addBookmarks();
}
//Adds saved bookmarks to the list
public void addBookmarks() {
//Go through the entire list
for(int x = 0; x < bl.getSize(); x++) {
//Create a new item for each item in the list
JMenuItem jmiBM = new JMenuItem(bl.returnURL(x));
//Add it and give it a listener
jmBookmarks.add(jmiBM);
jmiBM.addActionListener(this);
}
}
//ActionPerformed - controls actionListeners
public void actionPerformed(ActionEvent e) {
//Handle the exit item
if (e.getSource() == jmiExit)
System.exit(0);
//Handle the about item
else if (e.getSource() == jmiAbout)
new PopupDialog("About Shogun", "Shogun: Written by Dennis Brown 2000");
//Handle the addBookmark item
else if (e.getSource() == jmiAddBookmark) {
//Add it to the list
bl.add(bfRef.getCurrentURL());
//Add a new bookmark item
addBookmarkItem(bfRef.getCurrentURL());
}
//If it's none of the above, it's a bookmark
else {
//If it's not in remove "mode"
if (!bRemove)
//Go to that bookmark
bfRef.setCurrentURL(e.getActionCommand());
//If it is in remove "mode"
else {
//Remove it from the menu
jmBookmarks.remove((JMenuItem) e.getSource());
try {
//And remove it from the list
bl.remove(e.getActionCommand());
}
//If there's a problem removing it from the list, report it
catch(Exception ex) {
new PopupDialog("Error", "Error removing bookmark");
}
}
}
}
//ItemStateChanged - Listens for a check box in a menu
public void itemStateChanged(ItemEvent e) {
//If it's changed, set the remove "mode" to reflect it
if(e.getSource() == jmiRemoveBookmark)
bRemove = !bRemove;
}
//Adds a new bookmark item into the menu
public void addBookmarkItem(String s) {
//Create an item, add a listener, and add it
JMenuItem newItem = new JMenuItem(s);
newItem.addActionListener(this);
jmBookmarks.add(newItem);
}
}
SHOGUN-一个用Java编的浏览器
需积分: 50 47 浏览量
2002-06-20
00:00:00
上传
评论 1
收藏 36KB ZIP 举报
普通网友
- 粉丝: 882
- 资源: 2万+
最新资源
- 基于keras+fasterRCNN,在VOC格式的口罩数据集上训练,检测人群中有无戴口罩python源码+模型
- 基于opencv+qt5机器视觉的传统缺陷检测, 即采用标准图片和待测图片进行pixel to pixel的XOR操作源码+文档
- 管道内检测缺陷数据库管理系统源码+文档说明+sln
- 毕业设计-低功耗STM32F411开发板(原理图+PCB源文件+官方例程+驱动等)源码+文档说明+截图
- 基于yolov5-tensorRT检测+发动机缸体内壁缺陷检测系统源码+文档说明
- 基于C++实现的锂电池缺陷检测源码+文档说明
- push_version
- 软件自制图像批量压缩工具
- 经典缺陷检测算法源码整理包含PaDiM(2020ICPR)、PatchCore(2022CVPR)、SimpleNet+文档说明
- 基于深度学习的抗梯度噪声的缺陷检测器python源码+文档说明+模型的预训练
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈