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

package example;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.util.Objects;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new GridBagLayout());

    JLabel label = new JLabel("0") {
      @Override public Dimension getMaximumSize() {
        return getPreferredSize();
      }

      @Override public Dimension getPreferredSize() {
        return new Dimension(100, 100);
      }
    };
    label.setOpaque(true);
    label.setBackground(Color.WHITE);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setFont(label.getFont().deriveFont(30f));

    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    box.add(makeButton(-5, label));
    box.add(makeButton(-1, label));
    box.add(label);
    box.add(makeButton(+1, label));
    box.add(makeButton(+5, label));
    box.add(Box.createHorizontalGlue());

    add(box);
    setPreferredSize(new Dimension(320, 240));
  }

  private static JButton makeButton(int extent, JLabel view) {
    String title = String.format("%+d", extent);
    JButton button = new JButton(title) {
      @Override public Dimension getMaximumSize() {
        return new Dimension(50, 100);
      }
    };
    AutoRepeatHandler handler = new AutoRepeatHandler(extent, view);
    button.addActionListener(handler);
    button.addMouseListener(handler);
    return button;
  }

  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();
      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);
  }
}

class AutoRepeatHandler extends MouseAdapter implements ActionListener {
  private final Timer autoRepeatTimer;
  private final BigInteger extent;
  private final JLabel view;
  private JButton arrowButton;

  protected AutoRepeatHandler(int extent, JLabel view) {
    super();
    this.extent = BigInteger.valueOf(extent);
    this.view = view;
    autoRepeatTimer = new Timer(60, this);
    autoRepeatTimer.setInitialDelay(300);
  }

  @Override public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o instanceof Timer) {
      if (Objects.nonNull(arrowButton) && !arrowButton.getModel().isPressed() && autoRepeatTimer.isRunning()) {
        autoRepeatTimer.stop();
        arrowButton = null;
      }
    } else if (o instanceof JButton) {
      arrowButton = (JButton) e.getSource();
    }
    BigInteger i = new BigInteger(view.getText());
    view.setText(i.add(extent).toString());
  }

  @Override public void mousePressed(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e) && e.getComponent().isEnabled()) {
      autoRepeatTimer.start();
    }
  }

  @Override public void mouseReleased(MouseEvent e) {
    autoRepeatTimer.stop();
    arrowButton = null;
  }

  @Override public void mouseExited(MouseEvent e) {
    if (autoRepeatTimer.isRunning()) {
      autoRepeatTimer.stop();
    }
  }
}

@@ -332,16 +332,56 @@
 swing.*;
+%0Aimport javax.swing.text.JTextComponent;
 %0A%0Apublic
@@ -486,27 +486,31 @@
    J
-Label lab
+TextField fi
 el
+d
  = new J
 Labe
@@ -505,21 +505,25 @@
  = new J
-Lab
+TextFi
 el
+d
 (%220%22) %7B%0A
@@ -706,18 +706,17 @@
 on(100, 
-10
+5
 0);%0A    
@@ -734,78 +734,13 @@
     
-label.setOpaque(true);%0A    label.setBackground(Color.WHITE);%0A    label
+field
 .set
@@ -787,21 +787,21 @@
 R);%0A    
-lab
+fi
 el
+d
 .setFont
@@ -801,21 +801,21 @@
 setFont(
-lab
+fi
 el
+d
 .getFont
@@ -834,16 +834,46 @@
 t(30f));
+%0A    field.setEditable(false);
 %0A%0A    Bo
@@ -975,21 +975,21 @@
 ton(-5, 
-lab
+fi
 el
+d
 ));%0A    
@@ -1011,21 +1011,21 @@
 ton(-1, 
-lab
+fi
 el
+d
 ));%0A    
@@ -1032,21 +1032,21 @@
 box.add(
-lab
+fi
 el
+d
 );%0A    b
@@ -1067,21 +1067,21 @@
 ton(+1, 
-lab
+fi
 el
+d
 ));%0A    
@@ -1107,13 +1107,13 @@
 +5, 
-lab
+fi
 el
+d
 ));%0A
@@ -1261,37 +1261,41 @@
 on(int extent, J
-Lab
+TextFi
 el
+d
  view) %7B%0A    Str
@@ -1463,18 +1463,17 @@
 ion(50, 
-10
+5
 0);%0A    
@@ -2569,21 +2569,29 @@
  final J
-Label
+TextComponent
  view;%0A 
@@ -2668,13 +2668,21 @@
 t, J
-Label
+TextComponent
  vie

use JTextField instead of JLabel