Reputation: 779
is it a bad idea to pass other parameters besides (Graphics g) to a method that draws an object to a gui? For example if you had:
A a = new A()
paintComponent(Graphics g) {
a.draw(g, something);
}
public class A {
draw(Graphics g, Something something) {
g.drawImage(something.getSomething(somethingElse), 0, 0, null);
}
}
Is this proper? Not sure why but I feel like methods dealing with graphics should be streamlined to only deal with graphics, in which case the "draw" method would have to be put in the "Something" class so it could reference the necessary stuff directly as a field or something without the extra parameter.
Upvotes: 0
Views: 48
Reputation: 347244
It depends on what it is you're trying th archive. Often when painng, I will set up context/support paint methods that I want to call repeatedly to build up the final image (think layers), this allows me to add/remove layers as I need to do & isolates each part.
For example, painting highlights. Thy generally don't care to much about the external context, but need to know how they are to be applied
I've also used painters
like those in the SwingX project
Just my thoughts on the subject
Upvotes: 1
Reputation: 62
It's probably better if the "something' could be a property or set of properties of A, but if it isn't related to the object in any way, then there's probably no better way to solve the problem.
Upvotes: 0