java posts

Design Java UI Like Visual Basic

One of the most frustrating and time-consuming tasks in Java is creating basic, boring, ordinary UI.  As in, windows, buttons, scroll bars, text fields, etc.

This is in stark contrast to, say, Visual Basic, where you can just drag and drop elements onto a form, and what you see is what you get.  In Java, if you want anything other than just the basics, you're going to have to do a lot of typing.

That is, unless, you are using the WindowBuilder Engine and Eclipse.

  • In Eclipse (3.7 at time of this writing), go to Help -> Install New Software.
  • Enter this address:
  • Download everything listed, then restart Eclipse:

After this, right-click in your project's src folder to create a new item.  Chose "other", then select the "Application Window" under Window Builder->Swing Designer:

Open the file you've created, and notice something cool-- you now have a "design" tab at the bottom of the code window.  Click it.  You now see a screen like so:

Notice it now looks a great deal like Visual Basic?

LibGDX Keycodes to Strings

If anyone out there is using the wonderful libGDX library for their mobile games, and are using the wonderful Controllers library that goes along with it, perhaps you've run into a problem which I found:  I wanted a way to let the player see the names of they keys they had mapped on the keyboard to different controls.

Well, in order to do that, I needed to know what the English names were associated with they keycodes delivered, for example, to the keyDown method.

So, I made a HashMap for my own uses, and thought I'd put it here.  It isn't complete, but it has most of the keys.  Enjoy!

public static HashMap<Integer, String> keycodeNames 
                          = new HashMap<Integer, String>();
  static {
    keycodeNames.put(7, "NUM_0");
    keycodeNames.put(8, "NUM_1");
    keycodeNames.put(9, "NUM_2");
    keycodeNames.put(10, "NUM_3");
    keycodeNames.put(11, "NUM_4");
    keycodeNames.put(12, "NUM_5");
    keycodeNames.put(13, "NUM_6");
    keycodeNames.put(14, "NUM_7");
    keycodeNames.put(15, "NUM_8");
    keycodeNames.put(16, "NUM_9");
    keycodeNames.put(29, "A");
    keycodeNames.put(57, "ALT_LEFT");
    keycodeNames.put(58, "ALT_RIGHT");
    keycodeNames.put(75, "APOSTROPHE");
    keycodeNames.put(77, "@");
    keycodeNames.put(30, "B");
    keycodeNames.put(4, "BACK");
    keycodeNames.put(73, "\\");
    keycodeNames.put(31, "C");
    keycodeNames.put(5, "CALL");
    keycodeNames.put(27, "CAMERA");
    keycodeNames.put(28, "CLEAR");
    keycodeNames.put(55, ",");
    keycodeNames.put(32, "D");
    keycodeNames.put(67, "BACKSPACE");
    keycodeNames.put(112, "FORWARD_DEL");
    keycodeNames.put(23, "CENTER");
    keycodeNames.put(20, "DOWN");
    keycodeNames.put(21, "LEFT");
    keycodeNames.put(22, "RIGHT");
    keycodeNames.put(19, "UP");
    keycodeNames.put(33, "E");
    keycodeNames.put(6, "ENDCALL");
    keycodeNames.put(66, "ENTER");
    keycodeNames.put(65, "ENVELOPE");
    keycodeNames.put(70, "=");
    keycodeNames.put(64, "EXPLORER");
    keycodeNames.put(34, "F");
    keycodeNames.put(80, "FOCUS");
    keycodeNames.put(35, "G");
    keycodeNames.put(68, "GRAVE");
    keycodeNames.put(36, "H");
    keycodeNames.put(79, "HEADSETHOOK");
    keycodeNames.put(3, "HOME");
    keycodeNames.put(37, "I");
    keycodeNames.put(38, "J");
    keycodeNames.put(39, "K");
    keycodeNames.put(40, "L");
    keycodeNames.put(71, "[");
    keycodeNames.put(41, "M");
    keycodeNames.put(90, "FAST_FORWARD");
    keycodeNames.put(87, "NEXT");
    keycodeNames.put(85, "PLAY_PAUSE");
    keycodeNames.put(88, "PREVIOUS");
    keycodeNames.put(89, "REWIND");
    keycodeNames.put(86, "STOP");
    keycodeNames.put(82, "MENU");
    keycodeNames.put(69, "MINUS");
    keycodeNames.put(91, "MUTE");
    keycodeNames.put(42, "N");
    keycodeNames.put(83, "NOTIFICATION");
    keycodeNames.put(78, "NUM");
    keycodeNames.put(43, "O");
    keycodeNames.put(44, "P");
    keycodeNames.put(56, ".");
    keycodeNames.put(81, "+");
    keycodeNames.put(18, "#");
    keycodeNames.put(26, "POWER");
    keycodeNames.put(45, "Q");
    keycodeNames.put(46, "R");
    keycodeNames.put(72, "]");
    keycodeNames.put(47, "S");
    keycodeNames.put(84, "SEARCH");
    keycodeNames.put(74, ";");
    keycodeNames.put(59, "SHIFT_LEFT");
    keycodeNames.put(60, "SHIFT_RIGHT");
    keycodeNames.put(76, "/");
    keycodeNames.put(1, "SOFT_LEFT");
    keycodeNames.put(2, "SOFT_RIGHT");
    keycodeNames.put(62, "SPACE");
    keycodeNames.put(17, "STAR");
    keycodeNames.put(63, "SYM");
    keycodeNames.put(48, "T");
    keycodeNames.put(61, "TAB");
    keycodeNames.put(49, "U");
    keycodeNames.put(0, "UNKNOWN");
    keycodeNames.put(50, "V");
    keycodeNames.put(25, "VOLUME_DOWN");
    keycodeNames.put(24, "VOLUME_UP");
    keycodeNames.put(51, "W");
    keycodeNames.put(52, "X");
    keycodeNames.put(53, "Y");
    keycodeNames.put(54, "Z");
    keycodeNames.put(129, "CONTROL_LEFT");
    keycodeNames.put(130, "CONTROL_RIGHT");
    keycodeNames.put(131, "ESCAPE");
    keycodeNames.put(132, "END");
    keycodeNames.put(133, "INSERT");
    keycodeNames.put(92, "PAGE_UP");
    keycodeNames.put(93, "PAGE_DOWN");
    keycodeNames.put(94, "PICTSYMBOLS");
    keycodeNames.put(95, "SWITCH_CHARSET");
    keycodeNames.put(255, "BUTTON_CIRCLE");
    keycodeNames.put(96, "BUTTON_A");
    keycodeNames.put(97, "BUTTON_B");
    keycodeNames.put(98, "BUTTON_C");
    keycodeNames.put(99, "BUTTON_X");
    keycodeNames.put(100, "BUTTON_Y");
    keycodeNames.put(101, "BUTTON_Z");
    keycodeNames.put(102, "BUTTON_L1");
    keycodeNames.put(103, "BUTTON_R1");
    keycodeNames.put(104, "BUTTON_L2");
    keycodeNames.put(105, "BUTTON_R2");
    keycodeNames.put(106, "BUTTON_THUMBL");
    keycodeNames.put(107, "BUTTON_THUMBR");
    keycodeNames.put(108, "BUTTON_START");
    keycodeNames.put(109, "BUTTON_SELECT");
    keycodeNames.put(110, "BUTTON_MODE");
    keycodeNames.put(144, "NUMPAD_0");
    keycodeNames.put(145, "NUMPAD_1");
    keycodeNames.put(146, "NUMPAD_2");
    keycodeNames.put(147, "NUMPAD_3");
    keycodeNames.put(148, "NUMPAD_4");
    keycodeNames.put(149, "NUMPAD_5");
    keycodeNames.put(150, "NUMPAD_6");
    keycodeNames.put(151, "NUMPAD_7");
    keycodeNames.put(152, "NUMPAD_8");
    keycodeNames.put(153, "NUMPAD_9");


Software License Fine Print

This code is considered "open source," and is released under the GNU Public License version 3 or any later version ( In a nut shell, you can change this code however you want, and redistribute it, but ONLY if it is ALSO under the GNU Public License version 3 or later.  This code/software is given "as-is", with no warranty or guarantee.

If you use this code/software, I would appreciate credit and a link back to this site (, though this is not required.

Java Associative Array (Sort Of)

Attached File(s): 

Ever wish that Java had associative arrays (aka assoc arrays) like in PHP?  As in, $x["name"] = "Bill" ?  Well, I created a helper class for Java which comes close to approximating it.  It can even loop through it similar to foreach().

ipad-java.jpgI call the class PseudoAssocArray, because it actually uses a HashMap to do the behind the scenes work. 

Simply include the file attached at the top of the page in your project, then use it like so:

PseudoAssocArray temp = new PseudoAssocArray(1);
temp.put("name", "April");
temp.put("age", "26");
// ...
String n = temp.get("name");

You can even make it be 2 dimensional by supplying a 2 in the constructor.  For example:

PseudoAssocArray temp = new PseudoAssocArray(2);
temp.put(0, "name", "April");
temp.put(1, "name", "Samuel");
// ...
String n = temp.get("1", "name");

Loop through like so:

temp.resetCounter(); //always do this first
while (temp.hasMore()) {
  Object obj = temp.getNext();
  // or: String s = (String) temp.getNext();

To loop through and get both key and value, try this:

while (temp.hasMore()) {
  Map<String, Object> entry = temp.getNextMap();
  String key = (String) entry.get("key");
  String value = (String) entry.get("value");



Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (, NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Syndicate content