My First ‘Self-Made’ Swing Application

I always wanted to create a Swing app by myself ever since I got to know that Swing has been included in the subject Advance Java Technology (or AJT). And I never imagined that it’d be the part of the first ever blog post of my life!  I’m currently in 7th semester of my Computer Engineering career at Shankersinh Vaghela Bapu Institute of Technology.

So I started learning basics of Swing API and gradually started adding components to it. Then an idea suddenly struck me from somewhere that What if I create an app that tests user’s clicking speed? It would include a simple button which the user would have to click 10 times. Then the user would get a message displaying his/her score (in milliseconds) and an extra message which would tell the user how good he/she is in clicking.

So I had the plan and I knew that the components needed would be a Button and Text which are available in Swing as JButton API and JLabel API respectively.

The next thing I wanted was a way to record the time needed by the user to click the button 10 times. I then remembered a little project I was working on when I read an article about ‘Benchmarking in Java’ which demonstrated a use of Stopwatch. I had created a class called Stopwatch which would record the time when the stopwatch started and stopped. I had two methods start() and stop() and another method called getElapsedTime() which would give the time between invocation of start() and stop() methods. getElapsedTime() returns a long value giving the elapsed time in milliseconds.And so I had all the stuff needed to develop this small app. I then completed it in nearly 4 hours ( C’mon it was my first app :D) and named it Click Tester, not that good, but suits the purpose.


Here is how it works:

You’re given a window titled ‘Click Tester’ which has two lines. First line saying, “How fast can you click?” and second one saying, “Click the button for 10 times!”.

After clicking it 10 times, it shows the time taken for you to click the button 10 times and another line telling how well you did.

Here’s how the last line is decided:

if your score is less than 1000 then you would get “Whoa! You must be Superman!” ,

if your score is between 1000 and 1200 then “We have a Click Star!”,

if your score is between 1200 and 1700 then “Good! You can do better!”,

if your score is between 1700 and 2200 then “Height of Laziness!”,

and greater than 2200 gives “You’re nothing but useless!”.

Note: The timer starts as soon as you click the button the first time. So if you get “You’re nothing but useless” then it is totally your fault. Don’t blame the app. 😛

Here is the link to download the app.

Prerequisites: JRE 6 or above.

Thanks. Don’t forget to comment. All the suggestions are welcome.

Leave a Reply