当前位置: 代码迷 >> J2SE >> 新人一个给MenuItem添加监听器的有关问题!
  详细解决方案

新人一个给MenuItem添加监听器的有关问题!

热度:10270   发布时间:2013-02-25 00:00:00.0
新人求助一个给MenuItem添加监听器的问题!!!!
我的代码如下(删去无关的部分了,有几个事件处理程序没有写,但是写了的那几个不能执行),红色部分为问题所讨论的内容~~~~~,最后打开程序,点相应的菜单,木有反应,这是怎么回事???希望牛人解答一下~~~

package gui;
import gui.HistoryList;
import gui.PopupDialog;

import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionListener;
public class MiniIE extends JFrame implements HyperlinkListener {
private JPanel mianban;
private JTextField kuang;
private JToolBar bar;
private JLabel jisu;
private JButton zhuandao;
private JButton houtui;
private JButton qianjin;
private JButton shuaxin;
private JButton lingcunwei;
private JMenuBar menubar;
private JTabbedPane tabbedPane;
private String sURL;
private HistoryList hl=new HistoryList(); 
private JEditorPane je=new JEditorPane();
private JScrollPane jsp;
private int tabCounter = 1;
private ImageIcon ii = new ImageIcon("close.jpg");
private Dimension iisize = new Dimension(ii.getIconWidth(),ii.getIconHeight());
private MiniIE chuangkou;
private ClientNetworkTools cnt = new ClientNetworkTools();
private ClientFileTools cft = new ClientFileTools();
private JLabel lblStatus;
public MiniIE(String s){
super(s);
}
public MiniIE(){
super();
final MiniIE chuangkou=new MiniIE("我爱(5i)浏览器");
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
chuangkou.setBounds(d.width/2-500,0,1000,700); 

mianban=new JPanel();
mianban.setLayout(new BorderLayout());
mianban.setBorder(new EmptyBorder(5,5,5,5));

menubar=new JMenuBar();
JMenu menu1=new JMenu("文件");
JMenu menu2=new JMenu("工具");
JMenu menu3=new JMenu("帮助");
JMenuItem menuitem2=new JMenuItem("新建标签页");
JMenuItem menuitem3=new JMenuItem("保存网页");
JMenuItem menuitem4=new JMenuItem("退出");
JMenuItem menuitem5=new JMenuItem("历史");
JMenuItem menuitem6=new JMenuItem("清空历史记录");
JMenuItem menuitem7=new JMenuItem("帮助");
menu1.add(menuitem2);
menu1.add(menuitem3);
menu1.add(menuitem4);
menu2.add(menuitem5);
menu2.add(menuitem6);
menu3.add(menuitem7);
menubar.add(menu1);
menubar.add(menu2);
menubar.add(menu3);
chuangkou.add(menubar);
chuangkou.setJMenuBar(menubar);

menuitem2.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
chuangkou.addDefaultTab();
}
});
menuitem3.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){

}
});
menuitem4.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
System.exit(0);
}
});
menuitem5.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){

}
});
menuitem6.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){

}
});
menuitem7.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
new PopupDialog("帮助","你现在看到的是我爱(5i)浏览器1.0正式版!"+"\n"+"1.点击HOME进入主页。"+
"\n"+"2.点击相应按钮执行相应功能。"+"3.网址前加http://可以浏览因特网资源,不加则浏览本地资源。");
}
}); kuang.addActionListener(new kuangActionlistener());
zhuandao.addActionListener(new zhuandaoActionlistener());
houtui.addActionListener(new houtuiActionlistener());
qianjin.addActionListener(new qianjinActionlistener());
shuaxin.addActionListener(new shuaxinActionlistener());
lingcunwei.addActionListener(new lingcunweiActionlistener());
je.addHyperlinkListener(this);

bar.add(houtui);
bar.add(qianjin);