I'm relatively new to Java and attempting to get my first exposure using Swing, and so I've decided to mock up a calculator in Java using Swing and JButtons
/JTextFields
.
Problem being, most buttons display correctly and at the correct sizes, but there are a few abnormalities - particularly, the subtraction (-) button doesn't appear and the equation button (=) appears behind the others. Would post an image, but that should be sufficient and my rep won't allow me to inline an image; I lost an older account I had on here and have to suffer the consequences.
Without further ado, here's the code:
// Set the display JTextField as the top element in the GUI stackup:
disp.setBounds(50,25,400,50);
button7.setBounds(50,75,x,y);
button8.setBounds(150,75,x,y);
button9.setBounds(250,75,x,y);
buttonPlus.setBounds(350,75,x,y);
button4.setBounds(50,125,x,y);
button5.setBounds(150,125,x,y);
button6.setBounds(250,125,x,y);
buttonMinus.setBounds(350,75,x,y);
button1.setBounds(50,175,x,y);
button2.setBounds(150,175,x,y);
button3.setBounds(250,175,x,y);
buttonMult.setBounds(350,175,x,y);
buttonClear.setBounds(50,225,x,y);
button0.setBounds(150,225,x,y);
buttonEqual.setBounds(250,225,x,y);
buttonDiv.setBounds(350,225,x,y);
frame.add(disp);
frame.add(button0);
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.add(button6);
frame.add(button7);
frame.add(button8);
frame.add(button9);
frame.add(buttonClear);
frame.add(buttonPlus);
frame.add(buttonMinus);
frame.add(buttonMult);
frame.add(buttonDiv);
frame.add(buttonEqual);
//Display the window.
frame.pack();
frame.setVisible(true);
If it's relevant, I'll proceed to post the constructors as well; I'm using IntelliJ IDEA if that's of any pertinence.