Using FlowLayout in AWT - Example

FlowLayout is one of the Layouts in the AWT. The following program illustrates it.
import java.awt.*;
import java.awt.event.*;
class FlowLayoutDemo extends Frame
{
Button b1,b2,b3;
Label label;
   
    public FlowLayoutDemo()
    {
   
    // Set the frame properties
    setTitle("FlowLayout Demo");
    setSize(400,400);
    setLayout(new FlowLayout());
    setLocationRelativeTo(null);
    setVisible(true);
   
    // Create buttons
    b1=new Button(" Yes");
    b2=new Button("No");
    b3=new Button("Maybe");
   
    // Create label
    label=new Label();
   
    // Add buttons
    add(b1);
    add(b2);
    add(b3);
   
    //  Add label
    add(label);
   
    // Add action listener to buttons
    b1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)
            {
            label.setText("You clicked Yes");
            }
        });
    b2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)
            {
            label.setText("You clicked No");
            }
        });
    b3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)
            {
            label.setText("You clicked Maybe");
            }
        });
    }
    public static void main(String args[])
    {
    new FlowLayoutDemo();
    }
}
FlowLayoutDemo() : Code illustrating FlowLayout is written here
new FlowLayoutDemo() : Create object for the class FlowLayoutDemo