package com.two;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JTextField;
public class Test3 extends Frame implements ActionListener,WindowListener{
private static final long serialVersionUID = 1796988870352036106L;
String aa = "";
double cc;
double bb;
double dd;
double ee;
double ff;
JTextField t;
Button b;
Button b1;
Button b2;
Button b3;
Button b4;
Button b5;
Button b6;
Button b7;
Button b8;
Button b9;
Button b10;
Button b11;
Button b12;
Button b13;
Button b14;
Button b15;
Button b16;
public Test3() {
this.setSize(300, 300);
t = new JTextField();
this.add(t, "North");
Panel p = new Panel();
p.setLayout(new GridLayout(4, 5));
b = new Button("1");
b1 = new Button("2");
b2 = new Button("3");
b3 = new Button("4");
b4 = new Button("5");
b5 = new Button("6");
b6 = new Button("7");
b7 = new Button("8");
b8 = new Button("9");
b9 = new Button("0");
b10 = new Button(".");
b11 = new Button("c");
b12 = new Button("+");
b13 = new Button("-");
b14 = new Button("*");
b15 = new Button("/");
b16 = new Button("=");
Label l = new Label();
Label l2 = new Label();
p.add(b);
p.add(b1);
p.add(b2);
p.add(b12);
p.add(b13);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b14);
p.add(b15);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(l);
p.add(l2);
p.add(b9);
p.add(b10);
p.add(b11);
p.add(b16);
this.add(p);
b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
this.addWindowListener(this);
this.setVisible(true);
}
public static void main(String args[]) {
new Test3();
}
public void actionPerformed(ActionEvent e) {
String a = null;
String a1 = null;
String a2 = null;
String a3 = null;
String a4 = null;
String a5 = null;
String a6 = null;
String a7 = null;
String a8 = null;
String a9 = null;
if (e.getSource() == b) {
a = b.getLabel();
aa += a;
t.setText(aa);
} else if (e.getSource() == b1) {
a1 = b1.getLabel();
aa += a1;
t.setText(aa);
} else if (e.getSource() == b2) {
a2 = b2.getLabel();
aa += a2;
t.setText(aa);
} else if (e.getSource() == b3) {
a3 = b3.getLabel();
aa += a3;
t.setText(aa);
} else if (e.getSource() == b4) {
a4 = b4.getLabel();
aa += a4;
t.setText(aa);
} else if (e.getSource() == b5) {
a5 = b5.getLabel();
aa += a5;
t.setText(aa);
} else if (e.getSource() == b6) {
a6 = b6.getLabel();
aa += a6;
t.setText(aa);
} else if (e.getSource() == b7) {
a7 = b7.getLabel();
aa += a7;
t.setText(aa);
} else if (e.getSource() == b8) {
a8 = b1.getLabel();
aa += a8;
t.setText(aa);
} else if (e.getSource() == b9) {
a9 = b9.getLabel();
aa += a9;
t.setText(aa);
} else if (e.getSource() == b12) {
if (dd != 0) {
bb = dd * Double.parseDouble(aa);
cc = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
cc = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
cc = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (cc != 0) {
bb = cc + Double.parseDouble(aa);
cc = bb;
aa = "";
t.setText(String.valueOf(cc));
} else {
t.setText("");
cc = Double.parseDouble(aa);
aa = "";
}
} else if (e.getSource() == b14) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
dd = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
dd = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
dd = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
dd = bb;
aa = "";
t.setText(String.valueOf(dd));
} else {
dd = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b15) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
ee = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
ee = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
ee = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
ee = bb;
aa = "";
t.setText(String.valueOf(ee));
} else {
ee = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b11) {
t.setText("");
aa = "";
bb = 0;
ee = 0;
cc = 0;
ff = 0;
dd = 0;
} else if (e.getSource() == b13) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
ff = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
ff = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
ff = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
ff = bb;
aa = "";
t.setText(String.valueOf(ff));
} else {
ff = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b10) {
aa = aa + ".";
}
if (e.getSource() == b16) {
if (cc == 0 && dd == 0 && ee == 0 && ff == 0) {
t.setText(String.valueOf(0));
} else if (dd == 0 && ee == 0 && ff == 0) {
bb = Double.parseDouble(aa);
cc = bb;
t.setText(String.valueOf(bb));
} else if (ee == 0 && ff == 0) {
bb = Double.parseDouble(aa) * dd;
t.setText(String.valueOf(bb));
} else if (ff == 0) {
bb = ee / Double.parseDouble(aa);
t.setText(String.valueOf(bb));
} else {
bb = ff - Double.parseDouble(aa);
t.setText(String.valueOf(bb));
}
}
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JTextField;
public class Test3 extends Frame implements ActionListener,WindowListener{
private static final long serialVersionUID = 1796988870352036106L;
String aa = "";
double cc;
double bb;
double dd;
double ee;
double ff;
JTextField t;
Button b;
Button b1;
Button b2;
Button b3;
Button b4;
Button b5;
Button b6;
Button b7;
Button b8;
Button b9;
Button b10;
Button b11;
Button b12;
Button b13;
Button b14;
Button b15;
Button b16;
public Test3() {
this.setSize(300, 300);
t = new JTextField();
this.add(t, "North");
Panel p = new Panel();
p.setLayout(new GridLayout(4, 5));
b = new Button("1");
b1 = new Button("2");
b2 = new Button("3");
b3 = new Button("4");
b4 = new Button("5");
b5 = new Button("6");
b6 = new Button("7");
b7 = new Button("8");
b8 = new Button("9");
b9 = new Button("0");
b10 = new Button(".");
b11 = new Button("c");
b12 = new Button("+");
b13 = new Button("-");
b14 = new Button("*");
b15 = new Button("/");
b16 = new Button("=");
Label l = new Label();
Label l2 = new Label();
p.add(b);
p.add(b1);
p.add(b2);
p.add(b12);
p.add(b13);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b14);
p.add(b15);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(l);
p.add(l2);
p.add(b9);
p.add(b10);
p.add(b11);
p.add(b16);
this.add(p);
b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
this.addWindowListener(this);
this.setVisible(true);
}
public static void main(String args[]) {
new Test3();
}
public void actionPerformed(ActionEvent e) {
String a = null;
String a1 = null;
String a2 = null;
String a3 = null;
String a4 = null;
String a5 = null;
String a6 = null;
String a7 = null;
String a8 = null;
String a9 = null;
if (e.getSource() == b) {
a = b.getLabel();
aa += a;
t.setText(aa);
} else if (e.getSource() == b1) {
a1 = b1.getLabel();
aa += a1;
t.setText(aa);
} else if (e.getSource() == b2) {
a2 = b2.getLabel();
aa += a2;
t.setText(aa);
} else if (e.getSource() == b3) {
a3 = b3.getLabel();
aa += a3;
t.setText(aa);
} else if (e.getSource() == b4) {
a4 = b4.getLabel();
aa += a4;
t.setText(aa);
} else if (e.getSource() == b5) {
a5 = b5.getLabel();
aa += a5;
t.setText(aa);
} else if (e.getSource() == b6) {
a6 = b6.getLabel();
aa += a6;
t.setText(aa);
} else if (e.getSource() == b7) {
a7 = b7.getLabel();
aa += a7;
t.setText(aa);
} else if (e.getSource() == b8) {
a8 = b1.getLabel();
aa += a8;
t.setText(aa);
} else if (e.getSource() == b9) {
a9 = b9.getLabel();
aa += a9;
t.setText(aa);
} else if (e.getSource() == b12) {
if (dd != 0) {
bb = dd * Double.parseDouble(aa);
cc = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
cc = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
cc = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(cc));
} else if (cc != 0) {
bb = cc + Double.parseDouble(aa);
cc = bb;
aa = "";
t.setText(String.valueOf(cc));
} else {
t.setText("");
cc = Double.parseDouble(aa);
aa = "";
}
} else if (e.getSource() == b14) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
dd = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
dd = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
dd = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(dd));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
dd = bb;
aa = "";
t.setText(String.valueOf(dd));
} else {
dd = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b15) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
ee = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
ee = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
ee = bb;
ff = 0;
aa = "";
t.setText(String.valueOf(ee));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
ee = bb;
aa = "";
t.setText(String.valueOf(ee));
} else {
ee = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b11) {
t.setText("");
aa = "";
bb = 0;
ee = 0;
cc = 0;
ff = 0;
dd = 0;
} else if (e.getSource() == b13) {
if (cc != 0) {
bb = cc + Double.parseDouble(aa);
ff = bb;
cc = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (dd != 0) {
bb = dd * Double.parseDouble(aa);
ff = bb;
dd = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (ee != 0) {
bb = ee / Double.parseDouble(aa);
ff = bb;
ee = 0;
aa = "";
t.setText(String.valueOf(ff));
} else if (ff != 0) {
bb = ff - Double.parseDouble(aa);
ff = bb;
aa = "";
t.setText(String.valueOf(ff));
} else {
ff = Double.parseDouble(aa);
t.setText("");
aa = "";
}
} else if (e.getSource() == b10) {
aa = aa + ".";
}
if (e.getSource() == b16) {
if (cc == 0 && dd == 0 && ee == 0 && ff == 0) {
t.setText(String.valueOf(0));
} else if (dd == 0 && ee == 0 && ff == 0) {
bb = Double.parseDouble(aa);
cc = bb;
t.setText(String.valueOf(bb));
} else if (ee == 0 && ff == 0) {
bb = Double.parseDouble(aa) * dd;
t.setText(String.valueOf(bb));
} else if (ff == 0) {
bb = ee / Double.parseDouble(aa);
t.setText(String.valueOf(bb));
} else {
bb = ff - Double.parseDouble(aa);
t.setText(String.valueOf(bb));
}
}
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}