so guys here's my code for a simple calculator....please help me with ways on how to improve it....i.e any scientific features plus the layout etc
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class MyCal { JFrame frame=new JFrame(); JPanel panel = new JPanel(); JTextField txt1= new JTextField(); JTextField txt2= new JTextField(); JTextField txt3= new JTextField(); JButton btnadd = new JButton("+"); JButton btnmul = new JButton("x"); JButton btnsub = new JButton("-"); JButton btndiv = new JButton("/"); JLabel lbl1 = new JLabel("number1"); JLabel lbl2 = new JLabel("number2"); JLabel lbl3 = new JLabel("answer"); public void AddTxtField(){ txt1.setBounds(100, 50, 150, 20); txt2.setBounds(100, 70, 150, 20); txt3.setBounds(100, 90, 150, 20); panel.add(txt1); panel.add(txt2); panel.add(txt3); lbl1.setBounds(10, 50, 150, 20); panel.add(lbl1); lbl2.setBounds(10, 70, 150, 20); panel.add(lbl2); lbl3.setBounds(10, 90, 150, 20); panel.add(lbl3); } public void Addbottons(){ btnadd.setBounds(100, 115, 100, 20); btnadd.addActionListener(new addhandaler()); panel.add(btnadd); } public void Multiplybutton(){ btnmul.setBounds(100,140, 100, 20); btnmul.addActionListener(new mulhandaler()); panel.add(btnmul); } public void Divisionbutton(){ btndiv.setBounds(210, 115, 100, 20); btndiv.addActionListener(new divhandaler()); panel.add(btndiv); } public void Subtractionbutton(){ btnsub.setBounds(210, 140, 100, 20); btnsub.addActionListener(new subhandaler()); panel.add(btnsub); } class addhandaler implements ActionListener{ public void actionPerformed(ActionEvent e) { int num1= Integer.parseInt(txt1.getText()); int num2= Integer.parseInt(txt2.getText()); int numtotal= num1+num2; txt3.setText(String.valueOf(numtotal)); } } class subhandaler implements ActionListener{ public void actionPerformed(ActionEvent e) { int num1= Integer.parseInt(txt1.getText()); int num2= Integer.parseInt(txt2.getText()); int numtotal= num1-num2; txt3.setText(String.valueOf(numtotal)); } } class mulhandaler implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { int num1= Integer.parseInt(txt1.getText()); int num2= Integer.parseInt(txt2.getText()); int numtotal= num1*num2; txt3.setText(String.valueOf(numtotal)); } } class divhandaler implements ActionListener{ public void actionPerformed(ActionEvent e) { int num1= Integer.parseInt(txt1.getText()); int num2= Integer.parseInt(txt2.getText()); int numtotal= num1/num2; txt3.setText(String.valueOf(numtotal)); } } public void CreateFrom(){ frame.setTitle("Cal"); frame.setSize (400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(null); }public MyCal( ){ CreateFrom (); AddTxtField(); Addbottons(); Divisionbutton(); Multiplybutton(); Subtractionbutton(); frame.add(panel); frame.setVisible(true); } public static void main(String[] args) { new MyCal(); } }