• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI adding a drawing to a panel

 
Edward Spencer Spencer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a class called panel where I need to add four lights that need to change color. The lights are within a rectangle. But I can't figur out how to add a drawing to a panel and i'm only allowed to use to classes not including the class for the listener.
Main is in a seperate class called Light
I'm okay with the listener class exept how to access the drawing from it.

For example (It's a dogs breakfast at this point--sorry it wont run but will give you an idea of what I'm trying to do.
Thanks!!!



 
Les Morgan
Rancher
Posts: 717
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread should give you want you need: http://www.coderanch.com/t/657015/GUI/java/Moving-oval
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just make up Graphic objects. You need to paint with the Graphic object passed into the paintComponent(...) method. I suggest you start all over.

Read the section from the Swing tutorial on Custom Painting for explanations and working examples.

Download the examples and test them. Then at the end of the tutorial use the final example as a starting point and make your changes.
 
Edward Spencer Spencer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob thank you. the tutorial helped a lot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!