当前位置: 首页>>代码示例>>Java>>正文


Java JButton.addKeyListener方法代码示例

本文整理汇总了Java中javax.swing.JButton.addKeyListener方法的典型用法代码示例。如果您正苦于以下问题:Java JButton.addKeyListener方法的具体用法?Java JButton.addKeyListener怎么用?Java JButton.addKeyListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JButton的用法示例。


在下文中一共展示了JButton.addKeyListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import javax.swing.JButton; //导入方法依赖的package包/类
private void init(){
     
    setLayout(new BorderLayout()); //tipo de distribucion de los elementos en el frame
    
    //genero las instancias de los botones
    JButton boton1 = new JButton("boton 1");
    JButton boton2 = new JButton("boton 2");
    JButton boton3 = new JButton("boton 3");
   
    //agrego los escuchadores del Mouse
    boton1.addMouseListener(this);
    
    //agrego el evento de Action al boton2
    boton2.addActionListener(this);
    
    //agrego el escuchador del teclado del boton1
    boton3.addKeyListener(this);
    
    //agrego los botones al Frame
    add(boton1, BorderLayout.CENTER);
    add(boton2, BorderLayout.WEST);
    add(boton3, BorderLayout.EAST);
    
    //configuro la venta, en dimesion, boton de salir y lo pongo visible
    setSize(300, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    
}
 
开发者ID:jalmx89,项目名称:sota-sxt,代码行数:30,代码来源:Ventana.java

示例2: init

import javax.swing.JButton; //导入方法依赖的package包/类
private void init(){
    setTitle("Mi ventana");
    //setLayout(new FlowLayout());
    setLayout(new GridLayout(3, 4));
    
    JButton boton1 = new JButton("boton 1");
    JButton boton2 = new JButton("boton 2");
    JButton boton3 = new JButton("boton 3");
 
    boton1.addActionListener(new EventoAccion());
    boton2.addMouseListener(new EventoRaton());
    boton3.addKeyListener(new EventoTeclado());
    
    for(int x =0 ; x < 5; x++){
        add(new JLabel("etiqueta "+ (x+1)));
    }      
    
    add(new JTextField("campo de texto", 20));
    
    add(new JTextArea(5,30));
    
    add(boton1);
    add(boton2);
    add(boton3);
    
    setSize(300, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}
 
开发者ID:jalmx89,项目名称:sota-sxt,代码行数:30,代码来源:Frame.java

示例3: show

import javax.swing.JButton; //导入方法依赖的package包/类
public void show(Component parent, Runnable runOnClose) {
    this.runOnClose = runOnClose;
    key2bookmark = new HashMap<Character, BookmarkInfo>(2 * 46, 0.5f);
    BookmarkManager lockedBookmarkManager = BookmarkManager.getLocked();
    try {
        // Open projects should have their bookmarks loaded before invocation of this method
        // so that it's possible to enumerate present keys properly
        for (ProjectBookmarks projectBookmarks : lockedBookmarkManager.activeProjectBookmarks()) {
            for (FileBookmarks fileBookmarks : projectBookmarks.getFileBookmarks()) {
                for (BookmarkInfo bookmark : fileBookmarks.getBookmarks()) {
                    String key = bookmark.getKey();
                    if (key != null && key.length() > 0) {
                        key2bookmark.put(key.charAt(0), bookmark);
                    }
                }
            }
        }
    } finally {
        lockedBookmarkManager.unlock();
    }
    
    JPanel cellPanel = new JPanel();
    if (key2bookmark.size() > 0) {
        cellPanel.setLayout(new GridLayout(4, 10, 2, 2));
        addCells(cellPanel, 10 * 4, '1', '9', '0', '0', 'A', 'Z');
    } else { // No bookmarks with keys
        cellPanel.setLayout(new GridLayout(2, 1, 2, 2));
        JLabel noKeysLabel = new JLabel(NbBundle.getMessage(BookmarkKeyChooser.class, "LBL_keyChooserNoActiveKeys"), JLabel.CENTER);
        JLabel noKeysHelpLabel = new JLabel(NbBundle.getMessage(BookmarkKeyChooser.class, "LBL_keyChooserNoActiveKeysHelp"), JLabel.CENTER);
        cellPanel.add(noKeysLabel);
        cellPanel.add(noKeysHelpLabel);
    }
    cellPanel.setBorder(new EmptyBorder(4, 4, 4, 4));
    closeButton = new JButton(NbBundle.getMessage(BookmarkKeyChooser.class, "CTL_keyChooserCloseButton")); // NOI18N

    dialog = org.netbeans.editor.DialogSupport.createDialog(
            NbBundle.getMessage(BookmarkKeyChooser.class, "CTL_keyChooserTitle"), // NOI18N
            cellPanel, true, // modal
            new JButton[] { closeButton }, false, // bottom buttons
            0, // defaultIndex = 0 => allow close by Enter key too
            0, // cancelIndex
            this // ActionListener
    );
    dialog.pack();
    
    Point parentMidPoint = new Point(parent.getWidth() / 2, parent.getHeight() / 2);
    SwingUtilities.convertPointToScreen(parentMidPoint, parent);
    dialog.setBounds(
            parentMidPoint.x - dialog.getWidth() / 2,
            parentMidPoint.y - dialog.getHeight() / 2,
            dialog.getWidth(),
            dialog.getHeight()
    );
    closeButton.addKeyListener(this);
    dialog.setAlwaysOnTop(true);
    dialog.setVisible(true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:BookmarkKeyChooser.java


注:本文中的javax.swing.JButton.addKeyListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。