import javax.swing.JApplet;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MODos extends JApplet {
JTextField ftext;
JTextField stext;
JTextField ctext;
JButton compute;
JButton clear;
JButton exit;
// Set to global variable scope
JCheckBox add, subtract, divide, multiply;
int first,sec,comp;
public MODos() {
getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Enter First Number :");
lbl1.setBounds(67, 78, 160, 17);
getContentPane().add(lbl1);
JLabel lbl2 = new JLabel("Enter Second Number :");
lbl2.setBounds(67, 110, 160, 20);
getContentPane().add(lbl2);
final JLabel lblNewLabel_2 = new JLabel("");
lblNewLabel_2.setBounds(67, 175, 148, 14);
getContentPane().add(lblNewLabel_2);
ftext = new JTextField();
ftext.setBounds(237, 76, 118, 20);
getContentPane().add(ftext);
ftext.setColumns(10);
stext = new JTextField();
stext.setBounds(237, 110, 118, 20);
getContentPane().add(stext);
stext.setColumns(10);
ctext = new JTextField();
ctext.setBounds(237, 169, 118, 20);
getContentPane().add(ctext);
ctext.setColumns(10);
compute = new JButton("Compute");
compute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(add.isSelected()) {
first=Integer.parseInt(ftext.getText());
sec=Integer.parseInt(stext.getText());
comp=first+sec;
lblNewLabel_2.setText("Sum is :");
ctext.setText(comp+"");
}
else if(subtract.isSelected()){
first=Integer.parseInt(ftext.getText());
sec=Integer.parseInt(stext.getText());
comp=first-sec;
lblNewLabel_2.setText("Difference is :");
ctext.setText(comp+"");
}
else if(divide.isSelected()){
first=Integer.parseInt(ftext.getText());
sec=Integer.parseInt(stext.getText());
comp=first/sec;
lblNewLabel_2.setText("Quotient is :");
ctext.setText(comp+"");
}
else if(multiply.isSelected()){
first=Integer.parseInt(ftext.getText());
sec=Integer.parseInt(stext.getText());
comp=first*sec;
lblNewLabel_2.setText("Product is :");
ctext.setText(comp+"");
}
// If no operation was selected
else {
JOptionPane.showMessageDialog(null, "You must select an operator!");
}
}
});
compute.setBounds(58, 245, 89, 23);
getContentPane().add(compute);
JButton clear = new JButton("Clear");
clear.setBounds(167, 245, 89, 23);
getContentPane().add(clear);
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ftext.setText(null);
stext.setText(null);
ctext.setText(null);
add.setSelected(false);
multiply.setSelected(false);
subtract.setSelected(false);
divide.setSelected(false);
}
});
JButton exit = new JButton("Exit");
exit.setBounds(276, 245, 89, 23);
getContentPane().add(exit);
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
add = new JCheckBox("Add");
add.setBounds(58, 196, 89, 23);
getContentPane().add(add);
subtract = new JCheckBox("Subtract");
subtract.setBounds(228, 222, 83, 23);
getContentPane().add(subtract);
divide = new JCheckBox("Divide");
divide.setBounds(228, 196, 83, 23);
getContentPane().add(divide);
multiply = new JCheckBox("Multiply");
multiply.setBounds(58, 222, 89, 23);
getContentPane().add(multiply);
}
}