1
class BiomeViewComponent extends JComponent {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
int xpos=300;
int ypos=300;
g.setColor(Color.yellow);
Random r = new Random();
int spread = r.nextInt(2)+1;
System.out.println(spread);
if (spread==1){
xpos=xpos+50;
g.setColor(Color.yellow);
g.fillRect(xpos,ypos,50,50);
}
else{
ypos=ypos-50;
g.setColor(Color.yellow);
g.fillRect(xpos,ypos,50,50);
}
}
}
我使用了paintComponent腳本的接受答案,就像上面的代碼,它的工作,但現在的問題是我如何使它不止一次繪製?使用PaintComponent重繪()
謝謝你!我感謝幫助! – BaconMan97
好的問題...我現在如何讓它重漆? – BaconMan97