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.
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.
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
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"?
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, 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?
Joined: Jan 14, 2004
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.