我正在自学 AP Java 课程,我只需要一些快速帮助。我对paintComponent 有这个问题。我总是收到消息来覆盖它并为它创建其他东西。这是我的那个类的代码:
package pkghello;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
/**
*
* @author ap
*/
public class RectangleComponent extends JComponent {
public void paintComponent (Graphics g) //It only highlights "paintComponent"
{
Graphics2D g2 = (Graphics2D) g;
//
Rectangle box = new Rectangle (5,10,20,30);
g2.draw(box);
box.translate(90, 90);
box.setSize(150,150);
g2.draw(box);
}
}