November 8th, 2012, 07:46 AM
draw image at mouse position
I have recently started the developement of a minigame called "toro".
As this is my first time using graphics, i have no ideea where to start, so i'll just make a brief introduction to the program and ask you for help.
Toro is a game in which you have to defend 5 dots against a bull, by telling the dots where to go via a cursor. The program is composed from a JPANEL inside a JFRAME .
What i need to do is the following:
1) Add a mouse listener on the JPANEL so i could get the coordinates of the mouse as it you click it. [done]
2) When Clicked, the panel should display an image (100*100px if it matters) to the coordinates returned by the listener [pending]
What i have tried:
I know that you will not accept giving help without me trying by myself, so i'll tell you what i already tried.
Bassically everything i tried was related to overriding paintComponent(Graphics g) , but most of it failed since my main class extends JFRAME and not JPANEL hence the inability to override paintComponent() .
I have also tried making another class extending JPANEL , tentative which failed.
From the tutorials I've seen i learned how to draw an image at the very beginning of the execution, but not when triggered by an event ( mouseClicked ).
Please help me, i really dont know what to look for anymore, as i already consulted G O O G L E ! but nothing has been relevant.
Last edited by cens; November 8th, 2012 at 07:54 AM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!