verzus
asked on
drawing image and imageObserver
I'm working on an application where the paintComponent method leaves it to other methods (in other classes) to do the actual drawing. Something like:
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
otherClass1.draw(g2, someArea);
...
etc etc
In one of those classes I want to draw an image:
public void draw(Graphics2D g2, Rectangle2D myArea){
g2.drawImage(myImage, myArea.getX(), myArea.getY(), null);
The thing is a null value is not accepted as ImageObserver. Nor did sending a (this) reference from the JPanel with the paint method help. It's a small image and I don't care about Tracker.
The reason i don't want to paint in different Panels is I want to print the contents easily.
cheers
/vs
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
otherClass1.draw(g2, someArea);
...
etc etc
In one of those classes I want to draw an image:
public void draw(Graphics2D g2, Rectangle2D myArea){
g2.drawImage(myImage, myArea.getX(), myArea.getY(), null);
The thing is a null value is not accepted as ImageObserver. Nor did sending a (this) reference from the JPanel with the paint method help. It's a small image and I don't care about Tracker.
The reason i don't want to paint in different Panels is I want to print the contents easily.
cheers
/vs
Does "One of those classes" inherit from Component (way up the hierarchy)?
If not, they will not implement the ImageObserver interface.
If that is the case you can either;
supply a reference to the class with the overridden paintComponent method
OR
just create a new Component in your draw method and supply that as the ImageObserver reference
OR
implement the ImageObserver interface in the class with the draw method.
If not, they will not implement the ImageObserver interface.
If that is the case you can either;
supply a reference to the class with the overridden paintComponent method
OR
just create a new Component in your draw method and supply that as the ImageObserver reference
OR
implement the ImageObserver interface in the class with the draw method.
ASKER
I am not getting any wizer...
The image drawing class does not inherit anything. I tried sending a reference from the class with paintComponent, the result was the same, only:
cannot resolve symbol :
method drawImage(java.awt.Image,d ouble,doub le,<nullty pe>)
instead of
method drawImage(java.awt.Image,d ouble,doub le,myClass Name)
even tried implementing ImageObservera and passing the this-reference.
and:
ImageObserver imageObserver;
g2.drawImage(legendMapImag e, myArea.getX(), myArea.getY(), imageObserver);
gave me:
cannot resolve... method
drawImage (java.awt.Image,double,dou ble,java.a wt.image.I mageObserv er)
What do you mean by creating a new component? Any component? A new JLabel an pass that as reference?
The image drawing class does not inherit anything. I tried sending a reference from the class with paintComponent, the result was the same, only:
cannot resolve symbol :
method drawImage(java.awt.Image,d
instead of
method drawImage(java.awt.Image,d
even tried implementing ImageObservera and passing the this-reference.
and:
ImageObserver imageObserver;
g2.drawImage(legendMapImag
gave me:
cannot resolve... method
drawImage (java.awt.Image,double,dou
What do you mean by creating a new component? Any component? A new JLabel an pass that as reference?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, it wasn't the imageObserver, it was the double values...
Why not?