• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trying to make custom GUI

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Khrystyne Alcala
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic