Reposted ---- Cannot plot Ovals on the Map on mouse Clicks

Hi all...
I am able to load the map of the South Pacific but I am not able to plot ovals on it . The following is my cod and the exception is also given below the code when i click the mouse. code is based on java 1.5 sdk
Please could anyone correct me with the correct code so that i am able to load the map and click the mouse to draw the points. I am having no knowledge of Java so we have to learn on out own to do this project.
Cheers
Jitendra
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class Map extends JPanel {
protected ImageIcon icon;
protected Point fp;
protected Point tp;
Graphics grf;
public static void main (String[] args) {
if (args.length == 0) {
System.out.println("You must specify the name of an image file");
return;
Map editor = new Map(args[0]);
JFrame f = new JFrame(args[0]);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(editor);
f.setSize(800, 700);
f.setVisible(true);
public Map(String name) {
super();
setLayout(new GridLayout(1,1,0,0));
icon = new ImageIcon(name);
JLabel label = new JLabel(icon);
label.setHorizontalAlignment(SwingConstants.LEFT);
label.setVerticalAlignment(SwingConstants.TOP);
label.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
handleMouseDown(event);
label.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent event) {
handleMouseDrag(event);
JScrollPane jsp = new JScrollPane(label);
add(jsp);
protected void handleMouseDown(MouseEvent ev) {        
tp = ev.getPoint();
grf.setColor(Color.blue);
System.out.println("Tp " + tp);
grf.fillOval(tp.x,tp.y,15,15);
repaint();
protected void handleMouseDrag(MouseEvent ev) {
tp = ev.getPoint();
public void paintComponent(Graphics g){
this.grf = g;
g.drawLine(fp.x,fp.y,tp.x,tp.y);
g.fillOval(fp.x,fp.y,15,15);
g.fillOval(tp.x,tp.y,15,15);
}

Who knows what the OP is doing with this posting. The same question with formatted code is found here:
http://forum.java.sun.com/thread.jspa?threadID=659765&tstart=0

Similar Messages

  • Cannot plot Ovals on the Map on mouse Clicks

    Hi all...
    I am able to load the map of the South Pacific but I am not able to plot ovals on it . The following is my cod and the exception is also given below the code when i click the mouse. code is based on java 1.5 sdk
    Please could anyone correct me with the correct code so that i am able to load the map and click the mouse to draw the points.
    Cheers
    Jitendra
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class Map extends JPanel {
       protected ImageIcon icon;
       protected Point fp;//start = new Point(0, 0);
       protected Point tp;//finish = new Point(0, 0);
       Graphics  grf;
       public static void main (String[] args) {
          String file = "../pic/Pic2.JPG";
          if (args.length == 0) {
             System.out.println("You must specify the name of an image file");
             return;
             //args[0] = file;
             Map editor = new Map(args[0]);
             JFrame f = new JFrame(args[0]);
             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             f.setContentPane(editor);
             f.setSize(800, 700);
             f.setVisible(true);
             //f.getContentPane().add(editor);
       public Map(String name) {
          super();
          setLayout(new GridLayout(1,1,0,0));
          icon = new ImageIcon(name);
          JLabel label = new JLabel(icon);
          label.setHorizontalAlignment(SwingConstants.LEFT);
          label.setVerticalAlignment(SwingConstants.TOP);
          label.addMouseListener(new MouseAdapter() {
             public void mousePressed(MouseEvent event) {
                handleMouseDown(event);
             public void mouseReleased(MouseEvent e){
                    /*tp = e.getPoint();
                    grf.setColor(Color.blue);
                    System.out.println("Tp " + tp);
                    //grf.drawLine(fp.x,fp.y,tp.x,tp.y);
                    //grf.fillOval(fp.x,fp.y,15,15);
                    grf.fillOval(tp.x,tp.y,15,15);
                    repaint();*/
          label.addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseDragged(MouseEvent event) {
                            handleMouseDrag(event);
          JScrollPane jsp = new JScrollPane(label);
          add(jsp);
       protected void handleMouseDown(MouseEvent ev) {
          //if((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
             //start = event.getPoint();
             //finish = event.getPoint();
             tp = ev.getPoint();
             //System.out.println("fp " + fp);
             grf.setColor(Color.blue);
             System.out.println("Tp " + tp);
                    //grf.drawLine(fp.x,fp.y,tp.x,tp.y);
                    //grf.fillOval(fp.x,fp.y,15,15);
                    grf.fillOval(tp.x,tp.y,15,15);
             //repaint();
             //System.out.println("Finish " + finish);
       protected void handleMouseDrag(MouseEvent ev) {
          //finish = event.getPoint();
          //tp = ev.getPoint();
          //System.out.println("DragFinish " + finish);
          //repaint();
       public void paintComponent(Graphics g){
       /*if (image == null){
                    image = createImage(getWidth(),getHeight());
                    grf   = image.getGraphics();
                    grf.setColor(getBackground());
                    grf.fillRect(0,0,getWidth(),getHeight());
                    //g.drawImage(image,0,0,null);
                    //g.setColor(dfltcolor);
                    //grf   = icon.getGraphics();
                    this.grf = g;
                    g.drawLine(fp.x,fp.y,tp.x,tp.y);
                    g.fillOval(fp.x,fp.y,15,15);
                    g.fillOval(tp.x,tp.y,15,15);
    }/* Exception
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Map$1.mouseReleased(Map.java:50)
    at java.awt.Component.processMouseEvent(Component.java:5488)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
    at java.awt.Component.processEvent(Component.java:5253)
    at java.awt.Container.processEvent(Container.java:1966)
    at java.awt.Component.dispatchEventImpl(Component.java:3955)
    at java.awt.Container.dispatchEventImpl(Container.java:2024)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.java:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1774)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    */

    Roughly put, don't access Graphics object outside the
    paintComponent() method.
    And, don't use Graphics object other than that is
    passed as the argument of the
    paintComponent() method for painting on the
    component.
    If you want to draw on an Image object before
    painting it on the component, use BufferedImage
    and the Graphics object gotten from its method. After
    that, use g.drawImage() method in the
    paintComponent() method.
    Your grf variable is complete nonsense.
    Delete it.
    Most importantly: learn Java GUI programming basics
    before anything else.
    See:
    http://java.sun.com/docs/books/tutorial/uiswing/index.
    htmlThanks very much but how I gonna use to load the image...since I haven't done any java before this is my first time as it is required in my project........pls some one help me.........

  • HT5429 unable to use MAPs in india as well as Middle east - When I try it gives pop up message - cannot provide directions. The map server is not available

    unable to use MAPs in india as well as Middle east - When I try it gives pop up message - cannot provide directions. The map server is not available

    Here:
    http://support.apple.com/kb/DL907?viewlocale=en_US&locale=en_US

  • My iPad "cannot determine location" on the map.

    My iPad "cannot determine location" on the map. Location services is turned on for all apps.  Why doesn't this work, and how can I fix it?

    If you have the wifi-only model then your location is determined by the router that you are connected to being in the database that Apple uses - only the 3G model has a built-in GPS chip. If you have an iPod that is able to get a location via your router then you could try Settings > General > Reset > Reset Network Settings and then reconnect to the network and see if the iPad then gets a location.

  • JTree - setSelectionPath not the same as mouse click

    I have a JTree. Selecting a node on it with a mouse displays a panel in a neighbouring area. However, I also need to select a node programatically. I have tried using JTree.setSelectedPath(), JTree.getSelectionModel().setSelectionPath() and a few variations thereof. All these methods highlight the node but do not bring up the panel alongside. The widgets are in a framework, so I am limited in changing that.
    Why is a mouse click different from a set selection path? The keyboard works fine too if I navigate using the arrow keys and then press Enter. Strangely, clicking anywhere within the JTree after selecting the node programatically also works. I am using JDK 1.3.

    Hi DB,
    Try restoring the connection (right click on the source system - restore).
    Hope this helps.
    Regards,
    Diego

  • TS3276 I cannot add contacts to the address book by clicking "add sender to address book."

    In Apple Mail, OS 10.7.3, when I click on add sender to address book, nothing gets added. The address book doesn't change. When I try adding addresses via previous recipients, the button is active, but when I click, nothing is added to the address book. Any ideas for me?
    CB

    Same thing happens to me. Running 10.9.2 on Macbook Air. Everything worked fine up until a few weeks ago then it stopped behaving.

  • Cannot Drag & Drop in the dock or double click to open files anymore

    Since installing OS X 10.4.3 then .4 I can only open files through the appropiate
    application using OPEN under FILE in that application. Drag & drop into the dock app only gives a momentary flash and a double click on the file/document does nothing. Any ideas? It worked fine in 10.3

    I have a similar issue, but my case is pretty odd (it is to me, anyway). I am in a largely Windows-based company, but work in a small Mac-based department. We recently relocated into new offices, and the new environment is run on a Windows 2003 server (our old offices were on a Windows 2000 server).
    My issue is that when I try to double-click an icon, drag an icon to the Dock, or open with keyboard shortcuts, the application launches, but no file opens. The only way I can open a file is via File>Open through the application.
    My computer is a PowerMac G5 running OS X 10.4.4 -- oddly, our 10.3.x users do not have this issue. And I never had any problems on the W2K server. So I'm sure there's something with the new 2003 server and 10.4, but I've searched through the threads and didn't see anything exactly like my issue.
    Any thoughts? Are there server settings that may have been missed by our IT department? Or is there something I need to set on my Mac? Any help would be greatly appreciated.

  • How do you go to marker  when there is a wait for mouse click between the markers?

    I cant seem to get by the wait for mouse click, when using                          go to (marker)
    I have a game that I have 2 push buttons one is
    on mouseUp me
      go to frame 9
    end
    on mouseUp me
       go to frame  29
    end
    There is a wait to click in between these 2  frames and when I click on the  2nd button to go to frame 29  it stops at the wait to click?
    I have tried  all these below and cant get past the click to wait?????
    go
    go to frame
    go to marker
    _movie.go
    _movie.marker
    _nextMarker=

    Think this issue is resolved but to ensure the full answer is available, here it is.
    First, it's a bad idea to use the Tempo channel at all. You can use a script to do anything that you can do there. I have Lingo alternates to the Tempo channel at:
    http://www.deansdirectortutorials.com/Lingo/tempoLingo.htm
    (think I need to update this page though)
    So - DO NOT USE the Tempo Channel setting - Wait for Mouse Click or Key Press.
    The above setting creates a type of pause that interferes with other interactivity.
    Instead - use a 'Hold on Frame' behavior (from the Library Palette - Navigation category) or it could be written as:
    on exitFrame
    go the frame
    end
    Once you have the above behaviour in you desired frame, you can attach a sprite behaviour to your buttons / links. A good one to use is the ‘Jump to Marker Button’ behaviour in the Controls category of the Library Palette. You can attach this behavior to different sprites and just change the marker setting of the behavior, removing the need to have individual hard-coded scripts for each button.
    Next – DO NOT link to frame numbers. Always link to a marker. You may insert or remove frames. This would cause your incorrect links since the frame number would no longer the right point.
    Next – the following all do the same thing:
    go to frame “markername”
    go to “markername”
    go “markername”
    So, you can leave out ‘frame’ or even ‘to’ as they are not needed. I still use ‘go to’ as it feels more natural to me (just history).
    or you could use:
    _movie.go("dean")
    Don’t use
    go to marker “markername”
    I think that did work at some point but not anymore.
    marker can be used as follows:
    go marker (-1)
    Where -1 is the amount of markers back (could be forward as well).
    Well, that gives the detailed answer to your question.
    Dean

  • The mapping: XML_NV you are trying to load cannot be found in the classpath

    Hi Experts,
    We have a EDI to JDBC scenario wherein the incoming EDI files (ANSI X12) will picked up by XI and sends to Backend system and it was working fine. Today when i check the file folder, the EDI files are not picking up by XI system and when I check the Communication channel the below is the error message. Can anybody let me know how to workaround for this issue?
    Error: javax.resource.ResourceException: --- Conversion of synchronous request from module chain ended with errors ---[Error:ID=1010;LEVEL=1] BICMapping runMapping() The mapping: XML_NV you are trying to load cannot be found in the classpath! Maybe you forgot to compile or to activate the mapping! DESCRIPTION: BICMapping Error: The mapping [not specified] you are trying to load cannot be found in the right path! Maybe you forgot to compile or to activate the mapping!
    Your help is highly appreciated.
    Regards
    Faisal

    Dear Abdul
    If the mapping is there and the PI system is throwing an error that "Mapping not Found" then please try refreshing the cache.
    First try Partial and if it does'nt work then go for Full Cache Refresh.
    Alternatively if yours is a Java mapping, try relading the code (zip file) and activate the channel.
    Sourabh

  • When I try and Save for Web in Photoshop CC I receive an error message saying 'The operation cannot be completed. The requested operation cannot be perfomed on a file with a user-mapped selection open'.

    When I try and Save for Web in Photoshop CC I receive an error message saying 'The operation cannot be completed. The requested operation cannot be performed on a file with a user-mapped selection open'. This happens with any of my files not just one in particular...
    Can anyone help solve this please?

    ELEMENTS 12 AND ELEMENTS 13
    Upgraded to 13 Thinking might resolve the issue.
    Was working fine up until we had "Tech" come in the office and "up grade some stuff"
    then all of a sudden i started getting this message, something happened but i don't have a clue what.

  • Cannot find the maps stored in import manager during port creation

    Hi All,
    I am unable to find any maps that i saved in import manager during port creation ,the maps are not showing in dropdown list during port creation in console.Do i need to store the maps that i have in import manager in specific place under mdm server,so that i can see them during port creation.
    All i need to do is assign my import map during inbound port creation,but i cannot find any maps in console.
    Could I know whether i am storing my maps some where other than default location.
    Thanks
    Aravind

    Hi Aravind,
    First of all check the remote system assigned to ur Port. After that go to import manager. When u logon to the import manager, u get a window "Connect to source". Mention the same remote system over there.Select the file type.Browse the file and map the fields,values,field matching and save the map. then unload the repo and assign the map to the port.
    Second way is, u create the port first and give any particular remote system to it. Put the file (u want to use for mapping) in the ready folder of that port and in connect to source window select the type as port, remote system(ame as used port port) and port.then map and save. unload the repo and assign the map to port. Ready folder will be in ur server at location: C drive or D drive->SAP MDM 5.5 ->server->distributions->repo name->inbound->port code->ready. For this option, Ur port type should be manual. After assigning the map u can change it to automatic or keep it manual as per ur requirement.
    Hope this solves ur problem.
    Regards,
    Dheeraj.
    Edited by: Dheeraj Kumar on May 6, 2008 9:16 AM

  • My location service is not working from the day one the response is that (cannot able to determine the location) .What can i need to do to see my location in maps and other application even the location services is enabled in the settings?

    From the day one the response is that (cannot able to determine the location) while using ios5.1 .What can i need to do to see my location in maps and other application even the location services is enabled in the settings?.Which means that is there is any problem in my ipad ? currently running on IOS 6.

    Your location is determined from a location database which contains the MAC addresses of routers and their physical location. A MAC address is a unique number which is built-in to all network devices when manufactured. The database is built and updated by actually driving around and mapping router locations.
    Since you just moved the location of your router has not been updated in the database and when you use Maps you will see your old location.
    If you go outside your house you can be correctly located because your iPod sees other routers which are in the location database. Note that you do not need to be connected to a router for your iPod to see it and obtain its MAC address.

  • I cannot access my exact location on the maps.

    I Have registered in a social media app where it needs to access my exact location. I have tried downloading other map app like google maps but still it cannot determine my location. i tried using other Ipad and they can access thier location And we are using same Router of internet provider. I need a bigtime help. Thanks.

    If you have the WiFi-only iPad (which does not have GPS) your location is determined by the mapped location of nearby WiFi routers. A WiFi+Cellular iPad or an iPhone have GPS and can locate themselves.
    Without GPS iPad location-finding is done by using a Apple location database which contains the MAC addresses of routers and their physical location. A MAC address is a unique number which is built-in to all network devices when manufactured. No two routers have the same MAC address.
    The Apple database is built and updated by Apple GPS-enabled devices (primarily iPhones) actually seeing routers and then adding/updating the router's locations into the database. There is no manual way to request an update to the Apple location database.
    Note, to be used for location determination, a device does not need to actually be connected to a router, it just has to see the router and its MAC address. More precise location determination can be done if several nearby routers can be seen.
    When a router is moved from one location to another erroneous locations can sometimes be reported until the router's location is corrected in Apple's database. If a router's location has not been added to Apple's database the iPad will not be able to locate its position.

  • I have taken a photo from an airplane and cannot get the 'map' function on the exifwizard app. Is it because I was too high? Altitude that is.

    I have taken a photo from an airplane and cannot get the 'map' function on the exifwizard app. Is it because I was too high? Altitude that is. Other photos allow me to use the 'map' function.

    Most likely, if you were inside the airplane, rather than sat on the wing, the iPhone couldn't get a GPS lock-on, or you didn't wait long enough for it to get a lock on.
    EDIT: Lawrence is right... forgot about that.

  • I cannot see the maps (java) at the norwegian yellow pages, will there be a fix ?

    All the maps at this yellow pages site does not show. Will there be a fix soon?

    I hate to say Me too but "ME TOO" .  The last update srewed up our phones and now the new update is out but Verizon wont give it to us...   Sprint got it last week!

Maybe you are looking for

  • AT&T Unlimited Data Plans

    Well lookie that Verizon since you took away unlimited data plans at&t is coming out with unlimiteddata plans, guess where everyone is going to go now?

  • Had to restore iPod Touch and it left me without my photos - HELP! :~(

    Had to do a restore, synced and backed up before.  However after the restore the apps, videos, and music are back, but I've lost all my photos.  Any help that anyone can offer would be GREATLY appreciated!

  • Phone randomly dies requiring hard reset

    Does anyone else have this same issue.  My phone randomly dies and requires a hard reset.  It has happened to me twice in 10 days.  First time I thought that I had let my phones battery get to low but after putting it on the charger for an hour it wo

  • Tecra 9100: The lid is broken and TFT is dead

    I have a Toshiba Tecra 9100 512MB ram CD/DVD +ext DVD-+RW +ext 160GB HDD etc........, but also epilepsy. I fell in a fit, and broke the lid. The case is broken (lid only), and the TFT is dead. Can you repair this? And if so; how much for what? Please

  • MacBook and recording

    I'm considering purchasing a MacBook for recording with GarageBand, but also for college for the next 5 years. My first priority was for recording, but I figured I might as well get the regular MacBook. My question is, with the lack of FireWire on th