标题:怎样实现助记符功能
只看楼主
伍则帝
Rank: 3Rank: 3
来 自:四川省南充市高坪区
等 级:论坛游民
威 望:6
帖 子:100
专家分:34
注 册:2013-3-16
结帖率:84%
已结贴  问题点数:11 回复次数:1 
怎样实现助记符功能
我想实现记事本里的快捷键功能

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;



public class jishiben extends JFrame {

   
    JMenuBar jb1;
    JMenu j1,j2,j3,j4,j5;
    JMenuItem ji1,ji2,ji3,ji4,ji5,ji6,ji7;
    JMenuItem j21,j22,j23,j24,j25,j26,j27,j28,j29,j210,j211;
    JMenuItem j31,j32;
    JMenuItem j41;
    JMenuItem j51,j52;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new jishiben();
      
        
    }
   public jishiben()
   {
      jb1=new JMenuBar();
      j1=new JMenu("文件(F)");
      j2=new JMenu("编辑(E)");
      j3=new JMenu("格式(O)");
      j4=new JMenu("查看(v)");
      j5=new JMenu("帮助(H)");

      ji1=new JMenuItem("新建(N)      Ctrl+N");
      ji2=new JMenuItem("打开(O)...   Ctrl+O");
      ji3=new JMenuItem("保存(S)      Ctrl+S");
      ji4=new JMenuItem("另存为...");
      ji5=new JMenuItem("页面设置(U)... ");
      ji6=new JMenuItem("打印(P)...Ctrl+P");
      ji7=new JMenuItem("退出(X)");
      
      
      j21=new JMenuItem("撤消(U)      Ctrl+U");
      j22=new JMenuItem("剪切(T)      Ctrl+X");
      j23=new JMenuItem("复制(C)      Ctrl+C");
      j24=new JMenuItem("粘贴(P)      Ctrl+V");
      j25=new JMenuItem("删除(L)      Del");
      j26=new JMenuItem("查找(F)...   Ctrl+F");
      j27=new JMenuItem("查找下一个(N)  F3");
      j28=new JMenuItem("替换(R)      Ctrl+H");
      j29=new JMenuItem("转到(G)      Ctrl+G");
      j210=new JMenuItem("全选(A)     Ctrl+A");
      j211=new JMenuItem("时间/日期(D)  F5");
      
      j31=new JMenuItem("自动换行(默认)  Ctrl+W");
      j32=new JMenuItem("字体(F)...");
      
      j41=new JMenuItem("状态栏(S)");
      
      j51=new JMenuItem("查看帮助(H)");
      j52=new JMenuItem("关于记事本(A)");
      
      
        
       /* j1.setMnemonic('F');
        j2.setMnemonic('F');
        j3.setMnemonic('F');
        j4.setMnemonic('F');
        j5.setMnemonic('F');
        
        ji1.setMnemonic('F');
        ji2.setMnemonic('F');
        ji3.setMnemonic('F');
        ji4.setMnemonic('F');
        ji5.setMnemonic('F');
        ji6.setMnemonic('F');
        ji7.setMnemonic('F');
        
        j21.setMnemonic('F');
        j22.setMnemonic('F');
        j23.setMnemonic('F');
        j24.setMnemonic('F');
        j25.setMnemonic('F');
        j26.setMnemonic('F');
        j27.setMnemonic('F');
        j28.setMnemonic('F');
        j29.setMnemonic('F');
        j210.setMnemonic('F');
        j211.setMnemonic('F');
        j31.setMnemonic('F');*/
        j32.setMnemonic('F');
       /* j41.setMnemonic('F');
        j51.setMnemonic('F');
        j52.setMnemonic('F');*/
      
      this.setJMenuBar(jb1);
      jb1.add(j1);
      jb1.add(j2);
      jb1.add(j3);
      jb1.add(j4);
      jb1.add(j5);
      
      j1.add(ji1);j1.add(ji2);j1.add(ji3);
      j1.add(ji4);
      j1.addSeparator();
      j1.add(ji5);
      j1.add(ji6);
      j1.addSeparator();
      j1.add(ji7);
      
      j2.add(j21);
      j2.addSeparator();
      j2.add(j22);      
      j2.add(j23);
      j2.add(j24);
      j2.add(j25);
      j2.addSeparator();
      j2.add(j26);
      j2.add(j27);
      j2.add(j28);
      j2.add(j29);
      j2.addSeparator();
      j2.add(j210);
      j2.add(j211);

      j3.add(j31);
      j3.add(j32);
      
      j4.add(j41);
      
      j5.add(j51);
      j5.add(j52);
      
      
      
      Mnemonici mmm=new Mnemonici();//先初始化动作事件类
      ji7.addActionListener(mmm);//再添加事件监听器
      
      
      this.addWindowListener(new mm());
      this.setTitle("记事本");
      this.setSize(666,555);
      this.setVisible(true);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
  
   class Mnemonici implements ActionListener{//创建事件类

         
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            if(e.getActionCommand().equals("退出(X)"))
                System.exit(0);
        }   
      
   }

}

class mm implements WindowListener
{

    public void windowActivated(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    public void windowClosed(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    public void windowClosing(WindowEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("关闭窗口");
        System.exit(0);//非0表示非正常退出程序
    }

    public void windowDeactivated(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    public void windowDeiconified(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    public void windowIconified(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    public void windowOpened(WindowEvent arg0) {
        // TODO Auto-generated method stub
        
    }
 
}
















搜索更多相关主题的帖子: 记事本 public import 快捷键 
2013-05-22 22:18
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
得分:11 
助记符到底是个什么功能呢,你说清楚点呀!

旨在提高编程水平,学有所用,学有所成,学有所为。
2013-05-23 22:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-407780-1-1.html




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

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