//  Scott DeRuiter       5/7/2003
//  Sticks2.java
//  Play the game of Sticks in an application (JFrame)

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

public class Sticks2 extends JFrame   
{

	private DrawPanel canvas;
	private TopButtons top;
	private BottomButtons bottom;

	public static void main ( String[] args )   
    	{
		new Sticks2 ( );
	}

	public Sticks2 ()   
    	{
		super ( "Sticks" );
		Container contentPane = getContentPane();

		canvas = new DrawPanel ( );
		contentPane.add( canvas, BorderLayout.CENTER );

		top = new TopButtons ( );
        	contentPane.add ( top, BorderLayout.NORTH );

		bottom = new BottomButtons ( );
        	contentPane.add ( bottom, BorderLayout.SOUTH );

		setDefaultCloseOperation ( DISPOSE_ON_CLOSE );      
		setLocation ( 20, 50 );
		setSize ( 500, 400 );
		show ( );
	}

	class DrawPanel extends JPanel 
    	{
		public DrawPanel ( )   
        	{
			setBackground ( Color.blue );
		}

		public void paintComponent ( Graphics g )  
        	{
			super.paintComponent ( g );
		}
	}

	class TopButtons extends JPanel implements ActionListener   
    	{

		private JButton [] number;
		private int max;

		public TopButtons ( )   
        	{
			max = 4;
			this.setLayout ( new GridLayout ( 1, max ) );

			number = new JButton[max];
			for ( int i = 0; i < number.length; i++ )   
            		{
				number[i] = new JButton ( );
				CreateAButton ( number[i], i+1 );
			}
		}

		public void CreateAButton ( JButton n, int i )   
        	{
			n = new JButton ( "ROW " + i );
       			n.addActionListener ( this );
			this.add ( n );
		}

   		public void actionPerformed ( ActionEvent evt ) 
        	{
      			String command = evt.getActionCommand();
   		}
	}

	class BottomButtons extends JPanel implements ActionListener   
    	{
		private JButton [] row;
		private int max;

		public BottomButtons ( )   
        	{
			max = 5;
			this.setLayout ( new GridLayout ( 1, max ) );

			row = new JButton[max];
			for ( int i = 0; i < row.length; i++ )   
            		{
				row[i] = new JButton ( );
				CreateAButton ( row[i], i+1 );
			}
		}

		public void CreateAButton ( JButton n, int i )   
        	{
			n = new JButton ( "" + i );
       			n.addActionListener ( this );
			this.add ( n );
		}

   		public void actionPerformed ( ActionEvent evt ) 
        	{
      			String command = evt.getActionCommand();
   		}
	}
}

(Applet "LaunchSticks2" would be displayed here
if Java were available.)

Back to Lesson 33 Examples

Back to Java Main Page