當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。