我在这里有一门课,目的是在按下键时在窗口中移动枪。但是,我收到关于从类型中引用非静态方法的错误。这是两个部分。错误出现在两个“if (k == .....”行。
private class Keyboard extends KeyAdapter {
public void keyPressed (KeyEvent e) {
int k = e.getKeyCode();
if (k == 39) {Gun.move(10);}
if (k == 37) {Gun.move(-10);}
}
}
public class Gun {
private Color color;
private int A,B,C,D;
private int E,F,G,H;
public Gun (Color c) {
color = c;
A = 375;
B = 550;
C = 50;
D = 10;
E = 395;
F = 540;
G = 10;
H = 10;
}
public void move(int xAmount){
A = A + xAmount;
E = E + xAmount;
}
}