Map, Radio Button, and Coordinates

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #11
Oct 2nd, 2009
Originally Posted by Ezzaral View Post
- Labels do not have to be opaque. setOpaque(false);
- setLayout(null); will allow you to place a component anywhere you like.
so by the setting the label's opaque to null, the map image and the spot image will go along. . .? that mean the map image will be at the back and the label will be in the front of map image?

As for the layout, I will try to set it as null. . .I hope this will work. . .if this will work, how can I put the component anywhere I want? I am not using net beans or any visual java application. . I am pure hard code.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Map, Radio Button, and Coordinates

 
1
  #12
Oct 2nd, 2009
Positioning with no layout manager:
http://java.sun.com/docs/books/tutor...yout/none.html
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #13
Oct 2nd, 2009
I found some information on the internet that explain on how to set the location of the label. Thank you for the idea, I will let you know soon if I get this thing right.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Map, Radio Button, and Coordinates

 
1
  #14
Oct 2nd, 2009
You could use something like this in your MapPanel to manage the "spots"
  1. import java.awt.*;
  2. import java.awt.event.MouseEvent;
  3. import java.awt.event.MouseListener;
  4. import javax.swing.*;
  5.  
  6. public class MapPanel extends JPanel {
  7.  
  8. Image map;
  9. ImageIcon spot1, spot2, spot3, note;
  10. JLabel point1, point2;
  11.  
  12. public MapPanel() {
  13. Toolkit kit = Toolkit.getDefaultToolkit();
  14. map = kit.getImage("cebumap.jpg");
  15.  
  16. spot1 = new ImageIcon("spot.gif");
  17. point1 = new MapLabel(spot1, "p1");
  18. point1.setBounds(168, 30, spot1.getIconWidth(), spot1.getIconHeight());
  19.  
  20. spot2 = new ImageIcon("spot2.gif");
  21. point2 = new MapLabel(spot2, "p2");
  22. point2.setBounds(203, 55, spot2.getIconWidth(), spot2.getIconHeight());
  23.  
  24. setPreferredSize(new Dimension(457, 540));
  25.  
  26. setLayout(null);
  27. add(point1);
  28. add(point2);
  29. }
  30.  
  31. public void paintComponent(Graphics comp) {
  32. Graphics2D comp2D = (Graphics2D)comp;
  33. comp2D.drawImage(map, 0, 0, this);
  34. }
  35.  
  36. /** Small convenience class to manage all of your special point label functionality in one place */
  37. class MapLabel extends JLabel implements MouseListener {
  38. Icon icon;
  39. String name;
  40.  
  41. public MapLabel(Icon icon, String name) {
  42. this.icon = icon;
  43. this.name = name;
  44.  
  45. setIcon(icon);
  46. setToolTipText(name);
  47. addMouseListener(this);
  48. }
  49.  
  50. public void mouseClicked(MouseEvent e) {
  51. JOptionPane.showMessageDialog(this, "You clicked " + name);
  52. }
  53.  
  54. public void mouseEntered(MouseEvent e) {
  55. setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  56. }
  57.  
  58. public void mouseExited(MouseEvent e) {
  59. setCursor(null);
  60. }
  61.  
  62. public void mousePressed(MouseEvent e) {}
  63. public void mouseReleased(MouseEvent e) {}
  64. }
  65. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #15
Oct 3rd, 2009
Wow, thank you so much . .I think this will work. . I will let you know if it really work as soon as I can. .the code is really understandable.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #16
Oct 4th, 2009
The code works great. . .Thank you so much Ezzaral. . .I would like to ask one last thing. . .please advise me.

I would like to ask if the code is correct, the code will open another window name NewWindow if the point1 label is clicked. This is last problem. . .

  1. public void mouseClicked(MouseEvent e) {
  2. if(e.equals(point1)) {
  3. NewWindow nw = new Window();
  4. }
  5. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Map, Radio Button, and Coordinates

 
0
  #17
Oct 4th, 2009
You already know which point was clicked, because that point itself is the mouse handler, so all you need to do is create and show the new frame. You can pass whatever information you need from the point label to the frame.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #18
Oct 4th, 2009
Originally Posted by Ezzaral View Post
You already know which point was clicked, because that point itself is the mouse handler, so all you need to do is create and show the new frame. You can pass whatever information you need from the point label to the frame.
So you mean like this?
Assuming I have 3 frames name:

Point1 p1 = new Point1();
Point2 p2 = new Point2();
Point3 p3 = new Point3();


public void mouseClicked(MouseEvent e) {
Point1 p1 = new Point1();
Point2 p2 = new Point2();
Point3 p3 = new Point3();

}

My apology Sir Ezzaral, I am new to mouse listener and events. . . Hope you understand. . .=)
Last edited by nagatron; Oct 4th, 2009 at 1:18 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: Map, Radio Button, and Coordinates

 
0
  #19
Oct 5th, 2009
Each point has its own specific action. . .I need to put If condition to that, I found some codes on the internet and it looks like this:

  1. spot1 = new ImageIcon("spot.gif");
  2. point1 = new MapLabel(spot1, "p1");
  3. point1.setBounds(168, 30, spot1.getIconWidth(), spot1.getIconHeight());
  1. public void mouseClicked(MouseEvent e) {
  2. String str = point1.getText();
  3. if(str.equals("p1")) {
  4. NewWindow nw = NewWindow();
  5. }
  6. }

but it won't work, it won't do any action. . .please, help me with this last action.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Map, Radio Button, and Coordinates

 
0
  #20
Oct 5th, 2009
How does the action for point1 differ from point2? That is what matters for the mouse handler.

Do you actually have a frame class called NewWindow? Does it make itself visible in it's constructor?
Reply With Quote Quick reply to this message  
Reply

Tags
button, coordinates, java, radio

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC