I am trying to make a calculator. I am just trying to setup the GUI first. The problem I am having is that I want the JTextField to be the full width of the pane above all the JButtons. I want the double zero button to take up the space of two buttons horizontally in the bottom left
corner. I want the enter button to take up the space of two Jbuttons vertically in the bottom right hand corner. Here is a pic of what my UI looks like right now:
javakeypad.jpg
Here is my code:
public class KeypadUse { public static void main(String[] args) { Keypad key = new Keypad(); } }
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Keypad extends JFrame { private JTextField displayTF; private JButton oneB, twoB, threeB, fourB, fiveB, sixB, sevenB, eightB, nineB, zeroB, doubleZeroB, plusB, minusB, enterB; public Keypad() { setTitle("Keypad"); Container pane = getContentPane(); pane.setLayout(new GridLayout(5, 4)); displayTF = new JTextField(20); oneB = new JButton(); twoB = new JButton(); threeB = new JButton(); fourB = new JButton(); fiveB = new JButton(); sixB = new JButton(); sevenB = new JButton(); eightB = new JButton(); nineB = new JButton(); zeroB = new JButton(); doubleZeroB = new JButton(); plusB = new JButton(); minusB = new JButton(); enterB = new JButton(); pane.add(displayTF); pane.add(minusB); pane.add(nineB); pane.add(eightB); pane.add(sevenB); pane.add(plusB); pane.add(sixB); pane.add(fiveB); pane.add(fourB); pane.add(enterB); pane.add(threeB); pane.add(twoB); pane.add(oneB); pane.add(zeroB); pane.add(doubleZeroB); setSize(500,500); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } }
what I was thinking is that maybe there is a way to put a "place holder" to take up a full row and then I can resize my textfield. But I am
stumped on the buttons.
thanks in advance!