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.add (forwardItem);
viewMenu.setMnemonic('V');
【手机代码查看器java 如何用手机查看代码】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);
//在工具栏中添加按钮组件
toolBar.add(picSave);
toolBar.addSeparator();
toolBar.add(picBack);
toolBar.add(picForward);
toolBar.addSeparator();
toolBar.add(picView);
toolBar.addSeparator();
toolBar.add(picExit);
contentPane.add (bar,BorderLayout.CENTER);
contentPane.add(toolBar,BorderLayout.NORTH);
viewMenu.add (fullscreenItem);
viewMenu.add (sourceItem);
viewMenu.addSeparator ();
viewMenu.add (reloadItem);
jMenuBar1.add (fileMenu);
jMenuBar1.add (editMenu);
jMenuBar1.add (viewMenu);
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);
jurl.addActionListener(this);
}
/**
**实现监听器接口的actionPerformed函数
*/
public void actionPerformed(ActionEvent e) {
String url = "";
//点击转向按钮
if (e.getSource() == button){
//获得地址栏的内容
url=jurl.getText ();
//url不为“”,并且以“http://”开头
if(url.length ()0url.startsWith ("http://")){
try {
//JEditorPane组件显示url的内容链接
jEditorPane1.setPage (url);
//将url的内容添加到ArrayList对象history中
history.add(url);
//historyIndex的数值设为history对象的长度-1
historyIndex=history.size()-1;
//重新布局
jEditorPane1.setEditable(false); //add by copy editor :)
jEditorPane1.revalidate ();
}
catch(Exception ex) {
//如果链接显示失败,则弹出选择对话框“无法打开该搜索页”
JOptionPane.showMessageDialog (WebBrowser.this,"无法打开该搜索页","网页浏览器",JOptionPane.ERROR_MESSAGE);
}
}
//url不为“”,并且不以“http://”开头
else if(url.length ()0!url.startsWith ("http://")) {
//在url前面添加“http://”
url="http://"+url;
try {
jEditorPane1.setPage (url );
history.add(url);
historyIndex=history.size()-1;
jEditorPane1.setEditable(false); //add by copy editor :)
jEditorPane1.revalidate ();
}
catch(Exception ex) {
JOptionPane.showMessageDialog (WebBrowser.this,"无法打开该搜索页","网页浏览器",JOptionPane.ERROR_MESSAGE);
}
}
//没有输入url , 即url为空
推荐阅读
- 开发游戏赚钱要交税嘛,开发游戏赚钱要交税嘛
- asp.net过滤html标签,net 过滤器
- 阿里云服务器如何端口,阿里云服务器如何端口访问
- 企业微信直播上课好处,用企业微信直播上课
- php采集数据函数 php 采集
- 修改Oracle表里的数据,oracle数据库修改
- 如何打开excel选项,如何打开excel选项对话框
- jquery页面刷新1次,jquery 页面刷新
- rrd数据库php re数据库