因此,我尝试起草一种方法,该方法需要一个字符串和一个文本,理论上会逐渐将字符串输出到该文本,就像有人正在输入它一样。然而,所发生的只是程序暂停不同的时间(由于每次添加字母之间的暂停使用了随机值),然后显示整个字符串。
public void keyboard(String string, Text tBox, Stage stage, Scene scene) {
//generates a random number which later determines the amount of time the game pauses before
//adding the next character
Random number = new Random();
//stores the length of a string (as an integer)
int stringLen = string.length();
//gets increased later
int counter = 0;
char[] chars = new char[(stringLen+1)];
string.getChars(0, stringLen, chars, 0);
String returnVal = "";
do {
returnVal += Character.toString(chars[counter]);
counter += 1;
tBox.setText(returnVal);
pause((number.nextInt(3) + …Run Code Online (Sandbox Code Playgroud)