I programmed a calculator in java using a GridLayout method. I did not consider the fact that it would not make it possible to set different sized buttons. Therefore I am trying to find a work around instead since I could not figure out how to implement GridBagLayout into my code as it is.
Currently the result of my code looks like this: My current JFrame Design
However, I am trying to get it to look like this: How I want the design to look
public static void main(String[] args){
JFrame frame = new JFrame("Calculator");
Container content = frame.getContentPane();
ActionListener AL = new Calculator();
content.setLayout((new BorderLayout()));
JPanel panel1 = new JPanel(new BorderLayout());
panel1.add(new JLabel("CSC 20 Lab 08", JLabel.CENTER), BorderLayout.NORTH);
text = new JTextField("0.");
text.addActionListener(AL);
panel1.add( text, BorderLayout.SOUTH);
text.setHorizontalAlignment(JTextField.RIGHT);
content.add(panel1, BorderLayout.NORTH);
JPanel panel2 = new JPanel(new GridLayout(4, 5));
for (int i=1; i < 8; i = i + 3){
...adding numerical button in panel2...
...adding more buttons in panel2...
}
JPanel panel2b = new JPanel(new GridLayout(1, 2));
clearButton = new JButton("C");
panel2b.add(clearButton);
gridbag.setConstraints(clearButton, c);
...add "clear" functionality...
panel2.add(panel2b);
...adding more buttons in panel2...
content.add(panel2, BorderLayout.CENTER);
JPanel panel3 = new JPanel(new GridLayout(1, 3));
equalButton = new JButton("=");
panel3.add(equalButton);
equalButton.addActionListener(AL);
content.add(panel3, BorderLayout.SOUTH);
... more code
How can I most easily implement this to change the "C" button size?