/* * ============================================================== * DemoFlowLayout.java : Create five buttons and position them on * a content pane using the flowlayout manager. * * Adapted from : Pantham S., Pure JFC Swing, 1999. * Modified by : Mark Austin March, 2001 * ============================================================== */ import javax.swing.*; import java.awt.*; public class DemoFlowLayout extends JApplet { Container container = null; static final int iNoButtons = 5; public void init() { // 1. Get the handle on applet's content pane. container = this.getContentPane(); // 2. Create the flow layout object and set it for the applet. // parameters : horizontal gap = 5 pixels. // vertical gap = 10 pixels. FlowLayout fl = new FlowLayout( FlowLayout.LEFT, 5, 10 ); container.setLayout(fl); // 3. Create and add some buttons to the applet. for (int i = 0; i < iNoButtons; i++) { JButton button = new JButton("Button"+(i+1)); button.setPreferredSize(new Dimension(100,25)); // width=100, height=25 container.add(button); } } }