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

public final class MainPanel extends JPanel {
    private final Random rnd = new Random();
    private final JTabbedPane tabs = new JTabbedPane();
    public MainPanel() {
        super(new BorderLayout());
        JPanel c1 = new JPanel(new GridLayout(10, 10));
        final JPanel c2 = new JPanel(new GridLayout(10, 10));
        final Timer timer = new Timer(16, null);
        for (int i = 0; i < 100; i++) {
            c1.add(new Tile1(rnd));
            c2.add(new Tile2(rnd, timer));
        }
        c2.addHierarchyListener(e -> {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (e.getComponent().isShowing()) {
                    timer.start();
                } else {
                    timer.stop();
                }
            }
        });
        tabs.addTab("Timer: 100", c1);
        tabs.addTab("Timer: 1, ActionListener: 100", c2);
        tabs.addTab("Timer: 1, ActionListener: 1", new TilePanel(rnd));
        add(tabs);
        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);
    }
}

class Tile1 extends JComponent implements HierarchyListener {
    //java - javax.swing.Timer slowdown in Java7u40 - Stack Overflow
    //http://stackoverflow.com/questions/18933986/javax-swing-timer-slowdown-in-java7u40
    private int red;
    private final Timer timer;
    protected Tile1(final Random rnd) {
        super();
        addHierarchyListener(this);
        timer = new Timer(16, new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                red = rnd.nextInt(255);
                repaint();
            }
        });
    }
    @Override public void hierarchyChanged(HierarchyEvent e) {
        if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
            if (e.getComponent().isShowing()) {
                timer.start();
            } else {
                timer.stop();
            }
        }
    }
    @Override public Dimension getPreferredSize() {
        return new Dimension(10, 10);
    }
    @Override protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (isVisible()) {
            if (!timer.isRunning()) {
                timer.start();
            }
        } else {
            timer.stop();
        }
        g.setColor(new Color(red, 255 - red, 0));
        g.fillRect(0, 0, getWidth(), getHeight());
    }
}

class Tile2 extends JComponent {
    private int red;
    protected Tile2(final Random rnd, Timer timer) {
        super();
        timer.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                red = rnd.nextInt(255);
                repaint();
            }
        });
    }
    @Override public Dimension getPreferredSize() {
        return new Dimension(10, 10);
    }
    @Override protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(new Color(red, 255 - red, 0));
        g.fillRect(0, 0, getWidth(), getHeight());
    }
}

class TilePanel extends JPanel {
    protected TilePanel(Random rnd) {
        super(new GridLayout(10, 10));
        for (int i = 0; i < 100; i++) {
            JLabel l = new JLabel();
            l.setOpaque(true);
            add(l);
        }
        Timer timer = new Timer(16, e -> {
            for (int i = 0; i < 100; i++) {
                JComponent l = (JComponent) getComponent(i);
                int red = rnd.nextInt(256);
                l.setBackground(new Color(red, 255 - red, 0));
            }
        });
        addHierarchyListener(e -> {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (e.getComponent().isShowing()) {
                    timer.start();
                } else {
                    timer.stop();
                }
            }
        });
    }
}

@@ -159,16 +159,51 @@
 Random;%0A
+import java.util.stream.IntStream;%0A
 import j
@@ -488,22 +488,16 @@
         
-final 
 JPanel c
@@ -544,22 +544,16 @@
         
-final 
 Timer ti
@@ -591,37 +591,44 @@
     
-for (int i = 0; i %3C 100; i++)
+IntStream.range(0, 100).forEach(i -%3E
  %7B%0A 
@@ -701,24 +701,24 @@
 d, timer));%0A
-
         %7D%0A  
@@ -706,32 +706,34 @@
 mer));%0A        %7D
+);
 %0A        c2.addH
@@ -4183,37 +4183,44 @@
     
-for (int i = 0; i %3C 100; i++)
+IntStream.range(0, 100).forEach(i -%3E
  %7B%0A 
@@ -4307,32 +4307,34 @@
 dd(l);%0A        %7D
+);
 %0A        Timer t
@@ -4363,58 +4363,47 @@
  -%3E 
-%7B%0A            for (int i = 0; i %3C 100; i++) %7B%0A    
+IntStream.range(0, 100).forEach(i -%3E %7B%0A
     
@@ -4421,17 +4421,17 @@
 mponent 
-l
+c
  = (JCom
@@ -4467,20 +4467,16 @@
         
- 
-   
 int red 
@@ -4503,29 +4503,25 @@
             
-   
- l
+c
 .setBackgrou
@@ -4558,39 +4558,26 @@
 ));%0A        
-   
- %7D%0A        
 %7D
+)
 );%0A        a

use IntStream.range(...) instead of for (...)