【问题标题】:compare jTextField - java比较 jTextField - java
【发布时间】:2011-02-01 02:05:35
【问题描述】:

可以比较 JTextField 的值(字符串)吗?我有一些类似于下面的代码块,所以我的想法是比较(!= 或 ==)这个 - pn50.setText(play4b) 与,例如,pn50.setText(play5b);

我想避免比较字符串play5b或play4b,原因是pn50被按下按钮覆盖

        //card2
    ActionListener two = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (gr.getCounter1() < 1) {
                gr.setCounter1(gr.getCounter1() + 2);
                test1.setIcon(play1b);
                pn1.setText("Value of card: " + play2b);
                pn5.setText(play3b);
                pn50.setText(play4b);
                arraybtn[2].setText("no Card");
                arraybtn[2].setBackground(Color.lightGray);
            } else {
                pn5.setText("Only one Card");
            }
        }
    };

谢谢

【问题讨论】:

    标签: java string swing compare jtextfield


    【解决方案1】:

    getText() 方法将返回 JTextBox 的文本。使用.equals 或.compareTo 比较字符串。

    【讨论】:

    • 谢谢,解决了,解决了 pn50.getText().equals (pn80.getText())
    猜你喜欢
    • 2012-01-15
    • 2023-03-24
    • 2022-12-05
    • 2011-09-10
    • 2013-12-08
    • 2016-10-22
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多