CSE190L Layout Problem handout #23
One possible solution appears below.
public class ExamFrame {
private JFrame frame;
// ...
public ExamFrame() {
frame = new JFrame("fun");
// panel to the north
JPanel north = new JPanel();
north.setLayout(new BorderLayout());
north.add(quit, BorderLayout.WEST);
north.add(reset, BorderLayout.EAST);
frame.add(north, BorderLayout.NORTH);
JPanel center = new JPanel();
center.setLayout(new GridLayout(1, 2, 1, 1));
center.setBackground(Color.BLACK);
center.add(makePanel(panel1, slower1, faster1, periods1));
center.add(makePanel(panel2, slower2, faster2, periods2));
frame.add(center, BorderLayout.CENTER);
}
private JPanel makePanel(JPanel drawing, JButton slower,
JButton faster, JTextField periods) {
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(drawing, BorderLayout.CENTER);
JPanel north = new JPanel();
north.setBackground(Color.WHITE);
north.add(new JLabel("periods"));
north.add(periods);
p.add(north, BorderLayout.NORTH);
JPanel south = new JPanel();
south.add(faster);
south.add(slower);
p.add(south, BorderLayout.SOUTH);
return p;
}
}