The repaint () method is not recognized within a [closed] timer

1

This code works for me in the constructor of my jframe, it prints me an image in a label. Now I have a checkbox and when pressed I want to put the image for a second because of the timer but I mark error the repaint () method asks me the Netbeans create the method within the actionlistener, I do not know how to fix it. here my code in the action performed of the checkbox:

    private void simulacionActionPerformed(java.awt.event.ActionEvent evt) {                                           
        if(simulacion.isSelected()){
            t = new Timer(1000,new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
            ImageIcon imagen0 = new ImageIcon("src/imagenesmedidor/menora50.jpg");
            Icon icono0 = new ImageIcon(imagen0.getImage().getScaledInstance(medidor.getWidth(),medidor.getHeight(), Image.SCALE_DEFAULT));
            medidor.setIcon(icono0);
            this.repaint();
            }
        });

        }
    
asked by Raul Alberto Urtecho Magaña 09.03.2017 в 00:03
source

1 answer

0

You are calling this from an anonymous class (different from the one you implement or extend from JFrame).

To refer to the class and the object itself, you would have to replace this.repaint(); with nombreClase.this.repaint(); , "nombreClass" replace it with the name of your class, the one that implements JFrame, so you will recognize this the way you want, if I have not misunderstood.

    
answered by 09.03.2017 в 13:19