calculadora

JV
12 de Marzo del 2004
Estoy haciendo una calculadora con el JBuilder. Mi problema es que me realiza todas las operaciones menos la división. He cambiado el tipo de variable de enteras(int) a real (float), pero cuando hago esto solo me deja realizar un calculo y se bloquea. Hay alguna forma de recoger los números de la pantalla y transformarlos en float sin que se bloquee.

Pelly
12 de Marzo del 2004
Por el codigo que has puesto creo que el fallo es que te has dejado un punto y coma.Pon algo de codigo por que si no no sabemos que es lo que has hecho :-).
Un saludo

JD
12 de Marzo del 2004
Aqui te mando el código de la calculadora, haber si me puedes ayudar. Gracias .Es urgente.

package untitled1;

import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;

public class Frame1 extends DecoratedFrame {
BorderLayout borderLayout1 = new BorderLayout();
XYLayout xYLayout2 = new XYLayout();
BevelPanel bevelPanel1 = new BevelPanel();
BevelPanel bevelPanel2 = new BevelPanel();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
Button button5 = new Button();
Button button6 = new Button();
Button button7 = new Button();
Button button8 = new Button();
Button button9 = new Button();
Button button10 = new Button();
Button button11 = new Button();
Button button12 = new Button();
Button button13 = new Button();
TextField textField1 = new TextField();
int digito1=0;
int suma1=0, resta = 0;
int igual=0,producto=1;
char bandera;
int division =1,igual2=0;
Button button14 = new Button();
Button button15 = new Button();
Button button16 = new Button();
//Construct the frame
public Frame1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
button1.setLabel("0");
button1.addMouseListener(new Frame1_button1_mouseAdapter(this));
button2.setLabel("1");
button2.addMouseListener(new Frame1_button2_mouseAdapter(this));
button3.setLabel("2");
button3.addMouseListener(new Frame1_button3_mouseAdapter(this));
button4.setLabel("3");
button4.addMouseListener(new Frame1_button4_mouseAdapter(this));
button5.setLabel("4");
button5.addMouseListener(new Frame1_button5_mouseAdapter(this));
button6.setLabel("5");
button6.addMouseListener(new Frame1_button6_mouseAdapter(this));
button7.setLabel("6");
button7.addMouseListener(new Frame1_button7_mouseAdapter(this));
button8.setLabel("7");
button8.addMouseListener(new Frame1_button8_mouseAdapter(this));
button9.setLabel("8");
button9.addMouseListener(new Frame1_button9_mouseAdapter(this));
button10.setLabel("9");
button10.addMouseListener(new Frame1_button10_mouseAdapter(this));
button11.setFont(new Font("Dialog", 1, 14));
button11.setLabel("+");
button11.addActionListener(new Frame1_button11_actionAdapter(this));
button11.addMouseListener(new Frame1_button11_mouseAdapter(this));
button12.setFont(new Font("Dialog", 1, 14));
button12.setLabel("-");
button12.addMouseListener(new Frame1_button12_mouseAdapter(this));
button13.setFont(new Font("Dialog", 1, 14));
button13.setLabel("=");
button14.setLabel("C");
button15.setLabel("X");
button15.addMouseListener(new Frame1_button15_mouseAdapter(this));
button16.setLabel("/");
button16.addMouseListener(new Frame1_button16_mouseAdapter(this));
button14.addMouseListener(new Frame1_button14_mouseAdapter(this));
button13.addMouseListener(new Frame1_button13_mouseAdapter(this));
bevelPanel1.setLayout(xYLayout2);
this.add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(bevelPanel2, new XYConstraints(65, 4, 226, 245));
bevelPanel2.add(button1, new XYConstraints(55, 181, 30, 30));
bevelPanel2.add(button2, new XYConstraints(11, 147, 30, 30));
bevelPanel2.add(button3, new XYConstraints(55, 148, 30, 30));
bevelPanel2.add(button4, new XYConstraints(99, 149, 30, 30));
bevelPanel2.add(button5, new XYConstraints(11, 112, 30, 30));
bevelPanel2.add(button6, new XYConstraints(55, 113, 30, 30));
bevelPanel2.add(button7, new XYConstraints(99, 113, 30, 30));
bevelPanel2.add(button8, new XYConstraints(11, 76, 30, 30));
bevelPanel2.add(button9, new XYConstraints(55, 77, 30, 30));
bevelPanel2.add(button10, new XYConstraints(99, 78, 30, 30));
bevelPanel2.add(button11, new XYConstraints(146, 117, 30, 60));
bevelPanel2.add(button12, new XYConstraints(146, 78, 30, 30));
bevelPanel2.add(button13, new XYConstraints(146, 181, 30, 30));
bevelPanel2.add(textField1, new XYConstraints(11, 39, 160, 26));
bevelPanel2.add(button14, new XYConstraints(184, 78, 30, 30));
bevelPanel2.add(button15, new XYConstraints(185, 115, 30, 30));
bevelPanel2.add(button16, new XYConstraints(185, 150, 30, 30));
}

void button1_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"0");


}

void button2_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"1");
}

void button3_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"2");
}

void button4_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"3");
}

void button5_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"4");
}

void button6_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"5");
}

void button7_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"6");
}

void button8_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"7");
}

void button9_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"8");
}

void button10_mousePressed(MouseEvent e) {
textField1.setText(textField1.getText()+"9");
}
//simbolo mas//
void button11_mousePressed(MouseEvent e) {
digito1 = (Integer.parseInt(textField1.getText()));
suma1 = (digito1 + suma1);
igual=suma1;
textField1.setText(null);bandera='1';

}
//simbolo igual//
void button13_mousePressed(MouseEvent e) {
switch (bandera){
case '1':
digito1 = (Integer.parseInt(textField1.getText()));
igual=(igual+digito1);
textField1.setText(String.valueOf(igual));
igual=0;suma1=0;division=1;break;
case '2':
digito1 = (Integer.parseInt(textField1.getText()));
igual=(igual-digito1);
textField1.setText(String.valueOf(igual));
igual=0;resta=0;break;
case '3':
digito1= (Integer.parseInt(textField1.getText()));
igual=(igual*digito1);
textField1.setText(String.valueOf(igual));
igual=0;producto=1;break;
case '4':
digito1= (Integer.parseInt(textField1.getText()));
igual=(igual/digito1);
textField1.setText(String.valueOf(igual));
igual=0;division=1;break;}
}

void button14_mousePressed(MouseEvent e) {
textField1.setText(null);
suma1=0; digito1=0;
}
//simbolo resta//
void button12_mousePressed(MouseEvent e) {
digito1 = (Integer.parseInt(textField1.getText()));
resta = (digito1 -resta);
igual=resta;
textField1.setText(null);bandera='2';
}

void button11_actionPerformed(ActionEvent e) {

}
//simbolo multiplicación//
void button15_mousePressed(MouseEvent e) {
digito1 = (Integer.parseInt(textField1.getText()));
producto = (digito1 * producto);
igual=producto;
textField1.setText(null);bandera='3';

}
//simbolo division//
void button16_mousePressed(MouseEvent e) {
digito1 = (Integer.parseInt(textField1.getText()));
division = (digito1 / division);
igual=division;
textField1.setText(null);bandera='4';
}

}

class Frame1_button1_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button1_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button1_mousePressed(e);
}
}

class Frame1_button2_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button2_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button2_mousePressed(e);
}
}

class Frame1_button3_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button3_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button3_mousePressed(e);
}
}

class Frame1_button4_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button4_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button4_mousePressed(e);
}
}

class Frame1_button5_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button5_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button5_mousePressed(e);
}
}

class Frame1_button6_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button6_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button6_mousePressed(e);
}
}

class Frame1_button7_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button7_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button7_mousePressed(e);
}
}

class Frame1_button8_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button8_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button8_mousePressed(e);
}
}

class Frame1_button9_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button9_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button9_mousePressed(e);
}
}

class Frame1_button10_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button10_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button10_mousePressed(e);
}
}

class Frame1_button11_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button11_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button11_mousePressed(e);
}
}

class Frame1_button13_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button13_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button13_mousePressed(e);
}
}

class Frame1_button14_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button14_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button14_mousePressed(e);
}
}

class Frame1_button12_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button12_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button12_mousePressed(e);
}
}

class Frame1_button11_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;

Frame1_button11_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button11_actionPerformed(e);
}
}

class Frame1_button15_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button15_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button15_mousePressed(e);
}
}

class Frame1_button16_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;

Frame1_button16_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void mousePressed(MouseEvent e) {
adaptee.button16_mousePressed(e);
}
}



enrique
12 de Marzo del 2004
yo programe una calculadora con java!
tengo el codigo fuente libre, si te interesa, la puedes conseguir en esta direccion!

http://galeon.com/starcraftmex/progs.html

Pedro Erique
12 de Marzo del 2004
Gracias Enrique, me has salvado la vida con el código de tu calculadora estaba en un apuro por un examen de programación y te comento que el requisito de entrada al examen era de entregar el código fuente de un calculadora. Te consulto a ver si puedes ayudarme a crear un ejecutable de esta calculadora.
Gracias Nuevamente, saludos

melissa
12 de Marzo del 2004
puedes hacer algo asi
num2=Float.parseFloat(TxtVisor.getText());resu=num1/num2;
TxtVisor.setText(Float.toString(resu));break;