I was developing a project where I need to override the paint () method, but the paint () method only receives a Graphics object as a parameter. What I need to do is create a paint method that takes two parameters and uses Image objects belonging to the Other object to draw on the screen, for example '
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class Desenho extends JPanel{
public void paint(Graphics g, Outro o){
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(o.getImagem(), o.getX(), o.getY(), null);
}
}
After this I would need to call this method and pass the parameters.
Outro o2 = new Outro();
Graphics gh = new Graphics(); // Não posso criar um Graphics assim pois Graphics é classe abstrata.
paint(gh, o2);
The problem is that I can not create a Graphics object outside the method and thus I can not create the method with more than one argument.
If anyone knows how to do this or has a different idea that reaches the same result and can help me, thank you in advance.