【问题标题】:How to compare 2 ints in Jtextfield如何比较 Jtextfield 中的 2 个整数
【发布时间】:2023-03-24 10:40:02
【问题描述】:

在我的 JPanel 中,我有一个要求目标的 Jtextfield,在其中我做到了 int PGoals=10; int PGoals=9; Goals.setText(Integer.toString(PGoals));

在我的另一个 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");

}

【问题讨论】:

  • 使用 JSpinner 或 JFormattedTextField 代替

标签: java swing jframe jtextfield


【解决方案1】:

你可以这样试试:

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

【讨论】:

    【解决方案2】:

    试试这个:

    if(Integer.parseInt(Goals.getText())>Integer.parseInt(Goals2.getText()))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-10
      • 2021-06-12
      • 2011-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多