import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class SomeShape extends JPanel {
protected static float width;
protected BasicStroke line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
}
class Oval extends SomeShape {
Oval(float width) {
this.width = width;
line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
repaint();
}
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D)g;
int i = 10;
super.paint(g);
g.setColor(Color.blue);
g.drawOval(90, 0+i, 90, 90);
System.out.println("paint()");
}
}
public class FinalVersionFactory {
JFrame f = new JFrame();
Container cp = f.getContentPane();
float width = 0;
SomeShape getShape() {
return new Oval(width++); //I want to paint this oval when I call getShape() method
}
public FinalVersionFactory() {
f.setSize(400, 400);
// cp.add(new Oval()); without adding
cp.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
getShape();
}
});
f.setVisible(true);
}
public static void main(String[] args) { new FinalVersionFactory(); }
}
I need help. When I cliked on the JFrame nothing happened. I want to call paint() method and paint Oval when I create new Oval() object in getShape(). Can you correct my mistakes? I tried everything...Thank you.