zoukankan      html  css  js  c++  java
  • Exec 66 快捷键设置

    import javax.swing.*;
    
    import java.awt.event.*;
    import java.awt.*;
    public class Exec66 extends JFrame implements ActionListener{
        JTextField text;
        static int i=0;
        public Exec66() {
            this.setTitle("Test");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setBounds(100, 100, 200, 300);
            this.setLocationRelativeTo(null);
            
            JMenuBar bar = new JMenuBar();
            
            JMenu file = new JMenu("文件");
            JMenu edit = new JMenu("编辑");
            JMenu help = new JMenu("帮助");
            
            JMenuItem f1 = new JMenuItem("OPEN");
            JMenuItem f2 = new JMenuItem("保存");
            JMenuItem f3 = new JMenuItem("退出");
            JMenuItem e1 = new JMenuItem("复制");
            JMenuItem e2 = new JMenuItem("粘贴");
            JMenuItem e3 = new JMenuItem("全选");
            JMenuItem h1 = new JMenuItem("帮助");
            JMenuItem h2 = new JMenuItem("关于");
            
            f1.setMnemonic('O');
            f1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
        
            f1.addActionListener(this);
            f2.addActionListener(this);
            f3.addActionListener(this);
            e1.addActionListener(this);
            e2.addActionListener(this);
            e3.addActionListener(this);
            h1.addActionListener(this);
            h2.addActionListener(this);
            
            
            this.setJMenuBar(bar);
            bar.add(file);
            bar.add(edit);
            bar.add(help);
            
            file.add(f1);file.add(f2);file.add(f3);
            edit.add(e1);edit.add(e2);edit.add(e3);
            help.add(h1);help.add(h2);
            
            text = new JTextField(10);
            
            add(text);
            
            this.setVisible(true);
            
            JButton bt = new JButton("BUTTON");
            bt.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e ) {
                    text.setText("BUTTON "+(i++));
                }
            });
            bt.setMnemonic(KeyEvent.VK_O);
            add(bt,BorderLayout.SOUTH);
        }
    
        
        public static void main(String[] args) {
             new Exec66();
    
        }
        public void actionPerformed(ActionEvent e) {
            JMenuItem item = (JMenuItem)(e.getSource());
            if (item.getActionCommand().equals("退出")) System.exit(1);
            else text.setText(item.getActionCommand());
        }
    
    }
  • 相关阅读:
    JavaScript随机数
    javascript函数
    hdu 4122(RMQ)2011福州现场赛B题
    hdu 4119 (模拟+字符串)成都现场赛I题
    hdu 4118(树形dp) 成都现场赛H题
    hdu 4115(2-SAT) 2011 成都现场赛E题
    Codeforces Round #237 (Div. 2) 解题报告
    Codeforces Round #234 (Div. 2) 解题报告
    uva 1411(二分图最大权匹配)
    uva 11383(二分图最大权匹配)
  • 原文地址:https://www.cnblogs.com/qqjue/p/2627665.html
Copyright © 2011-2022 走看看