Documentos de Académico
Documentos de Profesional
Documentos de Cultura
/**
*
* @author Esteban
*/
import
import
import
import
import
import
import
java.awt.Color;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
javax.swing.JButton;
javax.swing.JFrame;
javax.swing.JPanel;
javax.swing.JTextField;
boton3.addActionListener(new EscucharATres());
boton4.addActionListener(new EscucharACuatro());
boton5.addActionListener(new EscucharACinco());
boton6.addActionListener(new EscucharASeis());
boton7.addActionListener(new EscucharASiete());
boton8.addActionListener(new EscucharAOcho());
boton9.addActionListener(new EscucharANueve());
boton0.addActionListener(new EscucharACero());
botonIgualar.addActionListener(new EscucharAIgual());
botondividiendo.addActionListener(new EscucharADivide());
botonSumar.addActionListener(new EscucharASuma());
botonRestar.addActionListener(new EscucharAResta());
botonMultiplicar.addActionListener(new EscucharAMultiplica());
botonLimpiar.addActionListener(new EscucharALimpia());
boton1.setLocation(0, 120);
boton1.setSize(45, 45);
boton2.setLocation(40, 120);
boton2.setSize(45, 45);
boton3.setLocation(80, 120);
boton3.setSize(45, 45);
boton4.setLocation(0, 80);
boton4.setSize(45, 45);
boton5.setLocation(40, 80);
boton5.setSize(45, 45);
boton6.setLocation(80, 80);
boton6.setSize(45, 45);
boton7.setLocation(0, 35);
boton7.setSize(45, 45);
boton8.setLocation(40, 35);
boton8.setSize(45, 45);
boton9.setLocation(80, 35);
boton9.setSize(45, 45);
boton0.setLocation(40, 165);
boton0.setSize(45, 45);
botonIgualar.setLocation(80, 165);
botonIgualar.setSize(45, 45);
botonLimpiar.setLocation(125, 35);
botonLimpiar.setSize(45, 45);
botonSumar.setLocation(125, 120);
botonSumar.setSize(45, 45);
botonRestar.setLocation(125, 165);
botonRestar.setSize(45, 45);
botondividiendo.setLocation(85, 80);
botondividiendo.setSize(0, 45);
botonMultiplicar.setLocation(125, 80);
botonMultiplicar.setSize(45, 45);
} //public main
class EscucharAUno implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("1");
} else {
campoTexto.setText(display + "1");
}
} else {
campoTexto.setText("1");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharADos implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("2");
} else {
campoTexto.setText(display + "2");
}
} else {
campoTexto.setText("2");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharATres implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("3");
} else {
campoTexto.setText(display + "3");
}
} else {
campoTexto.setText("3");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharACuatro implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("4");
} else {
campoTexto.setText(display + "4");
}
} else {
campoTexto.setText("4");
numero2 = Integer.parseInt(campoTexto.getText());
}
}
}
class EscucharACinco implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("5");
} else {
campoTexto.setText(display + "5");
}
} else {
campoTexto.setText("5");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharASeis implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("6");
} else {
campoTexto.setText(display + "6");
}
} else {
campoTexto.setText("6");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharASiete implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("7");
} else {
campoTexto.setText(display + "7");
}
} else {
campoTexto.setText("7");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharAOcho implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("8");
} else {
campoTexto.setText(display + "8");
}
} else {
campoTexto.setText("8");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharANueve implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("9");
} else {
campoTexto.setText(display + "9");
}
} else {
campoTexto.setText("9");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharACero implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = campoTexto.getText();
if (sumando == false && restando == false && multiplicando == false
&& dividiendo == false) {
if (display.equals("0")) {
campoTexto.setText("0");
} else {
campoTexto.setText(display + "0");
}
} else {
campoTexto.setText("0");
numero2 = Integer.parseInt(campoTexto.getText());
System.out.println(numero2);
}
}
}
class EscucharAIgual implements ActionListener {
public void actionPerformed(ActionEvent e) {
display=campoTexto.getText();
botonIgualar.setBackground(Color.GRAY);
campoTexto.setText(display+("="));
numero1=Integer.parseInt(campoTexto.getText());
System.out.println(numero1=numero2);
botonIgualar.setBackground(Color.BLUE);
boolean Igualar = true;
System.out.println("igualando="+Igualar);
}
}
class EscucharADivide implements ActionListener {
public void actionPerformed(ActionEvent e) {
display=campoTexto.getText();
botondividiendo.setBackground(Color.GRAY);
campoTexto.setText(display+("/"));
numero1=Integer.parseInt(campoTexto.getText());
System.out.println(numero1);
botondividiendo.setBackground(Color.BLUE);
dividiendo=true;
System.out.println("dividiendo="+dividiendo);
}
}
class EscucharASuma implements ActionListener {
public void actionPerformed(ActionEvent e) {
display=campoTexto.getText();
botonSumar.setBackground(Color.GRAY);
campoTexto.setText(display+("+"));
numero1=Integer.parseInt(campoTexto.getText());
System.out.println(numero1);
botonSumar.setBackground(Color.BLUE);
sumando=true;
System.out.println("sumando="+sumando);
}
}
class EscucharAResta implements ActionListener {
public void actionPerformed(ActionEvent e) {
display=campoTexto.getText();
botonRestar.setBackground(Color.GRAY);
campoTexto.setText(display+("-"));
numero1=Integer.parseInt(campoTexto.getText());
System.out.println(numero1);
botonRestar.setBackground(Color.BLUE);
restando=true;
System.out.println("restando="+restando);
}
}