Adding More Animations on a Single JFrame

No one could help me on another post but here we go:

If anyone can help with this code I basically started with adding the Spooky class like I say then went to the top of the code and got stuck on the getContentPane which isn’t allowing me to add 2 lines of that to add 2 of the shapes to animated…

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class test extends JFrame {

   public Gunman g = new Gunman();
   public Spooky j = new Spooky();

   public static void main(String[] args) {
      test t = new test();
      t.setSize(800, 600);
      t.setVisible(true);
      t.getContentPane().add(t.g);
      t.setBackground(Color.DARK_GRAY);

      while (true) {
         t.g.x = t.g.x + 1;
         t.g.y = t.g.y + 1;
         t.repaint();
         try {
            Thread.sleep(50);
         } catch (InterruptedException e) {
         }
      }
   }

   public void paintComponent(Graphics g) {
      g.clearRect(0, 0, 800, 600);
   }
}

class Gunman extends JComponent {

   // private static final long serialVersionUID = 1L;
   public int x = 20;
   public int y = 20;
   public int width = 20;
   public int height = 20;

   public void paintComponent(Graphics g) {
      g.setColor(Color.blue);
      g.fillRect(x, y, width, height);
   }
}
   class Spooky extends JComponent {
      public int x = 30;
      public int y = 30;
      public int width = 40;
      public int height = 50;

      public void paintComponent(Graphics g) {
         g.setColor(Color.RED);
         g.fillOval(x, y, width, height);
      }
   }

---- ORIGINAL CODE ----

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class Test extends JFrame {

    public Gunman g = new Gunman();

    public static void main( String[] args ) {
        Test t = new Test();
        t.setSize( 800, 600 );
        t.setVisible( true );
        t.getContentPane().add( t.g );

        while ( true ) {
            t.g.x = t.g.x + 1;
            t.g.y = t.g.y + 1;
            t.repaint();
            try {
                Thread.sleep( 100 );
            } catch ( InterruptedException e ) {
            }
        }
    }

    public void paintComponent( Graphics g ) {
        g.clearRect( 0, 0, 800, 600 );
    }
}


class Gunman extends JComponent {

    private static final long serialVersionUID = 1L;
    public int x = 10;
    public int y = 10;
    public int width = 8;
    public int height = 10;

    public void paintComponent( Graphics g ) {
        g.setColor( Color.red );
        g.fillRect( x, y, width, height );
    }
}

^^ You should see where I was going with it

Apologies for posting simular on another topic I made but I didn’t get any response on that reply. I’ve learned a hell of a lot though from you people over the last week with helpful links, I’m glad I’ve joined! :slight_smile: