Creating a GridLayout using Java AWT source code: This simple AWT tutorial in java is used to design a gridlayout. GridLayout is a sub class of awt in Java. It is considered as a layout manager. It is used to arrange particular controls in a specific container. This class have a multiple columns and rows. Example code is given below.
[Useful: C Programming Guide] & [IT Companies List]
GRID LAYOUT IN JAVA AWT
This java AWT program is used to view the button and any other thing will be display by grid form in equal size of buttons form and to display an icon or button by different size but in equal length.
Java awt GridLayout example:
Q: Write a Java code for GridLayout process using of AWT.
//Import statements import java.awt.*; import java.awt.event.*; //Class definition class MyPanel extends Panel { Button ba[]; //Array declaration public MyPanel() { setLayout(new GridLayout(3,3)); ba=new Button[9]; //Object creation for(int i=0;i<9;i++) //For looping statement { ba[i]=new Button(String.valueOf(i+1)); add(ba[i]); } } } // © http://students3k.com – Karthikh Venkat class Grid extends Frame //Main class { MyPanel pa1, pa2, pa3, pa4; public Grid() { setTitle("Grids Demo"); pa1=new MyPanel(); pa2=new MyPanel(); pa3=new MyPanel(); pa4=new MyPanel(); add("North",pa1); add("South",pa2); add("East",pa3); add("West",pa4); setSize(300,300); show(); } public static void main(String str[]) { new Grid(); } }