Reputation: 129
so I would like to run the class "WASD" which I have in my code:
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
}
}
}
The arrow points to syntax error in my code, apparently when I type in WASD(); it want there to be a method called WASD, what would I need to do for it to look for the CLASS WASD?
Upvotes: 0
Views: 262
Reputation: 69
-> WASD();
this is a call to a function.if you want to call the class WASD from MOVEASD then use the new operator..
new WASD();
Upvotes: 1