Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for May 2014

From Java Swing Dimension JFormattedTextField bite

leave a comment »

Today, I poke around Java Swing to build up a simple data entry. One thing I wanted to do is to create a number input field so as usually I hack through the API document and found this little JFormattedTextField component. By the judge from the API point of view it is pretty easy to use. All we have to do is instantiate the component with preferred format or mask and that is pretty much about it.

numField = newJFormattedTextField(NumberFormat.getIntegerInstance());
container.add(numField);

Now, I wanted to hook an event listener to this field and retrive new value

/* this, container which implements PropertyChangeListener */
numField.addPropertyChangeListener("value", this);

So basically we got this:

numField = new JFormattedTextField(NumberFormat.getIntegerInstance());
numField.addPropertyChangeListener("value", this);
container.add(numField);

Now if you try to call .setValue(new Integer(100)) you will present with an exception java.lang.NullPointerException. After inspecting the PropertyChangeEvent class definition I believe that Java try to compare old value and new value, but we haven’t set any value before we hook up an event listener. Therefore, Java takes it liberties to raise an error in our face and that is fair enough right?

How to fix this? Well, it is simple set initial value before hook an event listener would solve the problem.

numField = new JFormattedTextField(NumberFormat.getIntegerInstance());
numField.setValue(new Integer(0)); // this line is your savier!
numField.addPropertyChangeListener("value", this);
container.add(numField);

Written by Chorn Sokun

May 13, 2014 at 8:06 am

Posted in Programming

Tagged with ,

Joljet mobile client

leave a comment »

A few years ago, I built a music portal to experience ExtJS and of cause to create my own music listening experience. It was fun and I have learnt a lot from this exercise from hand craft the app, built script and caching optimization. As always with great power come great responsibility. Due to the size of ExtJS core, the page load is not satisfy by most. However, the site hosted on cheap server and not using any CDN therefore I can’t push it too far.

Moving on, I have done with ExtJS and I know the site works perfectly on desktop platform. However, on mobile it is kind of suck. But well, as a pet project I’m not too worry about that until I’m need to listen to my favorite song on the go then mobile client is needed. So, I decided to built one for myself AGAIN! :D. Yeah, again. Why not after all I’m a craftman I love builting stuffs.

Now here is the plan

Image

I’m going to built mobile client which reuse all functionality from the portal and at the same time extending the functionalities to support offline, favorite & playlist customization or by the way I don’t want to be responsible for username & password so I am going to offload that task to Facebook.

Sound interesting right ;) to make it more interesting I shall say that I have no clue how to built a mobile app at this point. But, let see how long it will take for me to built one :D

 

Written by Chorn Sokun

May 12, 2014 at 8:07 am