This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Trying to make custom GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trying to make custom GUI" Watch "Trying to make custom GUI" New topic
Author

Trying to make custom GUI

Khrystyne Alcala
Greenhorn

Joined: Oct 09, 2005
Posts: 8
I am trying to find out if there is way to use a custom image as a GUI, and then place menus and menuitems on it. I am a second semester student and I'm trying to make this my final project for the quarter. Any help would be greatly appreciated.

CodeOn
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to Swing/AWT...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
What do you mean by using "a custom image as a GUI"? You can easily add a background image to a JFrame or JPanel. However, it will not be interactive. Of course, you can make it interactive, with enough work, but I'm willing to bet that there is an easier way to go about this. Perhaps you can explain what kind of image you have and how you want to "use it as a GUI"?

Layne


Java API Documentation
The Java Tutorial
Khrystyne Alcala
Greenhorn

Joined: Oct 09, 2005
Posts: 8
Thank you for responding Mr Lund,
I have an image(.jpg), of a car stereo with a picture screen that is sitting above it, I would like to use this image as my GUI interface and have it interact with the user. For example, clicking different areas of the "stereo" such as the volume button and the application responds with the volume increasing or decreasing. I know how to add an image as a background using JFrame, I just don't know how to make it interactive. I can't seem to find ANY references to this subject on the Internet or in any of my books.
Right now I'm reading:
HEADFIRST JAVA, JAVA PROGRAMMING TODAY(this is my class text),and THE COMPLETE REFERENCE JAVA J2SE 5 EDITION.
Can you help me??
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Create a window add the background image to it and now u have your setup.

��..clicking different areas of the "stereo" such as the volume button�..�

Just put normal jbuttons to those places.

(Note :- I am not sure of the spelling of the method names sorry)

setContenfilled - false
saintBorder � false
setOpeacity � false
now add image icon to the button. Now u will see u have your custom GUI

but if u test your GUI carefully u will find that thought your buttons look like a cercal it is not so.

To fix it I still done know (i have not tryed yet)I have post a similar question on this forum there is a answer to it
http://www.javaranch.com
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Khrystyne Alcala
Greenhorn

Joined: Oct 09, 2005
Posts: 8
Sameera, I will try what you have suggested. I am very curious about the response you got when you posted your similar question, the link you provided was invalid.

Craig, thank you for the code, when I compiled it, it drew 3 shapes and each changed color when I hovered over it, however, my problem is taking a picture from an outside source and making it an interactive gui. Can you help me with this problem?


Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Yes. What I would do is to identify the areas on the image you want to use, construct geometry primitives that match the image areas that you want to make interactive and use them in your event code. I tried to show how to build everything. The main thing you need to do is set up the primitives. You can do this by drawing your image the way you want it on your component. Then draw each primitive over the image with the size and location that suits you. For the primitives you can use things like rectangles and ellipses. The Polygon class is handy for shapes with straight–line boundries and GeneralPath is suited for shapes with straight and/or curved lines. You can find more information about using primitives in the 2D Graphics tutorial Lesson: Displaying Graphics with Graphics2D, especially the sections on "Stroking and Filling Graphics Primitives" and "Constructing Complex Shapes from Geometry Primitives".

I used a MouseMotionListener to make the illustration easy to use. You can replace it with a MouseListener and override 'mousePressed' to receive the user input for your program.
 
GeeCON Prague 2014
 
subject: Trying to make custom GUI