help needed with image map or creating a fancy java gui

S

steven robinson

Does anyone know if I can use image map within a java application, not
web based html. I am building a simple java mp3 player and would like
to use a flashy/fancy gui and thought the answer would be an image
map. Anyone out there know how I could use an image map in a
awt.window component? Or does anyone have any better ideas for
creating a fancy gui within my java application?

Thanks
Steve
 
T

Tim Van Wassenhove

Does anyone know if I can use image map within a java application, not
web based html. I am building a simple java mp3 player and would like
to use a flashy/fancy gui and thought the answer would be an image
map. Anyone out there know how I could use an image map in a
awt.window component? Or does anyone have any better ideas for
creating a fancy gui within my java application?

1) Draw your image on the panel.
Define the "areas" on the image with java.util.Shape.
Use the Shape.contains( mouse coordinates) to determine which
shape the mouse is on.

Better solution (AFAIK)
2) Add your compontents to a container, and override the paint methods.
 
N

nos

i think the OP wants to have a big gif file
instead of a large numer of components then
decide what to do based on x,y
 
S

steven robinson

nos said:
i think the OP wants to have a big gif file
instead of a large numer of components then
decide what to do based on x,y

Thats exactly it, any ideas how to approach this? Adding a gif image
to a panel should be easy, if thats allowed in awt.Panel? but how do
you define a an area that implements mouseListener ?

Thanks
Steve
 
H

Harald Hein

steven robinson said:
Thats exactly it, any ideas how to approach this? Adding a gif image
to a panel should be easy, if thats allowed in awt.Panel? but how do
you define a an area that implements mouseListener ?

You listen to all mouse events on the panel. Then you write your very
own code which tests where the event occured. Then you go through your
very own list of regions and try to find a region which encloses the
coordinate of a mouse event. For each region and type of mouse event
you have implemented a corresponding handler. E.g. "if a click appeared
in [4, 8, 12, 6], start playing an MP3".

The "fun" starts when you have to handle more complex user interaction,
like dragging a volume slider. And when you allow non-rectangular
regions. The math to detect if a coordinate is inside or outside an
arbitrary shape is quite interesting.

What you will end up with is your very own event dispatching system.

Or you try to find some implementation of this on the web. Or you come
to your senses, and just build a conventional AWT or Swing GUI. If you
go for Swing, you can at least create your own PLAF. Not as flexible as
a gif, but simpler.

BTW: Did someone tell you that it is impossible to have anything else
than rectangular windows in Java?
 
T

Thomas Weidenfeller

Harald Hein said:
The "fun" starts when you have to handle more complex user interaction,
like dragging a volume slider. And when you allow non-rectangular
regions. The math to detect if a coordinate is inside or outside an
arbitrary shape is quite interesting.

You don't need any fancy math at all. All you need is a bitmap with a
mask. A 1 bit at a particular position indicates the click was inside
the region.

/Thomas
 
S

steven robinson

BTW: Did someone tell you that it is impossible to have anything else
than rectangular windows in Java?

yes, I was told I could only have rectangular windows. If thats not
true I would really like to know how to create oval, circular or
rounded corner rectangular windows. Any ideas?

Steve


Harald Hein said:
steven robinson said:
Thats exactly it, any ideas how to approach this? Adding a gif image
to a panel should be easy, if thats allowed in awt.Panel? but how do
you define a an area that implements mouseListener ?

You listen to all mouse events on the panel. Then you write your very
own code which tests where the event occured. Then you go through your
very own list of regions and try to find a region which encloses the
coordinate of a mouse event. For each region and type of mouse event
you have implemented a corresponding handler. E.g. "if a click appeared
in [4, 8, 12, 6], start playing an MP3".

The "fun" starts when you have to handle more complex user interaction,
like dragging a volume slider. And when you allow non-rectangular
regions. The math to detect if a coordinate is inside or outside an
arbitrary shape is quite interesting.

What you will end up with is your very own event dispatching system.

Or you try to find some implementation of this on the web. Or you come
to your senses, and just build a conventional AWT or Swing GUI. If you
go for Swing, you can at least create your own PLAF. Not as flexible as
a gif, but simpler.

BTW: Did someone tell you that it is impossible to have anything else
than rectangular windows in Java?
 
S

steven robinson

You don't need any fancy math at all. All you need is a bitmap with a
mask. A 1 bit at a particular position indicates the click was inside
the region.

/Thomas


That sounds like what I want to do, how do I do that? any tips would be appreciated.

Thanks
Steve
 
A

Andrew Thompson

steven robinson said:
yes, I was told I could only have rectangular windows. If thats not
true I would really like to know how to create oval, circular or
rounded corner rectangular windows. Any ideas?
....
That sounds like what I want to do, how do I do that?
..any tips would be appreciated.

1) comp.lang.java.gui is a group more geared to what
you are doing.

2) search c.l.j.g for the FAQ and cast an eye over that.
 
T

Tim Tyler

Harald Hein said:
The "fun" starts when you have to handle more complex user interaction,
like dragging a volume slider. And when you allow non-rectangular
regions. The math to detect if a coordinate is inside or outside an
arbitrary shape is quite interesting.

Fortunately, it's all done for you in the standard library - see:

Shape.contains(x,y).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top