简体   繁体   中英

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);

}...

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM