package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
    private static final int MW = 300;
    private static final int MH = 200;
    private final JCheckBox checkbox = new JCheckBox("Fixed aspect ratio, Minimum size: " + MW + "*" + MH);

    private MainPanel() {
        super(new BorderLayout());
        EventQueue.invokeLater(() -> {
            Container c = getTopLevelAncestor();
            if (c instanceof JFrame) {
                JFrame frame = (JFrame) c;
                frame.setMinimumSize(new Dimension(MW, MH)); //JDK 1.6.0
                frame.addComponentListener(new ComponentAdapter() {
                    @Override public void componentResized(ComponentEvent e) {
                        initFrameSize(frame);
                    }
                });
            }
        });

        checkbox.addActionListener(e -> {
            Container c = getTopLevelAncestor();
            if (c instanceof JFrame) {
                initFrameSize((JFrame) c);
            }
        });
        //checkbox.setSelected(true);

        JLabel label = new JLabel();
        label.addComponentListener(new ComponentAdapter() {
            @Override public void componentResized(ComponentEvent e) {
                JLabel l = (JLabel) e.getComponent();
                Container c = getTopLevelAncestor();
                if (c instanceof JFrame) {
                    l.setText(c.getSize().toString());
                }
            }
        });

        JPanel p = new JPanel(new GridLayout(2, 1));
        p.add(checkbox);
        Toolkit.getDefaultToolkit().setDynamicLayout(false);
        p.add(new JCheckBox(new AbstractAction("Toolkit.getDefaultToolkit().setDynamicLayout: ") {
            @Override public void actionPerformed(ActionEvent e) {
                JCheckBox cb = (JCheckBox) e.getSource();
                Toolkit.getDefaultToolkit().setDynamicLayout(cb.isSelected());
            }
        }));
        add(p, BorderLayout.NORTH);
        add(label);
        setPreferredSize(new Dimension(320, 240));
    }
    protected void initFrameSize(JFrame frame) {
        if (!checkbox.isSelected()) {
            return;
        }
        int fw = frame.getSize().width;
        int fh = MH * fw / MW;
        frame.setSize(Math.max(MW, fw), Math.max(MH, fh));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -1616,86 +1616,8 @@
 );%0A%0A
-        JPanel p = new JPanel(new GridLayout(2, 1));%0A        p.add(checkbox);%0A
     
@@ -1685,46 +1685,39 @@
     
-p.add(new JCheckBox(new AbstractAction
+JCheckBox check = new JCheckBox
 (%22To
@@ -1762,18 +1762,17 @@
 yout: %22)
- %7B
+;
 %0A       
@@ -1776,140 +1776,36 @@
     
-    @Override public void actionPerformed(ActionEvent e) %7B%0A                JCheckBox cb = (JCheckBox) e.getSource();%0A               
+check.addActionListener(e -%3E
  Too
@@ -1850,10 +1850,35 @@
 out(
-cb
+((JCheckBox) e.getSource())
 .isS
@@ -1887,17 +1887,19 @@
 ected())
-;
+);%0A
 %0A       
@@ -1899,32 +1899,105 @@
         
-    %7D%0A        %7D)
+JPanel p = new JPanel(new GridLayout(2, 1));%0A        p.add(checkbox);%0A        p.add(check
 );%0A     

use a lambda expression instead of an anonymous class(ActionListener)