0% found this document useful (0 votes)
8 views2 pages

Program 4.2 //write A Program To Display Output Using Gridbaglayout

This Java program demonstrates the use of GridBagLayout to create a simple form with labels, text fields, and buttons. It creates a frame with a GridBagLayout, then adds components such as labels and text fields to specific grid positions by calling the add method and specifying grid coordinates, grid widths/heights, and weight values. The main method instantiates the frame, sets its title and size, and makes it visible.

Uploaded by

rohitchavan2345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Program 4.2 //write A Program To Display Output Using Gridbaglayout

This Java program demonstrates the use of GridBagLayout to create a simple form with labels, text fields, and buttons. It creates a frame with a GridBagLayout, then adds components such as labels and text fields to specific grid positions by calling the add method and specifying grid coordinates, grid widths/heights, and weight values. The main method instantiates the frame, sets its title and size, and makes it visible.

Uploaded by

rohitchavan2345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 4.

2
//Write a program to display output using GridbagLayout
import java.awt.*;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
class GridBagLayoutDemoEx extends
frame
{
GridBagLayoutDemoEx ( )
{
Label l1=new Label("Name");
TextField t1=new TextField(10);
Label l2=new Label("comment");
TextArea ta=new TextArea(6,15);
Button b1=new Button("Submit");
setLayout(new GridBagLayout());
GridBagConstraints gc=new GridBagConstraints();
add(l1,gc,0,0,1,1,0,0);
add(t1,gc,0,1,1,1,0,20);
add(l2,gc,0,0,1,1,0,0);
add(ta,gc,1,1,1,1,0,60);
add(b1,gc,0,0,2,1,0,20);
}
void add(Component c, GridBagConstraints gc,int x,int y,int w,int h,int wx,int wy)
{

gc.gridx=x;
gc.gridx=y;
gc.gridwidth=w;
gc.gridheight=h;
gc.weightx=wx;
gc.weighty=wy;
add(c,gc);

} }
public class GridBagLayoutDemo
{
public static void main(String args[])
{
GridBagLayoutDemoEx f= new GridBagLayoutDemoEx();
f.setTitle("GridBagLayoutDemo");
f.setSize(300,200);
f.setVisible(true);

}
}

You might also like