calculadora

nestor
03 de Junio del 2004
Necesito una calculadora científica programada en java

Lucas
03 de Junio del 2004
Y yo necesito un ERP a medida para un fabricante de vidrio. Vamos a ver, que esto no es un sitio para que te hagan las cosas. Si quieres algo hecho, pasate por www.jars.com, www.surceforge.net para bajarte aplicaciones java. Si quieres el codigo fuente de alguien que lo haya hecho, prueba suerte. Si es para una practica, ponte a currar y hazla solito.

karla
03 de Junio del 2004
public class Calcu extends javax.swing.JFrame {
int operacion,fac,valor,valort;
double n1,n2;
int aux=1;
int num,cont1;


public Calcu() {
initComponents();
setSize(400,350);
}


private void initComponents() {//GEN-BEGIN:initComponents
botones = new javax.swing.ButtonGroup();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jRadioButton5 = new javax.swing.JRadioButton();
jRadioButton6 = new javax.swing.JRadioButton();

getContentPane().setLayout(null);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("CALCULADORA");
setBackground(new java.awt.Color(204, 204, 204));
setFont(new java.awt.Font("Comic Sans MS", 0, 10));
setMaximizedBounds(new java.awt.Rectangle(0, 0, 0, 0));
setResizable(false);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

getContentPane().add(jTextField1);
jTextField1.setBounds(40, 30, 70, 22);

jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});

getContentPane().add(jTextField2);
jTextField2.setBounds(40, 70, 70, 22);

getContentPane().add(jTextField3);
jTextField3.setBounds(40, 200, 90, 22);

jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jLabel1.setForeground(new java.awt.Color(0, 51, 153));
jLabel1.setText("1\u00b0 Numero");
getContentPane().add(jLabel1);
jLabel1.setBounds(130, 30, 80, 14);

jLabel2.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jLabel2.setForeground(new java.awt.Color(0, 51, 153));
jLabel2.setText("2\u00b0 Numero");
getContentPane().add(jLabel2);
jLabel2.setBounds(130, 70, 80, 14);

jButton1.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jButton1.setForeground(new java.awt.Color(0, 51, 153));
jButton1.setText("TOTAL");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

getContentPane().add(jButton1);
jButton1.setBounds(40, 240, 90, 23);

jButton2.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jButton2.setForeground(new java.awt.Color(0, 51, 153));
jButton2.setText("LIMPIAR");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

getContentPane().add(jButton2);
jButton2.setBounds(270, 240, 100, 25);

jRadioButton1.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton1.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton1.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton1.setText("SUMAR");
botones.add(jRadioButton1);
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton1);
jRadioButton1.setBounds(230, 20, 61, 23);

jRadioButton2.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton2.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton2.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton2.setText("RESTAR");
botones.add(jRadioButton2);
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton2);
jRadioButton2.setBounds(230, 50, 65, 23);

jRadioButton3.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton3.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton3.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton3.setText("MULTIPLICAR");
botones.add(jRadioButton3);
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton3);
jRadioButton3.setBounds(230, 80, 95, 23);

jRadioButton4.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton4.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton4.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton4.setText("DIVIDIR");
botones.add(jRadioButton4);
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton4ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton4);
jRadioButton4.setBounds(230, 110, 67, 23);

jRadioButton5.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton5.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton5.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton5.setText("FACTORIAL");
botones.add(jRadioButton5);
jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton5ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton5);
jRadioButton5.setBounds(230, 140, 83, 23);

jRadioButton6.setBackground(new java.awt.Color(204, 204, 255));
jRadioButton6.setFont(new java.awt.Font("Comic Sans MS", 0, 10));
jRadioButton6.setForeground(new java.awt.Color(0, 51, 153));
jRadioButton6.setText("PRIMO");
botones.add(jRadioButton6);
jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton6ActionPerformed(evt);
}
});

getContentPane().add(jRadioButton6);
jRadioButton6.setBounds(230, 170, 59, 23);

pack();
}//GEN-END:initComponents

private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton6ActionPerformed
operacion = 6;
jTextField2.setText("0");
}//GEN-LAST:event_jRadioButton6ActionPerformed

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
n2 = Double.valueOf(jTextField1.getText()).doubleValue();
}//GEN-LAST:event_jTextField2ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}//GEN-LAST:event_jButton2ActionPerformed

private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton5ActionPerformed
operacion = 5;
jTextField2.setText("0");
}//GEN-LAST:event_jRadioButton5ActionPerformed

private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
operacion = 3;

}//GEN-LAST:event_jRadioButton3ActionPerformed

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
operacion = 1;


}//GEN-LAST:event_jRadioButton1ActionPerformed

private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed
operacion = 4;

}//GEN-LAST:event_jRadioButton4ActionPerformed

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
operacion = 2;

}//GEN-LAST:event_jRadioButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
n1 = Double.valueOf(jTextField1.getText()).doubleValue();
n2 = Double.valueOf(jTextField2.getText()).doubleValue();
fac = Integer.valueOf(jTextField1.getText()).intValue();
num = Integer.valueOf(jTextField1.getText()).intValue();
if(operacion == 1){
jTextField3.setText(String.valueOf(n1+n2));
}
if(operacion == 2){
jTextField3.setText(String.valueOf(n1-n2));
}
if(operacion == 3){
jTextField3.setText(String.valueOf(n1/n2));
}
if(operacion == 4){
jTextField3.setText(String.valueOf(n1*n2));
}

if(operacion ==5){

for(int i=1;i<=fac;i++){
aux=aux*i;
}

jTextField3.setText(String.valueOf(aux));
aux=1;
}
if(operacion ==6){
cont1=0;
while(aux!=num)
{
if((num%aux)==0){
aux++;
cont1++;
}
if(cont1==2){
jTextField3.setText(String.valueOf("Es primo"));
}
else{
jTextField3.setText(String.valueOf("No es primo"));
}

}

}

}//GEN-LAST:event_jButton1ActionPerformed

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
n1 = Double.valueOf(jTextField1.getText()).doubleValue();
}//GEN-LAST:event_jTextField1ActionPerformed



public static void main(String args[]) {
new Calcu().show();
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup botones;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JRadioButton jRadioButton4;
private javax.swing.JRadioButton jRadioButton5;
private javax.swing.JRadioButton jRadioButton6;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration//GEN-END:variables

}

tengo esta a medias, quizas te podria sevir y vos seguir modificandola a tu gusto.