So I have a class called Creature. These guys have properties that will determine how they are drawn, but right now they just contain an (x,y) for where they are to be drawn. I would just like to draw a circle where each is located. Easy enough, I suppose, but I'm not getting it.
Here's what I have so far:
Expand|Select|Wrap|Line Numbers
- public class Main {
- public static void main(String[] args) {
- Creature dude = new Creature(20, 40);
- MakeWorld world = new MakeWorld();
- }
- }
Expand|Select|Wrap|Line Numbers
- import java.awt.*;
- import javax.swing.*;
- public class MakeWorld {
- MakeWorld(){
- JFrame frame = new JFrame("title");
- frame.getContentPane().add(new MyComponent());
- frame.getContentPane().setBackground(Color.WHITE);
- frame.setSize(Globals.FRAME_WIDTH, Globals.FRAME_HEIGHT);
- frame.setVisible(true);
- }
- class MyComponent extends JComponent
- {
- @Override
- public void paint(Graphics g)
- {
- Graphics2D g2d = (Graphics2D)g;
- g2d.fillOval(10, 20, 2, 2);
- }
- }
g2d.fillOval(dude.x, dude.y, 2, 2)?
It doesn't seem like I can add any parameters to paint(); so I can't even reference "dude".
Is there a way I could make a function like:
dude.draw() that I could call outside of the paint() function?
Thanks,
bd