Calculadora AWT y SWING
Hola Como estan.. bueno tengo un problema... en mi universidad me acaban de dejar como trabajo que haga una pequeña calculadora.. estoy trabjando con netbens y en mi pantalla tengo: 2 JRadio Button.. ( Suma y Resta)tengo 3 JTextField( dos para colocar datos, y uno mas para que aparesca la respuesta.. )
Bueno agradeceria bastante que me respondan..tengo bastante dificultades para hacerlo..solo quiero saber como hago para que se sumen.. para tener una idea.. ACa les mando mi codigo:
package demo2;
public class Ventana01 extends javax.swing.JFrame {
public Ventana01() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jTextField3 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
getContentPane().setLayout(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sistema de Ventas");
jLabel1.setText("Numero 1");
getContentPane().add(jLabel1);
jLabel1.setBounds(30, 40, 60, 14);
jLabel2.setText("Numero 2");
getContentPane().add(jLabel2);
jLabel2.setBounds(30, 70, 60, 14);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(100, 40, 50, 20);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(100, 70, 50, 20);
jRadioButton1.setText("Suma");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
getContentPane().add(jRadioButton1);
jRadioButton1.setBounds(200, 40, 53, 23);
jRadioButton2.setText("Resta");
getContentPane().add(jRadioButton2);
jRadioButton2.setBounds(200, 70, 53, 23);
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
getContentPane().add(jTextField3);
jTextField3.setBounds(100, 120, 200, 20);
jLabel3.setText("Respuesta");
getContentPane().add(jLabel3);
jLabel3.setBounds(30, 120, 60, 20);
pack();
}
// </editor-fold>
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Ventana01().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}
Bueno agradeceria bastante que me respondan..tengo bastante dificultades para hacerlo..solo quiero saber como hago para que se sumen.. para tener una idea.. ACa les mando mi codigo:
package demo2;
public class Ventana01 extends javax.swing.JFrame {
public Ventana01() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jTextField3 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
getContentPane().setLayout(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sistema de Ventas");
jLabel1.setText("Numero 1");
getContentPane().add(jLabel1);
jLabel1.setBounds(30, 40, 60, 14);
jLabel2.setText("Numero 2");
getContentPane().add(jLabel2);
jLabel2.setBounds(30, 70, 60, 14);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(100, 40, 50, 20);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(100, 70, 50, 20);
jRadioButton1.setText("Suma");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
getContentPane().add(jRadioButton1);
jRadioButton1.setBounds(200, 40, 53, 23);
jRadioButton2.setText("Resta");
getContentPane().add(jRadioButton2);
jRadioButton2.setBounds(200, 70, 53, 23);
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
getContentPane().add(jTextField3);
jTextField3.setBounds(100, 120, 200, 20);
jLabel3.setText("Respuesta");
getContentPane().add(jLabel3);
jLabel3.setBounds(30, 120, 60, 20);
pack();
}
// </editor-fold>
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Ventana01().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}