Results 1 to 4 of 4
Thread: Making a Drawing Class
- 02-09-2013, 05:25 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Making a Drawing Class
I would like to make a drawing class in which methods for drawing different shapes are implemented so that these methods can be used in different classes. So if the class was called Draw, then using the a method in a different class could go something like this: Draw.circle(parameters go here). The issue I am running into is that using paintComponent means that I can't separate drawing the different shapes into different methods and therefore one method has all the shape drawing and thus I can't call a particular method to to draw a particular shape. I am a physics student, so when I I want to draw shapes( to represent different grid structures) it is always within the context of a long algorithm and I would like to get all the drawing code in one class ready for use. I do not want everything lumped into paintComponent method. Help would be greatly appreciated.
- 02-09-2013, 06:45 PM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Re: Making a Drawing Class
Sure you can. The paintComponent method can call methods from within it, and in fact this is often done. You can even have it select which methods it wishes to call by having it respond to the "state" of the object, meaning give it logical blocks such as if blocks that will allow it to call a variety of methods depending on what is held by the object's variables.
Another option that is worthwhile looking into is having your paintComponent method draw a BufferedImage (if it's not null), and have your other methods change what is drawn on this image. Perhaps this could be what would work best for your purposes....and therefore one method has all the shape drawing and thus I can't call a particular method to to draw a particular shape. I am a physics student, so when I I want to draw shapes( to represent different grid structures) it is always within the context of a long algorithm and I would like to get all the drawing code in one class ready for use. I do not want everything lumped into paintComponent method. Help would be greatly appreciated.
- 02-10-2013, 05:11 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Making a Drawing Class
I can't seem to picture how exactly the BufferedImage scenario would work. Please excuse, my ignorance.
- 02-11-2013, 01:39 AM #4
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Re: Making a Drawing Class
Have a look through this and other forums to get some good (and not-so-good) examples of working with BufferedImages. For instance, have a look at the code in this answer here.
Similar Threads
-
Making a class to use in a project
By traisjames in forum New To JavaReplies: 6Last Post: 10-26-2012, 01:22 AM -
loading images from seperate class and drawing them
By ccub in forum Java 2DReplies: 1Last Post: 11-06-2011, 11:18 PM -
Drawing an object in my canvas class, the object is created in a separate class
By Hornfreak in forum AWT / SwingReplies: 3Last Post: 05-02-2011, 04:37 AM -
Drawing multiple instances of one class with an array
By Grimmjow in forum New To JavaReplies: 16Last Post: 05-22-2010, 03:51 AM -
Making a drawing tool
By Mike_H in forum New To JavaReplies: 1Last Post: 03-16-2010, 12:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks