cagin
cagin

Reputation: 5920

Java : repaint is undefined in class

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

Answers (2)

Reimeus
Reimeus

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

Maroun
Maroun

Reputation: 95968

repaint() method is part of java.awt.Component.Point is not a subclass of java.awt.Component. You can't use it that way.

Upvotes: 2

Related Questions