将Int值输入文本字段

问题描述

在JavaFX中,我有一个名为“ randomIntegerField”的TextField,当我按下按钮时,我需要使用方法返回的整数值自动填充此JavaFX JavaFX文本字段。

这是返回int值的方法

private int randomNum(){
     Random random = new Random();
     int integerIntered = Integer.parseInt(numberField.getText()); 
     return   random.nextInt(integerIntered - 0 + 1) + 0; 
}

这是按钮

 bntGo.setText("Go");
    
    bntGo.setonAction(e -> {
       randomIntegerField = String.valueOf(randomNum()); // The error i get is String can not converted into TextField. 
    });

请帮助我

解决方法

例如,您需要设置public class Receipt { public static void main(String[] args) { int subTotal = 38 + 40 + 30; double tax = .08 * subTotal; double tip = .15 * subTotal; double total = subTotal + tax + tip; printAmount("Subtotal:",subTotal); printAmount("Tax:",tax); printAmount("Tip:",tip); printAmount("Total:",total); } private static void printAmount(String label,double value) { System.out.println(label); System.out.println(value); } } 的{​​{3}}(我假设是randomIntegerField)...

TextField