Custom JDialog PIN Entry

Its been a while since I did Java programming, but I occasionally get myself into a weeks programming to keep up with the hobbies. Today is the second day I got back into some programming. I am working on an application which has a settings screen, but I don’t want people to access it, so I had a task of developing a password screen. The application is being designed for a touchscreen, so passwords are out of the question (no keyboard) hence, I wanted to get a keypad on the screen for a 4-digit PIN entry.

I wanted the behaviour of the program to stop everything and only allow user input on the keypad whilst it was on screen – much like the behaviour of a JDialog¬† when it is on screen – you have to deal with it before you can get back to the parent frame. So I built a class which extends on the JDialog and constructs a JPanel with the JButtons inside to deal with the user input. Not being a Java regular, I couldn’t tell you whether I’ve done something against the rules here, but it works pretty neatly, and the best bit is its a static call, so it can be used in any other scenario (just access the variables inside for the three possible responses, CANCELLED, ACCESS_GRANTED or ACCESS_DENIED)

The keypad looks like this:

To call it, you simply add the Keypad class to your program, and use the code below

//showDialog(jFrame, title, PIN, attemptsAllowed)
int result = Keypad.showDialog(myJFrame, "Please enter PIN", "1234", 3);
//result is one of the following
  case Keypad.ACCESS_GRANTED:
  case Keypad.ACCESS_DENIED:
  case Keypad.CANCELLED:

Hope that helps someone. All that is needed to perfect this is to prevent the user closing the window using the X in the top right, but that doesn’t bother me at the moment.
I’ve put the zip file below with the class file and the images used on the buttons.

Ecuador Experience build up

It’s been quiet on here recently. With the weather getting colder, and nights darker, there hasn’t been much time to get my bike shed finished, and other woodwork done, though the roof of the bike shed is waterproof, so it will survive until the spring if it needs to!

In college, I have had an interesting time – many months ago, we had a visit from a Phil Williams, who aside from travelling around businesses promoting ecological ideas and living, arranges the occasional trip to Ecuador, which is an opportunity to visit cloud forests, rainforests and travel across the Andes. When I heard about the trip, I was instantly interested. In October, we were asked if we were interested in the trip, and I registered my interest. At fairly short notice, we were told that the trip would be taking place in April, over Easter. Though it came as a bit of a shock, I figured the only way to do trips like this would be to seize the opportunity when they come up! I paid my deposit last week.

I got a newsletter which outlined the trip today, though a full schedule will be on its way in February. In that time, I’m working as much as I can in stadiums to get some money for the trip together, and possibly looking at a fundraiser over February half term! Its a busy time, but the more I do things, the faster Easter will come!