Java Programming Practical 21
Question 1
Write Java Program to display following output.

GridBagDemo1.java
Java
import java.awt.*;
class GridBagDemo1 extends Frame
{
Button b1;
Label l1,l2;
TextField t1;
TextArea ta;
GridBagDemo1()
{
GridBagLayout gb = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
b1=new Button("Submit");
l1=new Label("Name");
l2=new Label("Comments");
t1=new TextField(10);
ta=new TextArea(10,30);
setLayout(gb);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
Panel p1=new Panel(new FlowLayout(FlowLayout.LEFT,25,0));
p1.add(l1);
p1.add(t1);
add(p1,gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 1;
Panel p2=new Panel(new FlowLayout());
p2.add(l2);
p2.add(ta);
add(p2,gbc);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 1;
gbc.insets = new Insets(0,85,100,100);
add(b1,gbc);
setSize(400,400);
setTitle("GridBagLayout Example");
setVisible(true);
}
public static void main(String args[])
{
GridBagDemo1 obj=new GridBagDemo1();
}
}
Output
