I experienced a similar problem to Sameer Khazi in his original post.
I realised that the code I provided is used together with another class.
The class that extends JPanel is called each time a user clicks a button. This other class
creates a JFrame, creates a button, adds a listener to the button, creates a panel, adds the button and panel to the frame,
and when the user clicks on the button, the code in the actionPerformed method is executed, which in
this case is frame.repaint(). This causes the paintComponent method to be called. I did not need to add a
main method to the original code I posted.
I checked the versions for javac and java, both are Java 1.7.
I checked through the various steps that you provided. I then checked the classpath. I do have an older version of the java compiler running on my machine. I had to change the classpath to point to the directory I am currently using. There is another directory set up for the older version.
It is running now without having to make any changes. The autoboxing does work as well. I tried to pass it in as an int, and as an Integer object and both worked.