• Log in or sign up for an account here: https://www.sythe.org/login

Java HashMap help

Fate1

Apprentice

Banned
Joined
Apr 21, 2005
Sythe Gold
5
Messages
773
Age
34
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 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
What line?
 
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.
 
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.

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.
 
Runescape Gamblingrunescape gambling
Back
Top