import java.awt.*;
class NSIForm
{
Frame f;
int row = 0;
NSIForm
(
Frame f
)
{
this.f = f;
f.setLayout (new GridBagLayout ());
}
TextField addRow
(
String label
)
{
TextField textField = new TextField (5);
makeButton (f, new Label (label), 0, row, 1, 1, 0.0, 0.0);
makeButton (f, textField, 1, row++, 1, 1, 1.0, 0.0);
return textField;
}
void addRow
(
Object c
)
{
makeButton (f, c, 1, row++, 1, 1, 1.0, 0.0);
}
void addRow
(
Object c,
boolean leftjust
)
{
if (leftjust)
makeButton (f, c, 0, row++, 1, 1, 1.0, 0.0);
else
makeButton (f, c, 0, row++, 2, 1, 1.0, 0.0);
}
void show
(
)
{
f.pack();
f.show();
}
static void makeButton
(
Container cont,
Object arg,
int x,
int y,
int w,
int h,
double weightx,
double weighty
)
{
GridBagLayout gbl = (GridBagLayout)cont.getLayout();
GridBagConstraints c = new GridBagConstraints();
Component comp;
c.fill = GridBagConstraints.BOTH;
c.gridx = x;
c.gridy = y;
c.gridwidth = w;
c.gridheight = h;
c.weightx = weightx;
c.weighty = weighty;
if (arg instanceof String)
{
comp = new Button ((String) arg);
} else
{
comp = (Component) arg;
}
cont.add (comp);
gbl.setConstraints (comp, c);
}
}