import javax.swing.*;
import java.awt.*;
public class Calculator {
public static void main(String[] args) {
new Calculator();
}
public Calculator()
{
JFrame f = new JFrame(" ");
JPanel textfieldpanel1 = new JPanel();
JPanel textfieldpanel2 = new JPanel();
JPanel row1panel = new JPanel();
JPanel row2pane1 = new JPanel();
JPanel row3pane1 = new JPanel();
JPanel row4pane1 = new JPanel();
JTextField mainpanel = new JTextField(16);
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
JButton b10 = new JButton("0");
JButton divide = new JButton("/");
JButton multiply = new JButton("*");
JButton subtract = new JButton("-");
JButton add = new JButton("+");
JButton equals = new JButton("=");
JButton dot = new JButton(". ");
JButton clear = new JButton("C");
textfieldpanel1.setLayout(new GridLayout(1,1));
textfieldpanel1.add(textfieldpanel1);
textfieldpanel2.add(textfieldpanel1);
row1panel.setLayout(new GridLayout(1,3));
row2panel.setLayout(new GridLayout(1,3));
row3panel.setLayout(new GridLayout(1,3));
row4panel.setLayout(new GridLayout(1,3));
row1panel.add(b7);
row1panel.add(b8);
row1panel.add(b9);
row1panel.add(divide);
row2panel.add(b4);
row2panel.add(b5);
row2panel.add(b6);
row2panel.add(multiply);
row3panel.add(b1);
row3panel.add(b2);
row3panel.add(b3);
row3panel.add(subtract);
row4panel.add(b10);
row4panel.add(dot);
row4panel.add(clear);
row4panel.add(add);
mainpanel.setLayout(new GridLayout(5,1));
mainpanel.add(textfieldpanel2);
mainpanel.add(row1panel);
mainpanel.add(row2panel);
mainpanel.add(row3panel);
mainpanel.add(row4panel);
f.setContentPane(mainpanel);
f.setSize(200,200);
f.show();
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
It won't work.
Please help.