import animals.Animal;
import animals.Background;

import modules.AnimalModule;
import modules.Createobject;

import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class DrawPanel extends JPanel implements ActionListener, MouseMotionListener {
private final int PANEL_WIDTH;
private final int PANEL_HEIGHT;
private final int TIMER_DELAY;
private Timer timer;
private BufferedImage backgroundImage;
private ArrayList animals; // List of animals
private ArrayList backgrounds; // List of animals
private int ticksFromStart = 0;
private KeyHandler keyHandler;


public DrawPanel(final int width, final int height, final int timerDelay, List<AnimalModule> modules) {
    this.PANEL_WIDTH = width;
    this.PANEL_HEIGHT = height;
    this.TIMER_DELAY = timerDelay;

    timer = new Timer(timerDelay, this);
    timer.start();
    this.setFocusable(true);
    this.requestFocusInWindow();

    this.keyHandler = new KeyHandler();

    this.addKeyListener(keyHandler);


    setBackground(Color.green);

    animals = new ArrayList<>(); // Initialize the list of animals
    backgrounds = new ArrayList<>();

    Createobject.createAnimals(animals, getBackground(), modules);
    Createobject.createBackground(backgrounds, getBackground(), modules);

    // Add mouse motion listener
    addMouseMotionListener(this);
}

@Override
protected void paintComponent(final Graphics gr) {
    super.paintComponent(gr);
    Graphics2D g2d = (Graphics2D) gr;
    if (backgroundImage != null) {
        g2d.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
    } else {
        // Fill the background with the panel's color if the image is unavailable
        g2d.setColor(getBackground());
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    for (Background background : backgrounds) {
        background.draw(g2d);
    }

    for (Animal animal : animals) {
        animal.draw(g2d);
    }
}


@Override
public void actionPerformed(final ActionEvent e) {
    if (e.getSource() == timer) {
        ticksFromStart += 2;
        repaint();
    }
    if (keyHandler.isLeftPressed()) {
        for (Background background : backgrounds) {
            background.leftMove();
        }
        repaint();
    }
    if (keyHandler.isRightPressed()) {
        for (Background background : backgrounds) {
            background.rightMove();
        }
        repaint();
    }

}

@Override
public void mouseDragged(MouseEvent e) {
    // Optional: Implement if needed
}

@Override
public void mouseMoved(MouseEvent e) {
    for (Animal animal : animals) {
        if (animal.getMove()) {
            animal.setPosition(e.getX(), e.getY());
            updateAnimalsLookingAt(animal);
        }
    }
    repaint();
}

private void updateAnimalsLookingAt(Animal forMouseAnimals) {
    // Update the direction animals are looking at the sparrow
    for (Animal animal : animals) {
        if (animal.getLookAt()) {
            animal.lookAt(forMouseAnimals.getXCenter(), forMouseAnimals.getYCenter());
        }
    }
}
} package modules;

import animals.Animal;
import animals.Background;

import java.awt.Color;
import java.util.ArrayList;

public interface AnimalModule {
    void createAnimals(ArrayList<Animal> animals, Color background);
    void createBackground(ArrayList<Background> backgrounds);
}package modules;

import animals.Animal;
import animals.Background;
import bear.Bear;
import bird.Sparrow;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

public class Createobject {
    public static void createAnimals(ArrayList<Animal> animals, Color background, List<AnimalModule> modules) {
        for (AnimalModule module : modules) {
            module.createAnimals(animals, background);
        }
    }

    public static void createBackground(ArrayList<Background> backgrounds, Color background, List<AnimalModule> modules) {
        for (AnimalModule module : modules) {
            module.createBackground(backgrounds);
        }
    }
}package animals;

import java.awt.*;

public abstract class Animal {
    public int x;
    public int y;
    public int width;
    public int height;
    public boolean lookAt = false;
    public boolean move = false;
    public Color primaryColor;
    public Color secondaryColor;


    public Animal(int x, int y, int width, int height, Color primaryColor, Color secondaryColor) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.primaryColor = primaryColor;
        this.secondaryColor = secondaryColor;
    }


    public abstract void lookAt(int targetX, int targetY);

    public abstract void draw(Graphics2D g);

    public abstract void setPosition(int x, int y);

    public abstract boolean getLookAt();

    public abstract boolean getMove();

    public abstract int getXCenter();

    public abstract int getYCenter();


}я хочу, чтобы пользователь мог инициализировать объекты во время работы программы