在java中,我正在制作一个应用程序,当它被激活时(如果wantCommand = true),它将读取您按下的任何键,并将其添加到字符串中,然后使用Java.awt.Graphics,它将字符串绘制到屏幕...有人可以帮我编写代码以获取您输入的字符串(如果您弄乱了您输入的内容,也可能删除)这是我到目前为止的内容:
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class slashCommand {
public static boolean wantCommand = false;
public static String commandLine = "kill";
public static String getText () {
//get the string in a for loop or something maybe
return commandLine;
}
public static void render(Graphics g) {
if (wantCommand) {
g.setColor(new Color(0, 0, 0, 130));
g.fillRect(Inventory.inv_bag[0].x - 100, Inventory.inv_bag[0].y + 116, Component.size.width, 10);
g.setColor(new Color(255, 255, 255));
g.setFont(new Font("Arial", Font.PLAIN, 10));
g.drawString("/ " + commandLine, Inventory.inv_bag[0].x - 69, Inventory.inv_bag[0].y + 125);
}
}
}