This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have a thorny problem someone here may be able to help me with:
I have a package "Nomad", with various classes, but driven from an Applet - "Tracker". Part of my package is a subclass of Canvas ("MapDisplay") which I use to display a map of the world. Given a list of cities into Tracker, it uses the MapDisplay component to scroll from city to city (the map is bigger than the MapDisplay area), in order, and draw a red line between each one (like on the Indiana Jones movies).
All this works fine, but what I'd like to do is have a group of buttons at the bottom of the applet to control direction of travel along the route, pausing it so that comments can be read, etc. My problem is that when I add these buttons, it doesn't register any clicks until after the map has finished scrolling to its last city (which is a bit late).
Now some structure info: -My components are created as part of a separate Thread within init(), which is also where the city list is loaded. -My scrolling code is in paint(), and basically gets a ListIterator and steps through the list of cities and scrolls from one to the next.
I can't help but think my code needs to be moved around a bit. This is my first applet since "Hello World", so I'm not sure of the structure of what functions kick off when, and which are in separate Threads etc. I tried moving my scrolling code into start(), but that ended up taking longer to load, before just showing the map at the last city, red line already drawn.
What I need is the map to start scrolling as it does at the moment, but to register a button click immediately and perform the appropriate action. If no buttons are pressed, it just runs to the end and stops.