I have created a GUI on the Netbeans.... and I wanted to make a cross sign (x)
at the same point where user is clicking on the map.... As I have done it successfully.... but the problem is that when I am clicking on the map the cross sign is not coming at the same point.... it is coming very far from that point where i am clicking.... for example I have attached the sample image of my application.... when I am clicking on L of Los Angeles in the given map.... the red cross sign is showing very far from it... I don't why is it happening so.... Anybody any idea on this what can be the problem... This is my code...
test.jpg
sample image of my application for the above program
> Can you tell me why is it wrong.... As i have tried the same thing with this code... and it is working fine with this code....
run the code, it'll open in your browser
click somehwere and you'll get a red line/box/whatever drawn
OK so far
now minimize the browser, then maximize it again
everything cleared?
Yes it is true.... but my main problem is that red cross is not showing at the point where I am clicking on the map... it is showing very far from where I am clicking... Can you do the slight modifications in my code so that I can understand better where I am doing wrong....
will get you the graphics of 'extends javax.swing.JFrame'
so, if you click on the label at the label's 0,0, then tell the frame to draw something at the frame's 0,0
where would you expect it to be drawn?
from the above, can you work out the fix?
also, mouseClicked() is a very poor choice, it requires the x,y co-ords of both mousePressed and mouseReleased
to be identical, otherwise it won't fire i.e. any movement between pressed/released and clicked won't fire.
test it with a slow press/move/release.
I wanted to draw the red cross on the JLabel1 where the image of map is located.... but I am not able to figure it out why it is not showing at the same point where I am clicking on the map.... it is showing very far from that where I am clicking.... At the right side of the application I have created JPanel1 and then above JPanel1
I have created JLabel1 and then on the JLabel1 I am showing the Image of Map....
Do tell me what is going wrong.... As I have tried a lot... but I am not able to figure it out....
you need to work this out for yourself, otherwise you'll never be able to work out any problem.
here's a simple demo program that displays the same problem as yours.
run it, then click anywhere in the right panel (with blue border), little circles will appear in the left panel (black border)
the solution is obvious in this demo, as it is in yours
Thanks a lot for your help... I have figure it out my problem..
Really I have learned a lot with our conversations....
Cheers...
And one more thing.... As you have said that when I am minimizing my windows everything is getting cleared and it is true.... and It is because of the use of getGraphics()