当前位置: 首页>>代码示例>>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;未经允许,请勿转载。