g00se, on 12 May, 2009 - 07:17 AM, said:
Dont' worry - there'll be plenty of work to do - even if you do use the existing Shape implementations ;-)
I know how to use the existing shape implimentations, as I said. And we have to use the Graphics class. I assume you're referring to drawOval() darRect() drawLine... etc. etc.
Here is my hang-up that I can't get past -- and I have been busting my ass. I can't express my difficulty better than this. I'm just writing this quickly -- my concern here is to focus on the one point in question, so just assume height and width are equal to each other, etc. etc.
public class Circle {
private x;
private y;
private width;
private height;
public Circle(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
public drawCircle() {
g.drawOval(x,y,width,height);
}
}
}
Now I want to use this Circle class to place a circle on the JPanel called canvasPanel inside this class:
public class Canvas extends JFrame {
private JPanel canvas = new JPanel();
private JButton draw = new JButton("draw");
public Canvas() {
setLayout(new BorderLayout());
add(draw, BorderLayout.NORTH);
add(canvas, BorderLayout.SOUTH);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
draw.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// STICKING POINT. HOW THE HELL DO I TELL IT TO PUT THE CIRCLE HERE????
// PLEASE HELP!!
}
}
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// if I remember right, this causes an error cannot find symbol paintComponent(g)
}
}
If someone could please help me fix this code, my questions would be answered and I could work from this model. I'm not trying to cheat here -- I've been busting my butt on my own for hours over this. I have a genuine interest in learning Java. I'm not just trying to 'get through'. I'm just stumped.
Thanks!
Irongleet
This post has been edited by Charlie IronGleet: 12 May 2009 - 11:18 AM

New Topic/Question
Reply




MultiQuote

|