import java.applet.*; import java.awt.*; public class into_lap extends Applet { public void init() { setBackground(new Color(255, 240, 255)); setLayout(new GridBagLayout()); TextField tf = new TextField(); constrain(this, tf, 0, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); Label label = new Label("Text in label"); constrain(this, label, 1, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); TextField tf2 = new TextField(); constrain(this, tf2, 2, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); Label label2 = new Label("More Text in label"); constrain(this, label2, 3, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); Button button = new Button("Some button"); constrain(this, button, 4, 0, 1, 1, GridBagConstraints.NORTH, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0); } static final void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int anchor, int topPad, int leftPad, int bottomPad, int rightPad, int fill, double weightx, double weighty) { GridBagConstraints c = new GridBagConstraints(); c.gridx = grid_x; c.gridy = grid_y; c.gridwidth = grid_width; c.gridheight = grid_height; c.anchor = anchor; c.insets.top = topPad; c.insets.left = leftPad; c.insets.bottom= bottomPad; c.insets.right = rightPad; c.fill = fill; c.weightx = weightx; c.weighty = weighty; ((GridBagLayout)container.getLayout()).setConstraints(component, c); container.add(component); } } // END OF Class into_lap