Results 1 to 2 of 2
- 05-04-2012, 02:46 PM #1
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
Assistance on transforming a KeyListener to a KeyBinding?
These are excerpts from the source code I am working with:
Java Code:public Pokemon(){ currentBGM = title; currentBGM.start(); menu = new MenuScene(this); col.loadClip("Audio/SE/Collision.wav", "Collision", 1); col.loadClip("Audio/SE/Select.wav", "Select", 1); col.loadClip("Audio/SE/Menu.wav", "Menu", 1); col.loadClip("Audio/SE/Damage.wav", "Damage", 1); setBackground(Color.BLACK); setPreferredSize(new Dimension(480,320)); addKeyListener(this); gameTimer = new javax.swing.Timer(350, this); gameTimer.start(); }The Key Listener in this is faulty and I know that it's the reason my program isn't working correctly; when at the title screen of the program, the enter key is almost never recognized and as such, there's no way for the player to continue to the game. I also know that I need to replace the Key Listener with a Key Binding. The problem is that I absolutely stink at following Java tutorials and I don't know where to start. I've tried futzing around with various ways of writing the code like some of the tutorials I've looked at suggested, but I only exacerbated my own problem.Java Code:@Override public void keyPressed(KeyEvent e) { setFocusable(true); int keyCode = e.getKeyCode(); if (atTitle == true) { if (keyCode == KeyEvent.VK_ENTER) { gameTimer.setDelay(1); atTitle = false; currentBGM.stop(); currentBGM = continuebgm; currentBGM.start(); atContinueScreen = true; } }
Can anybody either walk me through this transition or tell me how I should implement a Key Binding in this situation?
- 05-04-2012, 03:25 PM #2
Similar Threads
-
KeyBinding not responsive
By Germoose in forum New To JavaReplies: 3Last Post: 04-21-2012, 11:10 PM -
Keybinding
By mine0926 in forum New To JavaReplies: 4Last Post: 01-11-2011, 05:33 AM -
KeyBinding Help
By Lil_Aziz1 in forum New To JavaReplies: 12Last Post: 07-27-2010, 03:58 PM -
Transforming XML to HTML
By Java Tip in forum Java TipReplies: 0Last Post: 03-01-2008, 10:06 PM -
transforming double to int
By AlejandroPenton in forum New To JavaReplies: 2Last Post: 12-11-2007, 01:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks