import java.applet.*; import java.awt.*; import java.awt.event.*; public class control_back extends Applet implements WindowListener { Frame frame; Label label; public void init() { frame = new Frame("A frame"); frame.setLayout(new GridBagLayout()); frame.setBounds(100, 100, 600, 300); Panel panel = new Panel(); panel.setBackground(Color.yellow); constrain (frame, panel, 0, 0, 1, 1, GridBagConstraints.CENTER, 0, 0, 0, 0, GridBagConstraints.BOTH, 1, 1); label = new Label("Some random label"); panel.add(label); frame.validate(); frame.show(); frame.addWindowListener(this); } 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); } public void windowOpened(WindowEvent we){} public void windowClosed(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowClosing(WindowEvent we) { if (we.getSource() == frame) { frame.setVisible(false); frame.dispose(); } } public void paint(Graphics g) { g.drawString("A frame should pop up", 10 , 20); } } // END OF Class control_back