anvd
anvd

Reputation: 4047

compare jTextField - java

It is possible compare the value (string) of JTextField? I have some blocks of code similar to the bellow, so my ideia is compare (!= or ==) this - pn50.setText(play4b) with, for example, pn50.setText(play5b);

I want avoid compare the string play5b or play4b, the reason is that pn50 is overwritten according to button pressed

        //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");
            }
        }
    };

thanks

Upvotes: 1

Views: 6222

Answers (1)

jzd
jzd

Reputation: 23629

The getText() method will return the text of a JTextBox. Use .equals or .compareTo to compare the Strings.

Upvotes: 2

Related Questions