// FlowLayoutDemo2.java
// Demos FlowLayout alignments with an applet
// Uses inner class that implements ActionListener
// APPLET CODE="FlowLayoutDemo2" HEIGHT=75 WIDTH=500
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class FlowLayoutDemo2 extends JApplet {
	private Container c;
	private JButton left, center, right;
	private FlowLayout flow;

	public void init( ) {
		c = getContentPane( );
		flow = new FlowLayout( );
		c.setLayout( flow );

		ButtonHandler handler = new ButtonHandler( );

		left = new JButton( "Left" );
		left.addActionListener( handler );	// registers handler as the listener
		c.add( left );
		center = new JButton( "Center" );
		center.addActionListener( handler );   // registers handler as the listen
		c.add( center );
		right = new JButton( "Right" );
		right.addActionListener( handler );	// registers handler as the listener
		c.add( right );
	}

	private class ButtonHandler implements ActionListener {
		public void actionPerformed( ActionEvent e ) {
			if ( e.getSource( ) == left ) flow.setAlignment( FlowLayout.LEFT );
			else if (e.getSource( ) == center ) flow.setAlignment( FlowLayout.CENTER );
			else flow.setAlignment( FlowLayout.RIGHT );
		
			flow.layoutContainer( c );
		}
	}
}