> Hi all,
>
> I have to create a GUI in java that should have the following
> functionalities:
Homework?
> 1. load a map (bmp/jpg file) ) as background (ok this is the simplest task)
> 2. create objects on this map
[quoted text clipped - 5 lines]
> I have no idea on how to implement these things. Does anyone have
> suggestions?
I suggest implementing 1, since you believe it to be the simplest, then
come back here with your code and ask for a clue for 2.
nix schrieb:
> Hi all,
>
> I have to create a GUI in java that should have the following
> functionalities:
Hmm... I'll give you just some basic instructions.
> 1. load a map (bmp/jpg file) ) as background (ok this is the simplest task)
In fact, this are two tasks:
a) load a map
b) display it in the background
Create a subtype of JPanel (if you want to use Swing) that is able to
this (or at least b)). You'll have to override paintComponent (Swing).
Perhaps you want to do a) as a separate task and to display some
progress bar or something like this.
> 2. create objects on this map
Use an array in the created class (see above) to hold descriptions for
these objects. Extend paintComponent so that the described objects are
painted properly.
> 3. delete these objects
This is to remove the object(s) from the array and to repaint the panel.
> 4. drag &drop these objects on the map to put them in different positions
For this you'll have to extend your class a bit. First of all write a
method that returns an object (or null) for a given point. Then
implement MouseListener and MouseMotionListener. If the use clicks on an
object (here you'll have to use the previous mentioned method) with the
left mouse button, put the selected object into "some memory". Whenever
the use drags the mouse (see MouseMotionListener#mouseDragged) update
the object's description (perhaps followed by a repaint). Implement the
methods that are needed to do this.
> 5. do right click on a selected object in order to set some attributes of
> the object
Use the location retrieval method mentioned above. Update the object's
description and repaint the panel afterwards.
This should be enough to complete the task and to let you have some fun
with it on your own.
Bye
Michael