所以我想运行我的代码中的“WASD”类:
public class MoveWASD extends JFrame
{
boolean Repeat = true;
int Location[] = {40, 40};
public static void main (String args[])
{
new MoveWASD();
}
public MoveWASD()
{
super("Use-WASD-to-Move");
setSize(800, 450);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
while(Repeat)
{
--> WASD(); }
}
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.fillRect(0, 0, 800, 450);
g.setColor(Color.BLUE);
g.fillRect(Location[0], Location[1], 20, 20);
}
public class WASD implements KeyListener
{
public void keyPressed(KeyEvent event)
{
if(event.getKeyChar() == 'w')
{
Location[1]--;
}
else if(event.getKeyChar() == 'd')
{
Location[0]++;
}
else if(event.getKeyChar() == 's')
{
Location[1]++;
}
else if (event.getKeyChar() == 'a')
{
Location[0]--;
}
else
{
Location[0] = Location[0];
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
}
箭头指向我的代码中的语法错误,显然是当我输入 WASD(); 它希望有一个称为 WASD 的方法,我需要做什么才能找到 CLASS WASD?