Monday, May 4, 2020

Grid Bag Layout - Normal - Layout Manager

import java.awt.*;
/* <applet code=GridBag1.class width=300 height=300></applet>*/
public class GridBag1 extends java.applet.Applet {
    GridBagConstraints constraints = new GridBagConstraints();
    void addGB( Component component, int x, int y  ) {
        constraints.gridx = x; 
        constraints.gridy = y;
        add ( component, constraints );
    }
   
    public void init() {
        setLayout( new GridBagLayout() );
        int x, y;  // for clarity
        addGB( new Button("North"),  x=1,y=0 );
        addGB( new Button("West"),   x=0,y=1 );
        addGB( new Button("Center"), x=1,y=1 );
        addGB( new Button("East"),   x=2,y=1 );
        addGB( new Button("South"),  x=1,y=2 );
    }
}

No comments:

Post a Comment