當前位置: 首頁>>代碼示例>>Java>>正文


Java JButton.getText方法代碼示例

本文整理匯總了Java中javax.swing.JButton.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java JButton.getText方法的具體用法?Java JButton.getText怎麽用?Java JButton.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JButton的用法示例。


在下文中一共展示了JButton.getText方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import javax.swing.JButton; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent event) {
    JButton btn = (JButton) event.getSource();
    String pressedKey = (String) btn.getClientProperty("key");

    if (CAPS.equals(pressedKey)) {
        for (JButton button : buttons) {
            String text = button.getText();
            text = caps ? text.toLowerCase() : text.toUpperCase();
            button.setText(text);
        }
        caps = !caps;
        return;
    }

    if (BACKSPACE.equals(pressedKey)) {
        if (password.length() > 0) {
            password = password.substring(0, password.length() - 1);
        }
    } else if (CLEAR.equals(pressedKey)) {
        password = "";
    } else {
        password += btn.getText();
    }
    passwordField.setText(password);
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:27,代碼來源:SecurePasswordInputPanel.java

示例2: actionPerformed

import javax.swing.JButton; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(final ActionEvent e) {
    final Object source = e.getSource();

    if (!(source instanceof JButton)) {
        return;
    }

    // only dealing with the toggleButtons
    final JButton btn = (JButton) source;

    m_selectedItem = btn.getText(); // future selection

    if (m_selectedItem.equals(m_defaultText)) {
        m_selectedItem = ClassModel.NO_CLASS;
    }

    fireActionEvent(new ActionEvent(btn, (int) (Math.random() * 12312),
            m_actionCommand));
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:24,代碼來源:ButtonList.java

示例3: initUndoRedoButton

import javax.swing.JButton; //導入方法依賴的package包/類
/**
 * Initializes undo/redo toolbar button.
 * 
 * @param button button to initialize.
 * @return initialized button.
 */
private JButton initUndoRedoButton(JButton button) {
    String text = (String)button.getAction().getValue(Action.NAME);
    Mnemonics.setLocalizedText(button, text);
    text = button.getText();
    button.setText(null);
    button.setToolTipText(text);
    button.setFocusPainted(false);
    return button;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:GridDesigner.java

示例4: addNumberButtons

import javax.swing.JButton; //導入方法依賴的package包/類
/**
 * Adds calculator number buttons on given panel.
 * 
 * @param p
 *            Panel.
 */
private void addNumberButtons(JPanel p) {
    JButton[] buttons = new JButton[10];

    ActionListener action = e -> {
        JButton button = (JButton) e.getSource();
        String number = button.getText();
        String text = display.getText();
        if (text.equals("0")) {
            display.setText("");
        }
        if (resetDisplay) {
            display.setText("");
        }
        display.setText(display.getText() + number);
        resetDisplay = false;
    };

    for (int i = 0; i < buttons.length; i++) {
        buttons[i] = createButton(Integer.toString(i));
        buttons[i].setForeground(Color.red);
        buttons[i].addActionListener(action);
    }
    p.add(buttons[0], new RCPosition(5, 3));
    for (int i = 0; i < 3; i++) {
        p.add(buttons[i + 1], new RCPosition(4, 3 + i));
    }
    for (int i = 3; i < 6; i++) {
        p.add(buttons[i + 1], new RCPosition(3, i));
    }
    for (int i = 6; i < 9; i++) {
        p.add(buttons[i + 1], new RCPosition(2, i - 3));
    }
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:40,代碼來源:Calculator.java

示例5: textForKey

import javax.swing.JButton; //導入方法依賴的package包/類
static String textForKey (String key) {
    JButton jb = new JButton ();
    Mnemonics.setLocalizedText (jb, NbBundle.getMessage (UnitTab.class, key));
    return jb.getText ();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:6,代碼來源:UnitTab.java

示例6: addFunctionButtons

import javax.swing.JButton; //導入方法依賴的package包/類
/**
 * Adds calculator function buttons on given panel.
 * 
 * @param p
 *            Panel.
 */
private void addFunctionButtons(JPanel p) {
    ActionListener execOperation = e -> {
        JButton button = (JButton) e.getSource();
        String buttonName = button.getText();
        UnaryOperation operation = getUnaryOperation(buttonName);

        double value = Double.parseDouble(display.getText());
        double result = executeUnaryOperation(operation, value);
        display.setText(Double.toString(result));
    };

    ActionListener xPownOp = e -> {
        executeBinaryOperation(new PownOperation());
    };

    JButton invx = createButton("1/x");
    invx.addActionListener(execOperation);

    JButton xpown = createButton("x^n");
    xpown.addActionListener(xPownOp);

    JButton sine = createButton("sin");
    sine.addActionListener(execOperation);

    JButton log = createButton("log");
    log.addActionListener(execOperation);

    JButton cosine = createButton("cos");
    cosine.addActionListener(execOperation);

    JButton ln = createButton("ln");
    ln.addActionListener(execOperation);

    JButton tan = createButton("tan");
    tan.addActionListener(execOperation);

    JButton ctg = createButton("ctg");
    ctg.addActionListener(execOperation);

    p.add(invx, new RCPosition(2, 1));
    p.add(sine, new RCPosition(2, 2));
    p.add(log, new RCPosition(3, 1));
    p.add(cosine, new RCPosition(3, 2));
    p.add(ln, new RCPosition(4, 1));
    p.add(tan, new RCPosition(4, 2));
    p.add(xpown, new RCPosition(5, 1));
    p.add(ctg, new RCPosition(5, 2));
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:55,代碼來源:Calculator.java


注:本文中的javax.swing.JButton.getText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。