Results 1 to 5 of 5
Thread: Java 2D game - creating menu
- 11-17-2012, 11:47 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Java 2D game - creating menu
I am trying to create Menu to my 2D game in Java (Sokoban). But the game is not responding to pressed keyes. Menu is working, but when I choose new game in menu (by pressing Enter), game starts but it does not react to pressed keyes. But, when I remove menu, game is responding to pressed keys ... but when there is also menu, it is not responding. How to solve this problem ?
Here is Sokoban class:
Java Code:public final class Sokoban extends JFrame { private static Menu menu; private static Board board; private static JFrame myFrame; private static Action enterAction; public Sokoban() { InitUI(); } public void InitUI() { myFrame = new JFrame(); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.setSize(800,600); myFrame.setLocationRelativeTo(null); myFrame.setTitle("Labyrint"); myFrame.setResizable(false); board = new Board(); menu = new Menu(); myFrame.add(menu); enterAction = new EnterAction(); menu.getInputMap().put( KeyStroke.getKeyStroke( "ENTER" ), "doEnterAction" ); menu.getActionMap().put( "doEnterAction", enterAction ); myFrame.setVisible(true); } static class EnterAction extends AbstractAction { public void actionPerformed( ActionEvent tf ) { System.out.println( "The Enter key has been pressed." ); menu.setVisible(false); menu = null; myFrame.add(board); } // end method actionPerformed() } // end class EnterAction public static void main(String[] args) { Sokoban sokoban = new Sokoban(); } }
Java Code:public Board() { rightAction = new RightAction(); getInputMap().put( KeyStroke.getKeyStroke( "RIGHT" ), "doRightAction" ); getActionMap().put( "doRightAction", rightAction ); initWorld(); } static class RightAction extends AbstractAction { public void actionPerformed( ActionEvent tf ) { System.out.println( "The Right key has been pressed." ); } }
- 11-17-2012, 12:12 PM #2
Re: Java 2D game - creating menu
Cross posted
Keylistener - not responding (creating menu) | DaniWeb
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 11-17-2012, 12:27 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: Java 2D game - creating menu
it is my topic ... but it is not solved there and I need to solve this as soon as possible :)
- 11-17-2012, 10:09 PM #4
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: Java 2D game - creating menu
delete this please, it is solved
- 11-18-2012, 01:29 PM #5
Similar Threads
-
Creating a game with java.
By GameCoderKata in forum New To JavaReplies: 1Last Post: 12-19-2011, 01:17 AM -
Creating a menu in a basic 2d game
By ResidentBiscuit in forum New To JavaReplies: 5Last Post: 11-30-2011, 04:18 AM -
Creating a Card Game in Java
By Natrix in forum New To JavaReplies: 1Last Post: 05-05-2009, 05:55 PM -
Need Help Creating a Java Drop-Down/ Collapsing Menu
By rudbls in forum New To JavaReplies: 3Last Post: 12-15-2007, 11:19 PM
Bookmarks