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
添加回答
舉報