Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to make custom GUI

 
Khrystyne Alcala
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Khrystyne Alcala
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Khrystyne Alcala
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic