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

public final class MainPanel extends JPanel {
    private static final byte END_OF_TRACK = 0x2F;
    private long tickpos;
    private final JButton start;
    private final JButton stop;
    private Sequencer sequencer;
    public MainPanel() {
        super(new BorderLayout(5, 5));
        URL url = getClass().getResource("Mozart_toruko_k.mid");
        try {
            Sequence s = MidiSystem.getSequence(url);
            sequencer = MidiSystem.getSequencer();
            sequencer.open();
            sequencer.setSequence(s);
        } catch (InvalidMidiDataException | MidiUnavailableException | IOException ex) {
            ex.printStackTrace();
            start = null;
            stop = null;
            add(new JLabel(ex.toString()));
            return;
        }
        sequencer.addMetaEventListener(new MetaEventListener() {
            @Override public void meta(MetaMessage meta) {
                if (meta.getType() == END_OF_TRACK) {
                    tickpos = 0;
                    start.setEnabled(true);
                    stop.setEnabled(false);
                }
            }
        });
        start = new JButton(new AbstractAction("start") {
            @Override public void actionPerformed(ActionEvent e) {
                sequencer.setTickPosition(tickpos);
                sequencer.start();
                stop.setEnabled(true);
                start.setEnabled(false);
            }
        });
        stop = new JButton(new AbstractAction("stop") {
            @Override public void actionPerformed(ActionEvent e) {
                tickpos = sequencer.getTickPosition();
                sequencer.stop();
                start.setEnabled(true);
                stop.setEnabled(false);
            }
        });
        JButton init = new JButton(new AbstractAction("init") {
            @Override public void actionPerformed(ActionEvent e) {
                sequencer.stop();
                tickpos = 0;
                start.setEnabled(true);
                stop.setEnabled(false);
            }
        });
        stop.setEnabled(false);

        JTextArea label = new JTextArea("Wolfgang Amadeus Mozart\nPiano Sonata No. 11 in A major, K 331\n(Turkish Rondo)");
        label.setBorder(BorderFactory.createTitledBorder("MIDI"));
        label.setEditable(false);
        label.setBackground(getBackground());

        Box box = Box.createHorizontalBox();
        box.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 0));
        box.add(Box.createHorizontalGlue());
        box.add(start);
        box.add(stop);
        box.add(init);

        add(label);
        add(box, BorderLayout.SOUTH);
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setPreferredSize(new Dimension(320, 240));
    }

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

@@ -418,16 +418,39 @@
 on start
+ = new JButton(%22start%22)
 ;%0A    pr
@@ -477,41 +477,86 @@
 stop
-;%0A    private Sequencer sequencer
+  = new JButton(%22stop%22);%0A    private final JButton init  = new JButton(%22init%22)
 ;%0A  
@@ -609,32 +609,61 @@
 rLayout(5, 5));%0A
+        Sequencer sequencer;%0A
         URL url 
@@ -1037,269 +1037,242 @@
     
-start = null;%0A            stop = null;%0A            add(new JLabel(ex.toString()));%0A            return;%0A        %7D%0A        sequencer.addMetaEventListener(new MetaEventListener() %7B%0A            @Override public void meta(MetaMessage meta) %7B%0A                if (meta
+add(new JLabel(ex.toString()));%0A            start.setEnabled(false);%0A            stop.setEnabled(false);%0A            init.setEnabled(false);%0A            return;%0A        %7D%0A        sequencer.addMetaEventListener(e -%3E %7B%0A            if (e
 .get
@@ -1305,36 +1305,32 @@
                 
-  
-  
 tickpos = 0;%0A   
@@ -1318,36 +1318,32 @@
    tickpos = 0;%0A
-    
                 
@@ -1358,36 +1358,32 @@
 tEnabled(true);%0A
-    
                 
@@ -1410,26 +1410,8 @@
 e);%0A
-                %7D%0A
     
@@ -1449,117 +1449,31 @@
 tart
- = new JButton(new AbstractAction(%22start%22) %7B%0A            @Override public void actionPerformed(ActionEvent e)
+.addActionListener(e -%3E
  %7B%0A 
@@ -1475,36 +1475,32 @@
 %3E %7B%0A            
-    
 sequencer.setTic
@@ -1523,36 +1523,32 @@
 s);%0A            
-    
 sequencer.start(
@@ -1554,36 +1554,32 @@
 ();%0A            
-  
-  
 stop.setEnabled(
@@ -1577,36 +1577,32 @@
 tEnabled(true);%0A
-    
             star
@@ -1618,38 +1618,24 @@
 led(false);%0A
-            %7D%0A
         %7D);%0A
@@ -1650,123 +1650,34 @@
 stop
- = new JButton(new AbstractAction(%22stop%22) %7B%0A            @Override public void actionPerformed(ActionEvent e) %7B%0A    
+.addActionListener(e -%3E %7B%0A
     
@@ -1727,36 +1727,32 @@
 ();%0A            
-    
 sequencer.stop()
@@ -1757,36 +1757,32 @@
 ();%0A            
- 
-   
 start.setEnabled
@@ -1781,36 +1781,32 @@
 tEnabled(true);%0A
-    
             stop
@@ -1821,38 +1821,24 @@
 led(false);%0A
-            %7D%0A
         %7D);%0A
@@ -1849,135 +1849,38 @@
     
-JButton init = new JButton(new AbstractAction(%22init%22) %7B%0A            @Override public void actionPerformed(ActionEvent e) %7B%0A    
+init.addActionListener(e -%3E %7B%0A
     
@@ -1909,36 +1909,32 @@
 ();%0A            
-    
 tickpos = 0;%0A   
@@ -1934,36 +1934,32 @@
  0;%0A            
-   
- 
 start.setEnabled
@@ -1970,36 +1970,32 @@
 e);%0A            
-    
 stop.setEnabled(
@@ -1998,38 +1998,24 @@
 led(false);%0A
-            %7D%0A
         %7D);%0A

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