これは、特定のx座標とy座標で円の形を作成する私のクラスです。同様に、私は別の同じクラスを持っていますが、x座標とy座標の位置が異なります。各クラスのオブジェクトを1つ作成し、それらをJFrameの特定の位置に表示したいと思います.2番目のオブジェクトをJFrmaeに追加すると、1番目のオブジェクトが上書きされます。JFrmaeのレイアウトを変えてみましたが、うまくいきませんでした。
class Ballbewegung2 extends JPanel implements Runnable {
int x_pos = 10; int y_pos = 100; int radius = 20;
public void init() {
setBackground (Color.blue); }
public void start () {
Thread th = new Thread (this);
th.start (); }
public void run () {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (true) {
x_pos ++; if(x_pos >= 400) x_pos = 10;
repaint();
try { Thread.sleep (20); }
catch (InterruptedException ex) {} thread.currentThread().setPriority(Thread.MAX_
PRIORITY); } } public void paint (Graphics g) { g.setColor (Color.red); g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius); } }