Reputation: 5920
I am new on java. I want to create an abstract factory in java. I have a class point
and I want to extend other classes ( circle, rectangle
) from this.
Here is my code. It says repaint is undefined..
import javax.swing.*;
import java.awt.*;
import java.awt.Component;
import javax.swing.*;
public class Circle extends Point {
public void Draw() {
repaint();
}
public void paint(Graphics g) {
g.drawOval(this.x, this.y, 10, 10);
}...
Upvotes: 0
Views: 1302
Reputation: 159784
The class Point
simply encapsulates an x
and y
integer value. It is not derived from java.awt.Component
so therefore repaint
cannot be invoked.
For custom painting in Swing extend JComponent
or JPanel
and override paintComponent
rather than paint
. Remember to invoke super.paintComponent(g)
.
See: Performing Custom Painting
Upvotes: 3