guys help me if these code is correct
import javax.swing.*;
import java.awt.event.*;
public class SampleCalc extends JFrame implements ActionListener{
JTextField txtNum1 = new JTextField();
JTextField txtNum2 = new JTextField();
JButton btnAdd = new JButton("+");
JButton btnSub = new JButton("-");
JButton btnMul = new JButton("*");
JButton btnDiv = new JButton("/");
JPanel pane = new JPanel();
public static void main(String args[]){
SampleCalc calc = new SampleCalc();
calc.setSize(300,300);
calc.setLocation(300,300);
calc.setResizable(false);
calc.setVisible(true);
calc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public SampleCalc() {
super("Calculator");
pane.setLayout(null);
txtNum1.setBounds(50,20,80,20);
txtNum2.setBounds(160,20,80,20);
btnAdd.setBounds(50,60,80,20);
btnSub.setBounds(160,60,80,20);
btnMul.setBounds(50,100,80,20);
btnDiv.setBounds(160,100,80,20);
pane.add(txtNum1);
pane.add(txtNum2);
pane.add(btnAdd);
pane.add(btnSub);
pane.add(btnMul);
pane.add(btnDiv);
btnAdd.addActionListener(this);
btnSub.addActionListener(this);
btnMul.addActionListener(this);
btnDiv.addActionListener(this);
setContentPane(pane);
}
public void actionPerformed(ActionEvent e){
String str1,str2;
str1 = txtNum1.getText();
str2 = txtNum2.getText();
if((str1.length() == 0)||(str2.length() == 0)){
JOptionPane.showMessageDialog(null,"You must input two numbers...");
}
else{
double num1 = Double.parseDouble(txtNum1.getText());
double num2 = Double.parseDouble(txtNum2.getText());
if(e.getSource() == btnAdd){
double sum;
sum = num1 + num2;
JOptionPane.showMessageDialog(null,"The Sum is: " + sum);
}
if(e.getSource() == btnSub){
double diff;
diff = num1 - num2;
JOptionPane.showMessageDialog(null,"The Difference is: " + diff);
}
if(e.getSource() == btnMul){
double pro;
pro = num1 * num2;
JOptionPane.showMessageDialog(null,"The Product is: " + pro);
}
if(e.getSource() == btnDiv){
double quo;
if(num2==0){
JOptionPane.showMessageDialog(null,"Cannot be divided by zero");
}
else{
quo = num1 / num2;
JOptionPane.showMessageDialog(null,"The Quotient is: " + quo);
}
}
}
}
}