以下程序编译没问题,可运行却没结果,请大侠帮忙?(问题到底出在哪儿?)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class MenuDemo extends JFrame implements ActionListener {
JMenuBar myMenuBar=new JMenuBar();
JMenu menu1,menu2,menu3,menu4,menu5;
JMenuItem menuItem11,menuItem12,menuItem13,menuItem14;
JCheckBoxMenuItem menuItem21,menuItem22;
JButton b1,b2,b3;
MenuDemo() {
getContentPane().setLayout(new BorderLayout()); //设置边界布局
createMenu(); //创建菜单
setTitle("菜单演示");
setSize(400,400);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { //关闭窗口
dispose();
System.exit(0);
}
});
}
void createMenu() {
menu1=new JMenu("系统管理(S)");
menu1.setMnemonic('S'); //设置热键
menu2=new JMenu("视图(V)");
menu2.setMnemonic('V'); //设置热键
menuItem11=new JMenuItem("用户管理(U)",
new ImageIcon("C:\\Documents and Settings\\Administrator\\My Documents\\Tencent Files\\453737451\\Image\\$MTFLH}6D44JDMK{1L8P)F2.GIF"));
//建立菜单项的同时加入图标
menuItem11.setMnemonic('U');
menuItem11.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,java.awt.event.InputEvent.CTRL_MASK));
menuItem12=new JMenuItem("密码设置(P)");
menuItem12.setIcon(new ImageIcon("C:\\Documents and Settings\\Administrator\\My Documents\\Tencent Files\\453737451\\Image\\%I@9572$H(`X2@`I}}EY3I9.gif"));
//建立完菜单项后设置图标
menuItem12.setMnemonic('P');
menuItem12.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,java.awt.event.InputEvent.CTRL_MASK));
menuItem13=new JMenuItem("退出(E)");
menu1.setMnemonic('E');
menu1.add(menuItem11);
menu1.add(menuItem12);
menu1.addSeparator(); //添加分隔条
menu1.add(menuItem13);
menuItem21=new JCheckBoxMenuItem("显示工具栏",true); //复选菜单项
menuItem22=new JCheckBoxMenuItem("显示提示文字",true);
menu2.add(menuItem21);
menu2.add(menuItem22);
myMenuBar.add(menu1);
myMenuBar.add(menu2);
setJMenuBar(myMenuBar); //将菜单添加到窗体
setIconImage(new ImageIcon("C:\\Documents and Settings\\Administrator\\My Documents\\Tencent Files\\453737451\\Image\\%I@9572$H(`X2@`I}}EY3I9.gif").getImage()); //设置窗口图标
menuItem11.addActionListener(this);
menuItem12.addActionListener(this);
menuItem13.addActionListener(this);
menuItem21.addActionListener(this);
menuItem22.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==menuItem11){
; //此处调用用户管理程序
}
else if(e.getSource()==menuItem12) {
; //此处调用密码设置程序
}
else if(e.getSource()==menuItem13) {
dispose();
System.exit(0);
}
else if(e.getSource()==menuItem21) {
if(menuItem21.getState()) {
; //使用工具栏显示 tb.setVisible(true);
}
else {
; //隐藏工具栏 tb.setVisible(false);
this.invalidate();
}
}
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
Font myFont=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()) {
Object myKey=keys.nextElement();
if(UIManager.get(myKey) instanceof Font) UIManager.put(myKey,myFont);
}
MenuDemo menuDemo=new MenuDemo();
}
}