2015-11-02 25 views
1

比較2個整數。在我的JPanel,我有一個JTextField呼籲的目標,並在其中,我沒有 int PGoals=10; int PGoals=9; Goals.setText(Integer.toString(PGoals));如何在JTextField中

在我的其他JTextField中,我做了

Goals2.setText(Integer.toString(PGoals2)); 

我想做一個if語句

if(PGoals>Pgoals2){ 

JTextfield.setText("Left Player has more goals"); }

else { JTextfield.setText("Right player has more goals");

}

+0

改爲使用JSpinner或JFormattedTextField – MadProgrammer

回答

0

你可以嘗試這樣的:

if(Integer.parseInt(PGoals) > Integer.parseInt(Pgoals2)) 
0

試試這個:

如果(Integer.parseIn t(Goals.getText())> Integer.parseInt(Goals2.getText()))