Some trouble with paintComponent()

2019-08-19 06:42发布

问题:

Following a previous message, I have another problem (what a newbie).

I have a class Fenetre, containing the following code (and more) :

@Override
public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(!init)
        {
            afficher= new Afficher(g);
            init = true;
        }
         g.setColor(Color.white);
         g.fillRect(0, 0, 1000, 500);

         if(lol)afficher.setMapOne(2,2,6);
         System.out.println("paintComponent : "+lol);

         afficher.checkChanges(g);
}

public void setLol(boolean n)
{
    lol = n;
    System.out.println("setLol : "+lol);
}

And in my principal class, GameEngine :

public void etablir(String secondWord)
    {
          System.out.println("Etablir ?");
          fenetre.setLol(true);
          fenetre.repaint();
    } 

It is pretty simple, but let me explain a bit:

afficher.checkChanges(g); checks the map (the goal is to draw an isometric map), a table like short[][], and displays it.

if(lol)afficher.setMapOne(2,2,6); Sets a certain part of the map in GREY, instead of BROWN (to show if the code worked well; I will see it immediately)

When I launch it:

  1. The map appears, great.
  2. I write "etablir", it launchs the methods etablir(), it prints "Etablir ?" in System.out
  3. lol is set as true
  4. ... And that's all. No repaint, no re-paintComponent, no update of the map.

So, to repaint by relauching paintComponent(Graphics g), is there an easy way? I'm sure I missed something simple.