import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Layout extends JApplet implements ActionListener
{
FlowLayout layoutFL = new FlowLayout(FlowLayout.LEFT);
FlowLayout layoutF = new FlowLayout();
FlowLayout layoutFR = new FlowLayout(FlowLayout.RIGHT);
GridLayout layoutG32 = new GridLayout(3,2,2,4);
GridLayout layoutG23 = new GridLayout(2,3,2,4);
JButton buttonOne = new JButton("Flow Left");
JButton buttonTwo = new JButton("Flow");
JButton buttonThree = new JButton("Flow Right");
JButton buttonFour = new JButton("Grid 3X2");
JButton buttonFive = new JButton("Grid 2X3");
JLabel iSawThat = new JLabel("Press a Button");
public void init()
{
Container con = getContentPane();
con.setLayout(layoutF);
con.add(buttonOne);
con.add(buttonTwo);
con.add(buttonThree);
con.add(buttonFour);
con.add(buttonFive);
con.add(iSawThat);
buttonOne.addActionListener(this);
buttonTwo.addActionListener(this);
buttonThree.addActionListener(this);
buttonFour.addActionListener(this);
buttonFive.addActionListener(this);
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if(source == buttonOne)
{
iSawThat.setText("Layout is Flow Left.");
Container con = getContentPane();
con.setLayout(layoutFL);
}
else if(source == buttonTwo)
{
iSawThat.setText("Layout is Flow.");
Container con = getContentPane();
con.setLayout(layoutF);
}
else if(source == buttonThree)
{
iSawThat.setText("Layout is Flow Right.");
Container con = getContentPane();
con.setLayout(layoutFR);
}
else if(source == buttonFour)
{
iSawThat.setText("Layout is Grid 3X2.");
Container con = getContentPane();
con.setLayout(layoutG32);
}
else if(source == buttonFive)
{
iSawThat.setText("Layout is Grid 2X3.");
Container con = getContentPane();
con.setLayout(layoutG23);
}
repaint();
}
}