| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 586 人关注过本帖
标题:关于计算器事件的监听问题求指教!!
取消只看楼主 加入收藏
cool霸气:
Rank: 1
来 自:成都
等 级:新手上路
帖 子:7
专家分:1
注 册:2014-3-14
结帖率:100%
收藏
 问题点数:0 回复次数:0 
关于计算器事件的监听问题求指教!!
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 自动生成的方法存根
        
            
    }
}
//对于“查看”,“编辑”,“帮助”就不需要监听!!谢谢!!
搜索更多相关主题的帖子: 计算器 package public import 标准型 
2014-04-21 19:23
快速回复:关于计算器事件的监听问题求指教!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047320 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved