Grid Layout in Java using applet

//program to implement grid layout

Description


This program demonstrate grid layout in Java.  Grid layout is used to place the components in a grid of cells.
The statement setLayout(new GridLayout(5,3)); is used to create a grid layout with five rows and three columns. The program repeatedly places a label, text box and a button in each row using a for loop.


Program



//<applet code=LayGrid height=400 width=400></applet>

import java.awt.*;

import java.applet.*;

public class LayGrid extends Applet

{

public void init()

{

setLayout(new GridLayout(5,3));

for(int i=1;i<6;i++)

{

add(new Label("Lablel "+i));

add(new TextField("TextField "+i));

add(new Button("Button "+i));

}

}

}



Output


Java applet program for grid layout
Grid Layout in Java (Execution) 

Grid layout in Java
Grid Layout in Java applet

No comments: