public class AlienDrawer { public AlienDrawer(Graphics g) { this.g = g ; } public void drawStuff() { g.drawRect(10, 10, 20, 20) ; } } public class MyPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g) ; AlienDrawer draw = new AlienDrawer(g) ; draw.drawStuff() ; } }