import java.awt.event.*; import java.awt.*; import javax.swing.*; public class Example2 extends JFrame implements ActionListener { public static void main(String[] args) { JFrame frame = new Example2(); // Create a Window with "stuff" in it frame.setTitle("Example2"); // Give a title frame.setSize(100,1000); // Give a default size of 100x100 frame.setLocation(0,0); // Place window in upper, left corner of screen frame.pack(); // "Shrink wrap" window to fit its contents frame.setVisible(true); // Show everything frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Kill program when window is closed } 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 Container cp; private JPanel leftPanel; private JPanel rightPanel; private JButton[] leftButtons; private JButton[] rightButtons; private JLabel message; private Timer scheduler; private int pos = RIGHTSIZE - 1; public Example2() { setLayout(); addButtons(); addLabel(); registerListeners(); } private void setLayout() { // 1st level: Content Pane: cp = getContentPane(); // Use flow layout to place panels: cp.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" because for message cp.add(leftPanel); rightPanel = new JPanel(); rightPanel.setLayout(new GridLayout(RIGHTSIZE,1)); cp.add(rightPanel); } private void addButtons() { // Create buttons on left side: leftButtons = new JButton[LEFTSIZE]; leftButtons[0]=new JButton("Start"); leftButtons[1]=new JButton("Stop"); leftButtons[2]=new JButton("Reset"); leftButtons[3]=new JButton("Set Delay"); leftButtons[4]=new JButton("Quit"); // Add buttons to left side: for (int count=0;count