-1

This bit of code calls two separate games when the respective key is pressed. the windows appear, but the user cannot play the game. The screen is unresponsive. How do i fix this?

public void keyPressed(KeyEvent e)
    {

         if(e.getKeyCode() == KeyEvent.VK_1)
           {
              //calls tic tac toe game, and point counter
              TicTacToe tic = new TicTacToe();
              TicTacToeDriver.main(null);
              PointCounter();
            }

          else if(e.getKeyCode() == KeyEvent.VK_2)
           {
              //calls hanman game, and point counter
              Hangman hang = new Hangman();
              HangmanDriver.main(null);
              PointCounter();
           }
       }
Imani Davis
  • 29
  • 1
  • 2
  • this code doesn't help at all. It's extremely incomplete. A few general comments: you don't need to create an instance of a Class to access static methods. How do the subprograms even access the frame? I can't see any code sending a reference to the frame to the subroutines. –  May 31 '16 at 00:38
  • what other parts of the code would you need to see? I made this code with two other individuals. It is not methods being called, but two separate drivers. – Imani Davis May 31 '16 at 00:53
  • Especially if the other two routines are individuals, the most likely reason they are unresponsive is the implementation of the other windows. Btw: are there any errors displayed in the console?? –  May 31 '16 at 10:11

1 Answers1

0

An easier way to do what you want would be this, I think:

public void keyPressed(KeyEvent e) {

         if(e.getKeyCode() == KeyEvent.VK_1) {
              //calls tic tac toe game, and point counter
              TicTacToeDriver.main(args);
              PointCounter();
            }

          else if(e.getKeyCode() == KeyEvent.VK_2) {
              //calls hanman game, and point counter
              HangmanDriver.main(args);
              PointCounter();
           }
       }

Let me know if this works.

jzbakos
  • 285
  • 1
  • 3
  • 12
  • an error popped up "cannot find symbol - variable args" – Imani Davis May 31 '16 at 01:13
  • Try adding this outside of the main class: private String[] args; Let me know if that works! – jzbakos May 31 '16 at 01:29
  • That's an answer to the question. You merely added a parameter - that apparently isn't required - to the driver-call and removed the useless instance-creations. –  May 31 '16 at 10:14