• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Brainstoming Session  RSS feed

 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello . I want to create a simple java applet or swing application which uses a image of the continental united states. I will have it where the user can click on a specific state (place on the map) and it will tell them below what the population is and the capitol etc. This is a final project of mine. I do not need any help with the coding but if someone could point me in the right direction to where I can start . Like offer me some pseudo code suggestions. i want to use a JPEG or something to that effect because I do not want to create the united states from scratch. My text book does not go into any detail about how mouse clicks can transmit from a pre rendered image. I hope this makes sense. Thanks for looking
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get you started, you should look into how java render images from Java tutorial and then how to add listeners to it.

The Swing tutorial should get you started with GUI.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi James,

one way to get it done is:

1) make sure you have an image of the USA, which you can load into a BufferedImage (call it BI)

2) create a JPanel with a paintComponent that draws this BI

3) add transparent JLabels to that JPanel on every place in the US that is of interest. This is one situation where
a GUI designer comes in handy; you can add these labels at the right size and at the right location with
great ease; just make sure you use a free layout (or no layout at all) to prevent that adding a label
realigns all the other labels.

4) add a MouseListener to all these labels. You can use this listener for two purposes: when the mouse
enters a label, you can pop up some info text, and when the user clicks on a label, you can pop up
the relevant information.

5) you can use a Map<JLabel, String> for info concerning the specific labels

Quite a bit of coding to do, and of course, there are many other ways to achieve the desired result. But I hope
you have some direction to go for.

Greetz,
Piet

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!