我正在做一個自學AP Java課程,我只需要一些快速幫助。我對paintComponent有這個問題。我總是收到消息來覆蓋它併爲它創建其他東西。這是我的代碼:開始Java(幫助)
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);
}
}
你的問題是什麼? – Raptor