import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Jframe extends JFrame implements ActionListener{
JButton b1=new JButton("+");
JButton b2=new JButton("-");
JButton b3=new JButton("*");
JButton b4=new JButton("/");
JButton b5=new JButton("=");
JTextField t1=new JTextField(5);
JTextField t2=new JTextField(5);
JTextField t3=new JTextField(5);
Jframe(){
setLayout(new FlowLayout());
setSize(400,300);
setVisible(true);
add(t1);
add(new JLabel("+"));
add(t2);
add(t3);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
addWindowListener(new Win());
}
public static void main(String args[]){
new frame();
}
public void actionPerformed(ActionEvent e){
if ((t1.getText()=="")||(t2.getText()==""))
{ JOptionPane.showMessageDialog(null,"Command: Open");}
else
{if (e.getSource()==b1){
int x=Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(x));}
if (e.getSource()==b2){
int x=Integer.parseInt(t1.getText())-Integer.parseInt(t2.getText());
t3.setText(Integer.toString(x));}
if (e.getSource()==b3){
int x=Integer.parseInt(t1.getText())*Integer.parseInt(t2.getText());
t3.setText(Integer.toString(x));}
if (e.getSource()==b4){
int x=Integer.parseInt(t1.getText())/Integer.parseInt(t2.getText());
t3.setText(Integer.toString(x));}}
}
}
class Win extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}