0

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?

2
  • Please follow Java naming conventions. It should be repeat and location (not capitalized). Commented Sep 28, 2013 at 2:11
  • you can't call a class , you can create a new object, or you can call a static method inside the class. exactly what are you trying to do ? Commented Sep 28, 2013 at 2:29

1 Answer 1

1

-> 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();

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but how would I do that?
just replace wasd() by new WASd() ??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.