Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem With GUI of Net Beans

 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[Thumbnail for test.jpg]
sample image of my application for the above program
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is my full code.... Please explain me what is the problem that I am having with red cross....
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the image that you have to put in C drive
Just Like...
C:\\photos\\la.jpg
la.jpg
[Thumbnail for la.jpg]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so to remove this thing what I have to do....


The answer was given in the first reply.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
crosspost: java-forums.org thread

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

Thanks for your cooperation.

/Pete
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic