【发布时间】:2014-02-12 20:25:30
【问题描述】:
在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);
}
}
}
【问题讨论】:
标签: java input awt keypress stringreader