package swing;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MenuTest implements ActionListener{
public MenuTest(){
JMenuBar menubar= new JMenuBar();
JMenu menu=new JMenu("查看(V)");
JMenuItem jmenuitem = new JMenuItem("科学型(T)");
JMenuItem jmenu = new JMenuItem("标准型(S)");
JMenuItem jmenu1 = new JMenuItem("分组型(w)");
menubar.add(menu);
menu.add(jmenu);
menu.add(jmenuitem);
menu.add(jmenu1);
menu=new JMenu("编辑(E)");
JMenuItem j1 = new JMenuItem("复制(c) Ctrl+c");
JMenuItem j2 = new JMenuItem("粘贴(p) Ctrl+v");
menu.add(j1);
menu.add(j2);
menubar.add(menu);
menu=new JMenu("帮助(H)");
menubar.add(menu);
TextField text = new TextField();
JPanel panel1 = new JPanel(new GridLayout(1,1,2,2));
panel1.add(text);
Button l1 = new Button("MC");
l1.addActionListener(this);
Button l2 = new Button("MR");
l2.addActionListener(this);
Button l3 = new Button("MS");
l3.addActionListener(this);
Button l4 = new Button("M+");
l4.addActionListener(this);
Button l5 = new Button("M-") ;
l5.addActionListener(this);
Button l6 = new Button(" 1 ");
l6.addActionListener(this);
Button l7 = new Button(" 2 ");
l7.addActionListener(this);
Button l8 = new Button(" 3 ");
l8.addActionListener(this);
Button l9 = new Button(" 4 ");
l9.addActionListener(this);
Button l_ = new Button(" + ");
l_.addActionListener(this);
Button l_0 = new Button(" 5 ");
l_0.addActionListener(this);
Button l_1 = new Button(" 6 ");
l_1.addActionListener(this);
Button l_2 = new Button(" 7 ");
l_2.addActionListener(this);
Button l_3 = new Button(" 8 ");
l_3.addActionListener(this);
Button l_4 = new Button(" - ");
l_4.addActionListener(this);
Button l_5 = new Button(" 9 ");
l_5.addActionListener(this);
Button l_6 = new Button(" . ");
l_6.addActionListener(this);
Button l_7 = new Button(" 0 ");
l_7.addActionListener(this);
Button l_a = new Button(" = ");
l_a.addActionListener(this);
Button l_8 = new Button(" * ");
l_8.addActionListener(this);
Button l_9 = new Button(" / ");
l_9.addActionListener(this);
Button l_z = new Button(" -/+");
l_z.addActionListener(this);
Button l_x = new Button(" CE ");
l_x.addActionListener(this);
Button l_c = new Button(" % ");
l_c.addActionListener(this);
Button l_d = new Button("Ba");
l_d.addActionListener(this);
JPanel panel = new JPanel(new GridLayout(5,7,2,2));
panel.add(l1);
panel.add(l2); panel.add(l3);
panel.add(l4); panel.add(l5);
panel.add(l6); panel.add(l7);
panel.add(l8); panel.add(l9);
panel.add(l_); panel.add(l_0);
panel.add(l_1); panel.add(l_2);
panel.add(l_3); panel.add(l_4);
panel.add(l_5); panel.add(l_6);
panel.add(l_7); panel.add(l_a);
panel.add(l_8); panel.add(l_9);
panel.add(l_c); panel.add(l_z);
panel.add(l_d);panel.add(l_x);
JFrame jf=new JFrame("计算器");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(panel1,BorderLayout.NORTH);
jf.add(panel, BorderLayout.CENTER);
jf.setJMenuBar(menubar);
jf.setSize(200, 250);
jf.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MenuTest();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
}
}
//对于“查看”,“编辑”,“帮助”就不需要监听!!谢谢!!