how can i paint in a panel with two different classes?

You need to have one class which will extend JPanel (fenetre) and array/list of objects (in your case Lemmings and Carreau list) both of those objects should have a void function which you call and pass the graphics so:

public class Lemmings{

public void draw(Graphics2D g2d)
{
//draw something here
}
}

Then in fenetre in paint function you just call the function draw on each of objects in array

public class Fenetre extends JPanel{
List<Lemmings> lems = new ArrayList<>(); //add the objects into this one
    @Override
    public void paint(Graphics g)
    {
    Graphics2D g2d = (Graphics2D)g;
         for(int i = 0; i < lems.size(); i++)
         {
              lems.get(i).draw(g2d);
         }
    }
    }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top