ランダムな場所に2つの画像を表示し、毎秒変更するプログラムを作成しようとしています。ただし、私の問題は、画像を再描画しても、前の位置の画像が表示されることです。
必要に応じて、WTK2.52を使用しています。
public void run()
{
while(true)
{
dVert = rand.nextInt(136);
dHorz = rand.nextInt(120);
rVert = 136 + rand.nextInt(136);
rHorz = 120 + rand.nextInt(120);
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("Error");
}
repaint();
}
}
public void paint(Graphics g)
{
int width = this.getWidth() / 2;
int height = this.getHeight() / 2;
g.drawImage(imgR, rVert, rHorz, g.TOP | g.LEFT);
g.drawImage(imgD,dVert,dHorz,g.TOP | g.LEFT);
//g.drawString(disp, width, 50, Graphics.TOP | Graphics.HCENTER);
//g.drawString(centerMsg,width, height, Graphics.TOP | Graphics.HCENTER);
System.out.println(width);
System.out.println(height);
}