Help with Building a GUI
843805Sep 26 2006 — edited Sep 26 2006I'm trying to activate my buttons "Calculate" and "Exit" for my Box Volume Calculator GUI I created with NetBeans. I get the error message "if without else".
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if (evt.getSource()==btnCalculate)
doCalculate();
else if (evt.getSource()==btnExit)
System.exit(0);
}
void doCalculate() {
double height;
double width;
double depth;
double volumeCalc;
height =Double.parseDouble(txtHeight.getText());
width =Double.parseDouble(txtWidth.getText());
depth =Double.parseDouble(txtDepth.getText());
volumeCalc =height*width*depth;
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
if (evt.getSource()==btnCalculate)
doCalculate();
else if (evt.getSource()==btnExit)
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BoxVolCalc().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration//GEN-END:variables
{
{
}}}