<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">

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

public class Example1 extends JFrame {
   private final int RIGHTSIZE = 10; // 10 "tiles" on the right
   private final int LEFTSIZE = 5; // 5 buttons on the left
   private int delay = 500;
   private JPanel leftPanel;
   private JPanel rightPanel;
   private JButton[] leftButtons;
   private JButton[] rightButtons;
   private JLabel message;
   private Timer scheduler;
   private int pos = RIGHTSIZE - 1;

   public static void main(String[] args) {
      new Example1(); // Create the root JFrame
   }

   public Example1() {
      setLayout();
      addButtons();
      addLabel();
      registerListeners();

      setDefaultCloseOperation(EXIT_ON_CLOSE); // Kill program when window is
                                               // closed
      setTitle("Example1"); // Give frame a title
      setSize(100, 1000); // Give it a default size of 100 x 1000
      setLocation(0, 0); // Place in upper left corner of screen
      pack(); // "Shrink wrap" to fit contents
      setVisible(true); // Show everything
   }

   private void setLayout() {
      // Use flow layout to place panels
      setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));

      // 2nd level: Place panels on left and right
      // Inside each panel, use a grid to place more components
      // which will be on the 3rd level
      leftPanel = new JPanel();
      leftPanel.setLayout(new GridLayout(LEFTSIZE + 1, 1)); // +1 for message
      add(leftPanel);

      rightPanel = new JPanel();
      rightPanel.setLayout(new GridLayout(RIGHTSIZE, 1));
      add(rightPanel);
   }

   private void addButtons() {
      // Button labels
      String[] labels = { "Start", "Stop", "Reset", "Set Delay", "Quit" };
      
      // Create buttons on left side
      leftButtons = new JButton[LEFTSIZE];
      for (int count = 0; count &lt; LEFTSIZE; count++) {
         leftButtons[count] = new JButton(labels[count]);
         leftButtons[count].setBackground(Color.YELLOW);
         leftButtons[count].setOpaque(true);
         leftPanel.add(leftButtons[count]);
      }

      // Create buttons on right side
      rightButtons = new JButton[RIGHTSIZE];
      for (int count = 0; count &lt; RIGHTSIZE; count++) {
         rightButtons[count] = new JButton(String.valueOf(count));
         rightButtons[count].setBackground(Color.WHITE);
         rightButtons[count].setOpaque(true);
         rightPanel.add(rightButtons[count]);
      }
   }

   private void addLabel() {
      message = new JLabel();
      message.setFont(new Font("Tahoma", Font.PLAIN, 16));
      message.setText("Not Done!");
      message.setHorizontalAlignment(JLabel.CENTER);
      leftPanel.add(message);
   }

   private void registerListeners() {
      leftButtons[0].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            // Do silly animation: from bottom to top, color a right button:
            scheduler = new Timer(delay, new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                  if (pos &lt; 0) {
                     scheduler.stop();
                     message.setText("Done!");
                     return;
                  }
                  rightButtons[pos].setBackground(Color.BLUE);
                  repaint();
                  pos--;
               }
            });
            scheduler.start();
         }
      });

      /*
       * Button handlers
       */

      // Stop
      leftButtons[1].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            scheduler.stop();
         }
      });

      // Reset
      leftButtons[2].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            scheduler.stop(); // might still be running!
            pos = RIGHTSIZE - 1;
            message.setText("Not Done!");
            for (int count = 0; count &lt; RIGHTSIZE; count++)
               rightButtons[count].setBackground(Color.WHITE);
            repaint();
         }
      });

      // Set Delay
      leftButtons[3].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            scheduler.stop(); // might still be running!
            delay = Integer.parseInt(JOptionPane.showInputDialog("Enter the delay in milliseconds:"));
         }
      });

      // Quit
      leftButtons[4].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            scheduler.stop(); // might still be running!
            switch (JOptionPane.showConfirmDialog(null,
                     "Do you really wish to quit?", "Alert!",
                     JOptionPane.YES_NO_OPTION)) {
            case JOptionPane.YES_OPTION: // quit program
               System.exit(0);
            case JOptionPane.NO_OPTION: // continue
               return;
            default: // unknown
               JOptionPane.showMessageDialog(null, "Something weird just happened!");
            }
         }
      });

   }
}
</pre></body></html>