Results 1 to 2 of 2
  1. #1
    OurOhnlyHope is offline Member
    Join Date
    May 2012
    Rep Power

    Default 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;
    		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);
    	    setPreferredSize(new Dimension(480,320));
    		gameTimer = new javax.swing.Timer(350, this);
    Java Code:
         public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();
         	if (atTitle == true) {
         		if (keyCode == KeyEvent.VK_ENTER) {
    	        	atTitle = false;
    				currentBGM = continuebgm;
    	        	atContinueScreen = true;
    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.

    Can anybody either walk me through this transition or tell me how I should implement a Key Binding in this situation?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Assistance on transforming a KeyListener to a KeyBinding?

    Moved from New to Java.

    The Oracle tutorial on Key Bindings *does* provide a step-by-step. Which part of it are you stuck on?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. KeyBinding not responsive
    By Germoose in forum New To Java
    Replies: 3
    Last Post: 04-22-2012, 12:10 AM
  2. Keybinding
    By mine0926 in forum New To Java
    Replies: 4
    Last Post: 01-11-2011, 06:33 AM
  3. KeyBinding Help
    By Lil_Aziz1 in forum New To Java
    Replies: 12
    Last Post: 07-27-2010, 04:58 PM
  4. Transforming XML to HTML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-01-2008, 11:06 PM
  5. transforming double to int
    By AlejandroPenton in forum New To Java
    Replies: 2
    Last Post: 12-11-2007, 02:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts