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.........

Similar Messages

  • 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

  • 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

  • How do I set my project to advance to next slide on mouse click vs just play?

    Captivate 6 on mac running OS 10.7.5 file format in question .htm (firefox)
    I'm brand new to Captivate 6 (never used it before) I have put together a mock presentation from scratch which has a few introductory slides then a quiz. When I publish it there is a "play" button which is NOT the behavior I want.
    I watched a training video from Lynda.com and the insstructor imported a PPT file, there was a dialog box which asked the how to advance slide, there was a drop down menu and one of two options was advance "on mouse click". This is the behavior I'm looking for.
    I've scoured the internet and forums etc to find a comparable option elsewhere in Captivate 6 when creating from scratch vs importing from PPT and cannot find one anywhere. I've also read that you can insert a click box object and that that would do what I'm looking for but that doesn't work either.
    Does any such option exist and if so where/ how do I get to it/ use it. Please see attachments below. First screen shot is the first slide I get which isn't the first slide either, what's up with that? Next one is simply to show how the project just "plays" instead of advancing slide by slide. Third is my publish dialog box. Bottom line I don't want a "play" button I want the user to mouse click next, next, next etc. How do I do this?
    Thank you for any help or suggestions!

    Maybe I understand something wrongly, but thought you also wanted to know how you can make slides advance on clicking the Next button instead of having it playing on automatically? And instead of using the playbar you want to have a Previous and Next button?
    The way imported PPT with advance on Mouse click works is because there is a click box added to each slide that pauses that slide at its end. The user has to click on the slide to advance.
    A click box is an 'interactive' object: this means that you can have it pausing the slide, that the user can interact with it and trigger an action like 'Go to Next Slide'.
    You added (from what I see on the last screenshot) another interactive object, but now I'm confused: the third screenshot has a Prev and Next arrow, I think those are shapes. You do not need to add a click box on top of them (what I see on the last screenshot), they can be converted themselves into buttons. I blogged a lot about those shape buttons. Anyway, both click box and shape button can pause the slide. This is the case by default for click boxes (at the end of their duration, their timeline), for shape buttons you have to tell them to pause in the Timing accordion. In your case I certainly would choose a shape button because they can be put on a master slide, or timed for the rest of the project whereas Click boxes need to be unique on each slide, you'l have a lot of copy/paste to do then. In the Action accordion, On Success you choose the action, I think in this case you want 'Go to Next Slide' for the Next 'thing'
    As for the first screenshot, Rod explained that you cannot get rid of the play button for pdf output, but you can have a poster image instead of the blank screen. There is a folder icon in Preferences, Project, Start and End when you deselect AuotPlay.
    Here is a link to an article where I explain shape buttons:
    http://lilybiri.posterous.com/why-i-like-shape-buttons-captivate-6
    There is an on-demand webinar as well on the Adobe site which I presented, only about shape buttons.
    Lilybiri

  • Multiple Buttons in JTable Headers:  Listening for Mouse Clicks

    I am writing a table which has table headers that contain multiple buttons. For the header cells, I am using a custom cell renderer which extends JPanel. A JLabel and JButtons are added to the JPanel.
    Unfortunately, the buttons do not do anything. (Clicking in the area of a button doesn't appear to have any effect; the button doesn't appear to be pressed.)
    Looking through the archives, I read a suggestion that the way to solve this problem is to listen for mouse clicks on the table header and then determine whether the mouse clicks fall in the area of the button. However, I cannot seem to get coordinates for the button that match the coordinates I see for mouse clicks.
    The coordinates for mouse clicks seem to be relative to the top left corner of the table header (which would match the specification for mouse listeners). I haven't figured out how to get corresponding coordinates for the button. The coordinates returned by JButton.getBounds() seem to be relative to the top left corner of the panel. I hoped I could just add those to the coordinates for the panel to get coordinates relative to the table header, but JPanel.getBounds() gives me negative numbers for x and y (?!?). JPanel.getLocation() gives me the same negative numbers. When I tried JPanel.getLocationOnScreen(), I get an IllegalComponentStateException:
    Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    Can someone tell me how to get coordinates for the button on the JTableHeader? Or is there an easier way to do this (some way to make the buttons actually work so I can just use an ActionListener like I normally would)?
    Here is relevant code:
    public class MyTableHeaderRenderer extends JPanel implements TableCellRenderer {
    public MyTableHeaderRenderer() {
      setOpaque(true);
      // ... set colors...
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));
      setLayout(new FlowLayout(FlowLayout.LEADING));
      setAlignmentY(Component.CENTER_ALIGNMENT);
    public Component getTableCellRendererComponent(JTable table,
                                                     Object value,
                                                     boolean isSelected,
                                                     boolean hasFocus,
                                                     int row,
                                                     int column){
      if (table != null){
        removeAll();
        String valueString = (value == null) ? "" : value.toString();
        add(new JLabel(valueString));
        Insets zeroInsets = new Insets(0, 0, 0, 0);
        final JButton sortAscendingButton = new JButton("1");
        sortAscendingButton.setMargin(zeroInsets);
        table.getTableHeader().addMouseListener(new MouseAdapter(){
          public void mouseClicked(MouseEvent e) {
            Rectangle buttonBounds = sortAscendingButton.getBounds();
            Rectangle panelBounds = MyTableHeaderRenderer.this.getBounds();
            System.out.println(Revising based on (" + panelBounds.x + ", "
                               + panelBounds.y + ")...");
            buttonBounds.translate(panelBounds.x, panelBounds.y);
            if (buttonBounds.contains(e.getX(), e.getY())){  // The click was on this button.
              System.out.println("Calling sortAscending...");
              ((MyTableModel) table.getModel()).sortAscending(column);
            else{
              System.out.println("(" + e.getX() + ", " + e.getY() + ") is not within "
                                 + sortAscendingButton.getBounds() + " [ revised to " + buttonBounds + "].");
        sortAscendingButton.setEnabled(true);
        add(sortAscendingButton);
        JButton button2 = new JButton("2");
        button2.setMargin(zeroInsets);
        add(button2);
        //etc
      return this;
    }

    I found a solution to this: It's the getHeaderRect method in class JTableHeader.
    table.getTableHeader().addMouseListener(new MouseAdapter(){
      public void mouseClicked(MouseEvent e) {
        Rectangle panelBounds = table.getTableHeader().getHeaderRect(column);
        Rectangle buttonBounds = sortAscendingButton.getBounds();
        buttonBounds.translate(panelBounds.x, panelBounds.y);
        if (buttonBounds.contains(e.getX(), e.getY()) && processedEvents.add(e)){  // The click was on this button.
          ((MyTableModel) table.getModel()).sortAscending(column);
    });

  • Wait for a mouse click

    Really need help with this one. I'm writing a program to simulate a Risk game and I need to write a method to make two countries neighbors, which would be done by adding each the neighbor country to each country's neighbor's array. To do this, I will need to click on the country, click on the map and then click on the other country. My method gets the country's name but how do I tell it to wait for a mouse click before trying to get the second country's name???? I've tried everything but to no avail. Any help would be appreciated.

    Some object has to be made a mouse listener for the components that are representing countries (I guess there are multiple of these) and the map.
    It should have a variable to represent first country clicked on - a variable that is initially null. It will need another variable to store the information it obtains from the click on the map (location, or whatever). It responds more or less as follows:
    Cick on country:
    Is firstCountry null?
        If so make firstCountry the country that was clicked on and finish
        If not, do we have mapInfo?
            If so use firstCountry, the country that was clicked on and mapInfo to update the neightbour list. Then make mapInfo and firstCountry null. Then finish.
            If not, just finish (because we are waiting for a click on the map).
    Click on map:
    Is firstCountry null?
        If so, just finish (because we are waiting to start the process with a click on a country).
        If not, extract the information from the map and place in mapInfo. Then finish.
    As you can see "waiting" in a GUI is quite a complex business - nothing really pauses, rather it continues as usual until an event of the right "type" occurs. The listener maintains enough "state" (information) to know what it is listening for and to remember necessary information that it has heard and will use later.
    This is somewhat general. It is difficult to be more specific unless you post some code. It should not be pages of GUI code - just enough to illustrate the task of three clicks and an action.

  • Different mouse clicks & speed up mouse movements?

    Hello,
    Does Adobe Captivate recognise different mouse clicks better
    to say if it can record on RMB LMB and MMB clicks different
    effects? For example I wish to record Software Simulation project
    were on different mouse clicks (RMB, LMB, MMB) would have custom
    effects like "OrangeRing" for RMB " "GreenRing" for LMB etc?
    One more question plz: I found Published movie mouse
    movements are very slow can I make it move more fast without
    editing every slide separatelly?
    Thanks
    Ton

    Hello Tony,
    Whilst Captivate does recognize different mouse clicks (in so
    much as the application will capture a right-click menu) you cannot
    specify what type of mouse effect the application will use when you
    capture.
    What you can do is change the mouse click effect post
    capture. To do this and with a just captured project open carry out
    these steps:
    1. Select the slide that has a mouse pointer where you would
    like need to show a right-click action.
    2. Choose Slide > Mouse > Properties...
    3. In the Mouse Properties dialog make sure that the option
    "show mouse click" is selected and then show either the color or
    the custom effect you would like to use to represent the
    right-click operation.
    Naturally, at the very start of your movie/project you would
    need to inform the learner that each time they see the one of the
    effect you want them to right-click. You could also include some
    audio as well which would be important if you need to adhere to
    accessibility standards.
    In regard to your second question, in most cases you will
    find that you get the best result if you adjust the mouse timing
    using the Timeline.
    That said if you own a copy of Adobe Captivate 2 you can
    change the mouse Display and Appear After settings globally via the
    Mouse Properties dialog. Personally, for mouse movement I would not
    recommend this. Anyway here are the steps to carry that out.
    1. Select any slide that has a mouse pointer present.
    2. Choose Slide > Mouse > Properties...
    3. Click the Timing tab
    4. Change the Display time and Appear After values
    5. Click the Settings button
    6. Choose the appropriate options from both Which properties
    and which slide categories
    7. Click OK.
    Note : You can also show the Mouse properties dialog by left
    clicking on mouse icon on any of the slides in the Filmstrip
    Regards,
    Mark

  • Adding mouse click effect

    Hello,
    I am trying to create a whirpool like wave effect on a image
    with a mouse click.
    This following url is what I am trying to achieve with
    captivate.
    http://www.gautamsaha.com/bigsky/assessment.swf
    The was created using the hotspot quiz type feature of
    "articulate"
    When you click on any part of the map with mouse, a nice
    wavelike ripple shows.
    When you click again on another part of the map, the same
    feature shows.
    I have tried hard...but I cant seem to figure out how to do
    this with Captivate.
    Can anyone help?

    Hi again gotham1
    When I say "create a widget", I'm referring to what I've seen
    my fellow Adobe Community Expert Paul Dewhurst do. You can check
    his stuff out by
    clicking here.
    Your statement regarding adding this to the gallery somewhat
    confuses me, as almost any object you add appears in the gallery.
    Further I'm confused with the comment regarding there being nothing
    in Captivate to enable interaction with Flash things. I'm really
    hopeful that you will check out Paul's stuff, as he has done many
    such things.
    I think your approach is what Paul uses. That is, dropping
    the Flash created .SWF onto a Captivate slide as an animation.
    Cheers... Rick

  • How can I (neatly) control mouse click events in a multi-dimensional array?

    Hello everyone!
         I have a question regarding the use of mouse clicks events in a multi-dimensional array (or a "2D" array as we refer to them in Java and C++).
    Background
         I have an array of objects each with a corresponding mouse click event. Each object is stored at a location ranging from [0][0] to [5][8] (hence a 9 x 6 grid) and has the specific column and row number associated with it as well (i.e. tile [2][4] has a row number of 2 and a column number of 4, even though it is on the third row, fifth column). Upon each mouse click, the tile that is selected is stored in a temporary array. The array is cleared if a tile is clicked that does not share a column or row value equal to, minus or plus 1 with the currently targeted tile (i.e. clicking tile [1][1] will clear the array if there aren't any tiles stored that have the row/column number
    [0][0], [0][1], [0][2],
    [1][0], [1][1], [1][2],
    [2][0], [2][1], [2][2]
    or any contiguous column/row with another tile stored in the array, meaning that the newly clicked tile only needs to be sharing a border with one of the tiles in the temp array but not necessarily with the last tile stored).
    Question
         What is a clean, tidy way of programming this in AS3? Here are a couple portions of my code (although the mouse click event isn't finished/working correctly):
      public function tileClick(e:MouseEvent):void
       var tile:Object = e.currentTarget;
       tileSelect.push(uint(tile.currentFrameLabel));
       selectArr.push(tile);
       if (tile.select.visible == false)
        tile.select.visible = true;
       else
        tile.select.visible = false;
       for (var i:uint = 0; i < selectArr.length; i++)
        if ((tile.rowN == selectArr[i].rowN - 1) ||
         (tile.rowN == selectArr[i].rowN) ||
         (tile.rowN == selectArr[i].rowN + 1))
         if ((tile.colN == selectArr[i].colN - 1) ||
         (tile.colN == selectArr[i].colN) ||
         (tile.colN == selectArr[i].colN + 1))
          trace("jackpot!" + i);
        else
         for (var ii:uint = 0; ii < 1; ii++)
          for (var iii:uint = 0; iii < selectArr.length; iii++)
           selectArr[iii].select.visible = false;
          selectArr = [];
          trace("Err!");

    Andrei1,
         So are you saying that if I, rather than assigning a uint to the column and row number for each tile, just assigned a string to each one in the form "#_#" then I could actually just assign the "adjacent" array directly to it instead of using a generic object to hold those values? In this case, my click event would simply check the indexes, one at a time, of all tiles currently stored in my "selectArr" array against the column/row string in the currently selected tile. Am I correct so far? If I am then let's say that "selectArr" is currently holding five tile coordinates (the user has clicked on five adjacent tiles thus far) and a sixth one is being evaluated now:
    Current "selectArr" values:
           1_0
           1_1, 2_1, 3_1
                  2_2
    New tile clicked:
           1_0
           1_1, 2_1, 3_1
                  2_2
                  2_3
    Coordinate search:
           1_-1
    0_0, 1_0, 2_0, 3_0
    0_1, 1_1, 2_1, 3_1, 4_1
           1_2, 2_2, 3_2
                  2_3
         Essentially what is happening here is that the new tile is checking all four coordinates/indexes belonging to each of the five tiles stored in the "selectArr" array as it tries to find a match for one of its own (which it does for the tile at coordinate 2_2). Thus the new tile at coordinate 2_3 would be marked as valid and added to the "selectArr" array as we wait for the next tile to be clicked and validated. Is this correct?

  • Mouse clicks occasionally stop working

    I am currently deploying a Java Swing application, and sometimes the end-user encounters an unusual problem whereby they open the application and mouse clicks have no effect. The mouse movement is still tracked fine, as buttons and menus get highlighted as expected when the mouse passes over them. I searched for information about this problem, and learned that a work-around is to click the middle mouse button. This does indeed restore the mouse click behaviour and all continues to work fine after that.
    So then I thought I might simulate a middle-button mouse click during my application start-up, in the hope of remedying the problem before any end-user actually sees it. The result is that instead of remedying the problem, I actually cause it to happen every time! The application gets into a state whereby mouse clicks are ignored, and clicking the middle-mouse button restores the mouse click behaviour.
    Has anyone else experienced this problem, and know of a way to prevent end-users from experiencing this problem? Here's some example code that demonstrates the behaviour:
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Main
        public static void main(String[] args)
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JButton("Click Me"));
            frame.pack();
            frame.setLocationRelativeTo(null);
            try
                // Simulate a middle-button mouse click
                Robot robot = new Robot();
                robot.mousePress(InputEvent.BUTTON2_MASK);
            catch (Exception e)
                e.printStackTrace();
            frame.setVisible(true);
    }Note I'm using Java 1.6.0_07. Any help with this would be much appreciated,
    Paul.

    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Main
        public static void main(String[] args)
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JButton("Click Me"));
            frame.pack();
            frame.setLocationRelativeTo(null);
            try
                // Simulate a middle-button mouse click
                Robot robot = new Robot();
                robot.mousePress(InputEvent.BUTTON2_MASK);
                // Simulate a middle-button mouse click again
                robot.mousePress(InputEvent.BUTTON2_MASK);
            catch (Exception e)
                e.printStackTrace();
            frame.setVisible(true);
    }?

Maybe you are looking for

  • I cannot get the file download using 1.6

    Hi, I am using HTMLDB v1.6 and I have followed the example to upload and download files. I was able to get the file upload working but I am getting the page cannot be found error message. I am using a package to implement the page download can I do t

  • ISE 1.1.1 Sponsor Portal - Unable to create First Names with "-"

    Hi! Regarding our international subsidiaries there are many names that contain the character "-" (i.e. Pierre-Pascal) When trying to create an new Guest Account the ISE refuses it because of an invalid character in the "First Name" field. In other fo

  • Unable to install Microsoft Office Professional Plus 2013

    I'm trying to install Office 2013 on a Windows 7 64bit but it fails as soon as I execute the setup.exe with the following error message "Microsoft Setup Bootstrapper has stopped working" So far I have tried running as administrator, disabling UAC, st

  • Problem with downloading music

    I have a problem with downloading music,I tried random sites but still when I downlad it start and end up witg error Subject Title edited to reflect new topic.

  • Running config details

    I customer asked me today during a demo of the Total Care portal, for running configuration, are the details shown captured at the time the device was reviewed during the discovery service or what would be running at the current time. I thought the i