0

I have an Observer which my Window class. I have a Model class that extends Observable containing an ImagePanel class, and a Controller class. I do add to my Model instance the window.

My problem is : I do a print before model.notifyObservers(), it works, another print after this call, it works too. But the print inside the update() of my Observer method doesn't show up?

From my controller I call this setImage method:

public void setImage(File file)
    {
        try
    {
        image = ImageIO.read(file);
        fileName = file.getPath();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
    width = image.getWidth();
    height = image.getHeight();
    imageType = image.getType();
    pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);
    this.setLocation(1000, 500);
    System.out.println("ALRIGHT2");
    model.change();
    if (model.hasChanged())
    {
        System.out.println("ALRIGHT5");
        model.notifyObservers();
        System.out.println("ALRIGHT6");
    }
}

This is the update method of my Observer:

public void update(Observable o, Object arg) {
    System.out.println("ALRIGHT3");
    image_panel.repaint();
    scrollPaneImage.repaint();
}

And I did this in my Observer constructor: model.addObserver(this);

What's wrong? I assume that the image I chose thanks to a JFileChooser doesn't update because this method is not called...

blondie
  • 35
  • 1
  • 6
  • You don't show where you create an instance of your observer, meaning how are we supposed to know when it's being added? Please provide more information. – Vince Apr 26 '14 at 20:58
  • Yes we need more info in order to help you. – Martin Serrano Apr 26 '14 at 21:09
  • I create the instance of my Observer in my main function, in my entry point of my program. The class containing this main function is in another package than the one containing my observer, if it can help. – blondie Apr 26 '14 at 21:37
  • Resolved ! Sorry for the inconvenience, my JScrollPane contains a JLabel which itself contains an ImageIcon and I forgot to update this ImageIcon... – blondie Apr 26 '14 at 22:52

1 Answers1

0

Resolved ! Sorry for the inconvenience, my JScrollPane contains a JLabel which itself contains an ImageIcon and I forgot to update this ImageIcon...

blondie
  • 35
  • 1
  • 6