/* Java Program To Make Use of grid layout to displaying components onto the applet. The Components Includes Buttons Text Boxes,Check Boxes. Done using Applets. */
import java.awt.*;
import java.applet.*;
public class GridApp extends Applet
{
TextArea ta;
TextField tf;
Button b1,b2;
CheckboxGroup cbg;
Checkbox cb1,cb2,cb3,cb4;
GridBagLayout gb;
GridBagConstraints gbc;
public void init()
{
gb = new GridBagLayout();
setLayout(gb);
gbc = new GridBagConstraints();
ta = new TextArea("TextArea",5,10);
tf = new TextField("Enter your Name:");
b1 = new Button ("TextArea");
b2 = new Button ("TextField");
cbg = new CheckboxGroup();
cb1 = new Checkbox("Bold",cbg, false);
cb2 = new Checkbox("Italic",cbg,false);
cb3 = new Checkbox("Plain",cbg,false);
cb4 = new Checkbox("Bold/Italic",cbg,true);
gbc.fill = GridBagConstraints.BOTH;
addComponent(ta,0,0,4,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(b1,0,1,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(b2,0,2,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(cb1,2,1,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(cb2,2,3,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(cb3,1,1,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(cb4,3,2,1,1);
gbc.fill = GridBagConstraints.HORIZONTAL;
addComponent(tf,4,0,1,3);
}
public void addComponent(Component c, int row, int col, int nrow, int ncol)
{
gbc.gridx = col;
gbc.gridy = row;
gbc.gridwidth = ncol;
gbc.gridheight = nrow;
gb.setConstraints(c,gbc);
add(c);
}
}
//< applet code =GridApp width = 500 height = 500>< /applet>
Subscribe to:
Post Comments (Atom)
Post a Comment