Java HashMap help

Discussion in 'Programming General' started by Fate1, Jan 2, 2010.

Java HashMap help
  1. Unread #1 - Jan 2, 2010 at 3:20 PM
  2. Fate1
    Joined:
    Apr 21, 2005
    Posts:
    773
    Referrals:
    2
    Sythe Gold:
    5

    Fate1 Apprentice
    Banned

    Java HashMap help

    I am using this code in my program
    Code:
    	
    import java.util.HashMap;
    
    Map<Character, Integer> map = new HashMap<Character, Integer>();
    	map.put('a', KeyEvent.VK_A);
    	map.put('b', KeyEvent.VK_B);
    	map.put('c', KeyEvent.VK_C);
    	map.put('d', KeyEvent.VK_D);
    	map.put('e', KeyEvent.VK_E);
    	map.put('f', KeyEvent.VK_F);
    	map.put('g', KeyEvent.VK_G);
    	map.put('h', KeyEvent.VK_H);
    	map.put('i', KeyEvent.VK_I);
    	map.put('j', KeyEvent.VK_J);
    	map.put('k', KeyEvent.VK_K);
    	map.put('l', KeyEvent.VK_L);
    	map.put('m', KeyEvent.VK_M);
    	map.put('n', KeyEvent.VK_N);
    	map.put('o', KeyEvent.VK_O);
    	map.put('p', KeyEvent.VK_P);
    	map.put('q', KeyEvent.VK_Q);
    	map.put('r', KeyEvent.VK_R);
    	map.put('s', KeyEvent.VK_S);
    	map.put('t', KeyEvent.VK_T);
    	map.put('u', KeyEvent.VK_U);
    	map.put('v', KeyEvent.VK_V);
    	map.put('w', KeyEvent.VK_W);
    	map.put('x', KeyEvent.VK_X);
    	map.put('y', KeyEvent.VK_Y);
    	map.put('z', KeyEvent.VK_Z);
    	map.put('1', KeyEvent.VK_1);
    	map.put('2', KeyEvent.VK_2);
    	map.put('3', KeyEvent.VK_3);
    	map.put('4', KeyEvent.VK_4);
    	map.put('5', KeyEvent.VK_5);
    	map.put('6', KeyEvent.VK_6);
    	map.put('7', KeyEvent.VK_7);
    	map.put('8', KeyEvent.VK_8);
    	map.put('9', KeyEvent.VK_9);
    	map.put('0', KeyEvent.VK_0);
    	map.put('.', KeyEvent.VK_PERIOD);
    	map.put('!', KeyEvent.VK_EXCLAMATION_MARK);
    	map.put(',', KeyEvent.VK_COMMA);
    	map.put(' ', KeyEvent.VK_SPACE);
    But I can not get it to compile for some reason. I get an error <identifier> expected.
    Any ideas why it wont work?
     
  3. Unread #2 - Jan 2, 2010 at 6:11 PM
  4. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Java HashMap help

    What line?
     
  5. Unread #3 - Jan 2, 2010 at 8:55 PM
  6. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Java HashMap help

    Well, you never imported java.awt.event.KeyEvent for starters. You also never defined a class, enum, or interface which you must do in any valid .java file.

    Once you've defined a class, make your 'map' field either a class or local variable within that class. You haven't really explained what you're going to do with this, but I assume that you're trying to make a method that returns the KeyEvent code associated with a char. If that's the case, then put the variable in a method, along with all of the method calls, and return the Integer of the get() method of your Map. You can make your method static, as there isn't any instance fields to with it must refer to. If you are going to call this method many times from your program, you should make your 'map' variable a static class member, and do all of your initial method calls within a static block.
     
  7. Unread #4 - Jan 2, 2010 at 11:01 PM
  8. Fate1
    Joined:
    Apr 21, 2005
    Posts:
    773
    Referrals:
    2
    Sythe Gold:
    5

    Fate1 Apprentice
    Banned

    Java HashMap help

    This is just part of the code. Not the whole entire thing. I have the java.awt.event* imported.
    Anywho what I'm trying to accomplish is making an autotyper using the HashMap using the robot class. This seemed like the easier way. And so just put it in a method and return the int? I'll give it a try. Thanks

    edit: actually i approached this all wrong and found an easier way than using hashmap but thanks anyways.
     
< Crappy auto talker | Good book for C++ >

Users viewing this thread
1 guest


 
 
Adblock breaks this site