2011-02-01 47 views
1

可以比较JTextField的值(字符串)吗?我有一些代码块类似波纹管,所以我的ideia比较(!=或==)这 - pn50.setText(play4b)与,例如,pn50.setText(play5b);compare jTextField - java

我想避免比较字符串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"); 
      } 
     } 
    }; 

感谢

回答

2

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

+0

谢谢,解决了,解决了pn50.getText()。equals(pn80.getText()) – anvd 2011-02-01 02:21:10