Suppose I want to create a method that has all the instructions to draw its specificities.
public class Martian
{
private int eyes;
private int legs;
// Only arguments are the starting co-ordinates of a Graphics object
public void draw(int x, int y)
{
// draw a Martian
}
}
In a separate file, I create a JFrame that needs to instantiate the object then within JFrame's paint()
method I draw the object.
The only way I've been drawing objects is through paintComponent(), how can I create my own draw method without using that method?
Or how can I incorporate paintComponent()?
Eventually I want paint
method to look like:
paint(Graphics g)
{
// Surely more steps
aMartian.draw(x, y);
}
Clearly a total noob, I would really appreciate ANY help on how to start this.
draw
method should probably have aGraphics
parameter and paint on it . – Arnaud Nov 12 '18 at 9:27Graphics
object in thedraw
method without usingsuper.paintComponent(g)
? – J. Doobie Nov 12 '18 at 9:38paintComponent
, you may callaMartian.draw(x, y, g)
. – Arnaud Nov 12 '18 at 9:43BufferStrategy Java
. Maybe with some reading you can solve it yourself. – Chiff Shinz Nov 30 '18 at 15:07