Keylistener not working for JPanel

If you search this problem, you’ll see that it is asked and has been solved many times. KeyListeners need to be on the focused component to work. One solution is to give your component the focus after first making it focusable. Better by a long shot however is to use Key Bindings. Google the tutorial … Read more

Popup Message boxes

javax.swing.JOptionPane Here is the code to a method I call whenever I want an information box to pop up, it hogs the screen until it is accepted: The first JOptionPane parameter (null in this example) is used to align the dialog. null causes it to center itself on the screen, however any java.awt.Component can be … Read more

Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException

OK what I am trying to do here is create a game where the object/ball is controlled by clicking on the object with the mouse, pulling back the mouse (the distance the mouse is pulled back will determine the velocity of the object) and on releasing the button the object will move (it’s angle of … Read more

What does super.paintComponent(g) do?

What does it do? It prints the component as if you hadn’t overridden the paintComponent method. If you have a background color set for instance, this is typically painted by the class you’re extending. When do we need to use it? You use it if you don’t paint on the entire component. The parts that … Read more