// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private int num;

  private MainPanel() {
    super(new BorderLayout());

    JDesktopPane desktop = new JDesktopPane();

    JButton button = new JButton("add");
    button.addActionListener(e -> addInternalFrame(desktop));

    Long lv = Long.valueOf(button.getMultiClickThreshhold());
    SpinnerNumberModel m = new SpinnerNumberModel(lv, Long.valueOf(0), Long.valueOf(10_000), Long.valueOf(100));
    m.addChangeListener(e -> button.setMultiClickThreshhold(m.getNumber().longValue()));

    JMenuBar mb = new JMenuBar();
    mb.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    mb.add(new JLabel("MultiClickThreshhold: "));
    mb.add(new JSpinner(m));
    mb.add(Box.createHorizontalGlue());
    mb.add(button);

    add(desktop);
    add(mb, BorderLayout.NORTH);
    setPreferredSize(new Dimension(320, 240));
  }

  private void addInternalFrame(JDesktopPane desktop) {
    JInternalFrame f = createFrame("#" + num, num * 10, num * 10);
    desktop.add(f);
    desktop.getDesktopManager().activateFrame(f);
    num++;
  }

  private static JInternalFrame createFrame(String t, int x, int y) {
    JInternalFrame f = new JInternalFrame(t, true, true, true, true);
    f.setSize(200, 100);
    f.setLocation(x, y);
    f.setVisible(true);
    return f;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      System.out.println(UIManager.get("OptionPane.buttonClickThreshhold"));
      UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

@@ -113,16 +113,66 @@
 .awt.*;%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A
 import j
@@ -236,28 +236,8 @@
 l %7B%0A
-  private int num;%0A%0A
   pr
@@ -283,25 +283,24 @@
 rLayout());%0A
-%0A
     JDesktop
@@ -331,24 +331,69 @@
 topPane();%0A%0A
+    AtomicInteger num = new AtomicInteger();%0A
     JButton 
@@ -479,16 +479,39 @@
 (desktop
+, num.getAndIncrement()
 ));%0A%0A   
@@ -511,17 +511,17 @@
 );%0A%0A    
-L
+l
 ong lv =
@@ -521,29 +521,16 @@
 ng lv = 
-Long.valueOf(
 button.g
@@ -553,17 +553,16 @@
 shhold()
-)
 ;%0A    Sp
@@ -613,64 +613,25 @@
 lv, 
-Long.valueOf(0), Long.valueOf(
+0L, 
 10_000
-)
+L
 , 
-Long.valueOf(
 100
-)
+L
 );%0A 
@@ -757,71 +757,8 @@
 ();%0A
-    mb.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));%0A
     
@@ -896,35 +896,82 @@
 n);%0A
-%0A
     
-add(desktop
+EventQueue.invokeLater(() -%3E getRootPane().setJMenuBar(mb)
 );%0A
+%0A
     add(
 mb, 
@@ -970,30 +970,15 @@
 add(
-mb, BorderLayout.NORTH
+desktop
 );%0A 
@@ -1038,16 +1038,23 @@
 private 
+static 
 void add
@@ -1091,234 +1091,50 @@
 ktop
-) %7B%0A    JInternalFrame f = createFrame(%22#%22 + num, num * 10, num * 10);%0A    desktop.add(f);%0A    desktop.getDesktopManager().activateFrame(f);%0A    num++;%0A  %7D%0A%0A  private static JInternalFrame createFrame(String t, int x, int y) %7B
+, int idx) %7B%0A    String title = %22#%22 + idx;
 %0A   
@@ -1173,16 +1173,20 @@
 lFrame(t
+itle
 , true, 
@@ -1217,85 +1217,138 @@
 .set
-Size(200, 100);%0A    f.setLocation(x, y);%0A    f.setVisible(true);%0A    return f
+Bounds(idx * 10, idx * 10, 200, 100);%0A    f.setVisible(true);%0A    desktop.add(f);%0A    desktop.getDesktopManager().activateFrame(f)
 ;%0A  

remove unnecessary boxing