This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。
7年前关闭。
我这里有一个课程,旨在在按下键时在窗口中移动枪支。但是,从类型引用非静态方法时出现错误。这是两个部分。错误出现在两行“ if(k == .....”)处。
您的
7年前关闭。
我这里有一个课程,旨在在按下键时在窗口中移动枪支。但是,从类型引用非静态方法时出现错误。这是两个部分。错误出现在两行“ 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;
}
}
最佳答案
哪个Gun
?您需要一个实例,即对由此创建的Gun
对象的引用:
Gun gun = new Gun(...);
gun.move(amount);
您的
Keyboard
对象将必须以某种方式引用此Gun
对象,或者可能是某个知道您要移动Gun
的管理器类型的对象。10-06 03:47