1 回答

TA贡献2003条经验 获得超2个赞
您有两个操作侦听器和 ,并且您只使用MyActionListenermyActionListenermyActionListener
尝试将两者统一为一,就会有这样的东西:
private class myActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println(commandLine.getText());
if (e.getSource() == about) {
System.out.println("A");
gp.about();
}
else if (e.getSource() == commandLine)
{
if (commandLine.getText().contains("penup"))
{
gp.penUp();
commandLine.setText("");
}
else if (commandLine.getText().contains("pendown"))
{
gp.penDown();
commandLine.setText("");
}
else if (commandLine.getText().contains("turnleft"))
{
gp.turnLeft();
commandLine.setText("");
}
else if (commandLine.getText().contains("turnright"))
{
gp.turnRight();
commandLine.setText("");
}
else if (commandLine.getText().contains("forward"))
{
gp.forward(50);
commandLine.setText("");
}
else if (commandLine.getText().contains("backward"))
{
gp.forward(-50);
commandLine.setText("");
}
else if (commandLine.getText().contains("black"))
{
gp.setPenColour(Color.black);
commandLine.setText("");
}
else if (commandLine.getText().contains("red"))
{
gp.setPenColour(Color.red);
commandLine.setText("");
}
else if (commandLine.getText().contains("green"))
{
gp.setPenColour(Color.green);
commandLine.setText("");
}
}
}
}
编辑:通过在爪哇语中命名修道院
类名应为名词,大小写混合,每个内部单词的第一个字母大写。尽量保持类名简单和描述性。使用整个单词 - 避免使用首字母缩略词和缩写(除非缩写比长格式更广泛地使用,例如URL或HTML)。
所以我建议你使用蜈螈MyActionListenermyActionListener
添加回答
举报