
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class MultiRes2 extends Frame {

    private static final int W = 100, H = 100;

    private static final BufferedImage
        IMG1 = generateImage(W / 2, H, Color.RED),
        IMG2 = generateImage(W, H / 2, Color.RED),
        IMG3 = generateImage(W, H, Color.GREEN);

    private static final BaseMultiResolutionImage IMG =
        new BaseMultiResolutionImage(new BufferedImage[]{IMG1, IMG2, IMG3});

    public MultiRes2() {
        EventQueue.invokeLater(this::CreateUI);
    }

    private void CreateUI() {

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) { dispose(); }
        });
        setSize(W, H);
        setResizable(false);
        setVisible(true);

        System.out.println("base image is IMG1: " + IMG.getResolutionVariant(W, H).equals(IMG1));
        System.out.println("base image is IMG2: " + IMG.getResolutionVariant(W, H).equals(IMG2));
        System.out.println("base image is IMG3: " + IMG.getResolutionVariant(W, H).equals(IMG3));
    }

    private static BufferedImage generateImage(int w, int h, Color c) {

        BufferedImage image = new BufferedImage(
            w, h, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(c);
        g.fillRect(0, 0, w, h);

        return image;
    }

    @Override
    public void paint(Graphics gr) {
        Graphics2D g = (Graphics2D) gr;
        if (g != null) { g.drawImage(IMG, 0, 0, this); }
    }

    public static void main(String[] args) {
        new MultiRes2();
    }
}
