(Apple problem # 3167076)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class framecomponents extends Applet implements WindowListener {
Frame frame;
public void init()
{
frame = new Frame("A frame");
frame.setLayout(new GridBagLayout());
frame.setBounds(100, 100, 600, 300);
Checkbox checkbox1 = new Checkbox("Checkbox with no background set");
constrain(frame, checkbox1, 0, 0, 1, 1, GridBagConstraints.WEST, 0, 0, 0, 0, GridBagConstraints.NONE, 0, 0);
Checkbox checkbox2 = new Checkbox("Checkbox with SystemColor.window background set");
checkbox2.setBackground(SystemColor.window);
constrain(frame, checkbox2, 0, 1, 1, 1, GridBagConstraints.WEST, 15, 0, 0, 0, GridBagConstraints.NONE, 0, 0);
Checkbox checkbox3 = new Checkbox("Checkbox with white background set");
checkbox3.setBackground(Color.white);
constrain(frame, checkbox3, 0, 2, 1, 1, GridBagConstraints.WEST, 15, 0, 0, 0, GridBagConstraints.NONE, 0, 0);
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)
{ // repeated from m so it can be called without referencing m
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 framecomponents