This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem With GUI of Net Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem With GUI of Net Beans" Watch "Problem With GUI of Net Beans" New topic
Author

Problem With GUI of Net Beans

Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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...




[Thumbnail for test.jpg]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this is just wrong



learn to do it the correct way, then start over

http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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....

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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?
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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....
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
there's no point fixing a minor error when the app. is seriously broken elsewhere.

if you're talking about the first lot of code you posted, it doesn't compile, so I can't run it to test it
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86


This is my full code.... Please explain me what is the problem that I am having with red cross....
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
This is the image that you have to put in C drive
Just Like...
C:\\photos\\la.jpg


[Thumbnail for la.jpg]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Graphics g = getGraphics();

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.
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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....
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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


Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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()

so to remove this thing what I have to do....
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2191
    
    7
so to remove this thing what I have to do....


The answer was given in the first reply.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
crosspost: java-forums.org thread

OP, please read this link: Be Forthright When Cross Posting To Other Sites

Thanks for your cooperation.

/Pete
 
GeeCON Prague 2014
 
subject: Problem With GUI of Net Beans