this is the Calculator code that i developed, the GUI was not perfectly arranged as i wanted but still contains all neccessary components that i needed. My main problem now is to get those buttons working and i will later learn more about my Layout manager.
import java.awt.*;
import javax.swing.*;
class jideCalculator extends JFrame {
//setting row1
JPanel row1 = new JPanel();
JTextField screen = new JTextField(15);
//setting row2
JPanel row2 = new JPanel();
JButton button7 = new JButton("7");
JButton button8 = new JButton("8");
JButton button9 = new JButton("9");
JButton buttonDel = new JButton("DEL");
JButton buttonAc = new JButton("AC");
//setting row3
JPanel row3 = new JPanel();
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton buttonX = new JButton("X");
JButton buttonDivision = new JButton("/");
//seting row4
JPanel row4 = new JPanel();
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton buttonPlus = new JButton("+");
JButton buttonMinus = new JButton("-");
//setting row5
JPanel row5 = new JPanel();
JButton buttonZero = new JButton("0");
JButton buttonPeriod = new JButton(".");
JButton buttonComma = new JButton(",");
JButton buttonResult = new JButton("=");
//setting the Frame
public jideCalculator() {
super("Jide's Calculator");
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout layout = new GridLayout(5, 1, 10, 10);
Container pane = getContentPane();
pane.setLayout(layout);
//setting row1 layout
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER, 10, 10);
row1.setLayout(layout1);
row1.add(screen);
screen.setEditable(false);
pane.add(row1);
//setting row2 layout
FlowLayout layout2 = new FlowLayout();
row2.setLayout(layout2);
row2.add(button7);
row2.add(button8);
row2.add(button9);
row2.add(buttonDel);
row2.add(buttonAc);
pane.add(row2);
//setting row3 layout
FlowLayout layout3 = new FlowLayout();
row3.setLayout(layout3);
row3.add(button4);
row3.add(button5);
row3.add(button6);
row3.add(buttonX);
row3.add(buttonDivision);
pane.add(row3);
//setting row4 layout
FlowLayout layout4 = new FlowLayout();
row4.setLayout(layout4);
row4.add(button1);
row4.add(button2);
row4.add(button3);
row4.add(buttonPlus);
row4.add(buttonMinus);
pane.add(row4);
//setting row5 layout
FlowLayout layout5 = new FlowLayout();
row5.setLayout(layout5);
row5.add(buttonZero);
row5.add(buttonPeriod);
row5.add(buttonComma);
row5.add(buttonResult);
pane.add(row5);
setVisible(true);
}
//execution statement
public static void main(
String[] arguments) {
jideCalculator jide = new jideCalculator();
}
}