Code rewritten using Java swing and java 7