Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Swing / AWT / SWT
repainting
Chris Roberts
Greenhorn
Posts: 8
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I was working on a program and I could not figure out how to change the
background color of the screen when I tried to repaint it. Here's my code:
public class drawingPanel extends JPanel { public final static int CIRCLE = 1, SQUARE = 2; private int shape; Dimension mySize = new Dimension(300, 300); protected void paintComponent(Graphics g) { super.paintComponent(g); Vector<Shape>Storage = new Vector<Shape>(); Circle temp; for(int i = 0; i<Storage.size(); i++) { System.out.println("Storing a circle"); temp = (Circle)Storage.elementAt(i); g.setColor(Color.blue); g.fillOval(temp.getX(), temp.getY(),(int)( 2*temp.getRadius()), (int)(2*temp.getRadius())); } } // override getPreferredSize public Dimension getPreferredSize() { return mySize; } // set shape value and repaint drawingPanel public void draw(int shapeToDraw) { shape = shapeToDraw; repaint(); } }
Dirk Schreckmann
Sheriff
Posts: 7023
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Moving this to the Swing / AWT / SWT / JFace forum...
[
How To Ask Good Questions
] [
JavaRanch FAQ Wiki
] [
JavaRanch Radio
]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Mouse events
Trying to make a shape.
MousePressed
Graphics 2d Object and Scroll Bar Issue
JFrame
More...