This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
i am trying to write a program
aim: generate an image by extending JFrame and by implementing KeyListener
i want to change the position of the image by pressing the keys -,=
i am unable to get the output.
verify this once and tell me the root cause
here i am attaching the code
Joined: Oct 27, 2011
its only printing the - pressed or = pressed
but its not doing any graphical thing on the JFrame window like changing the back ground color moving the image to that positions
not even printing the string
Also, you are storing the Graphics object and making changes to that from the keyListener methods. I am not sure if the same graphics object is passed to the paint methods. Instead, you can store the key event generated in an instance variable (in the key listener methods) and make a call to repaint(). Then in the paintComponent method, you have to do the if/switch check and draw the graph accordingly.
SCJP 1.4, OCMJEA/SCEA 5.0.
subject: using JFrame with KeyListener Interface and using paint method