private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your// handling code here:
// Konstanten
final double film1=3;
final double film2=3;
final double film3=3;
final double film4=2;
final double film5=2;
final double film6=2;
final double film7=1;
final double film8=1;
final double film9=1;
// Einfühung der Variablen
double zeit, preis;
preis=0;
try {
zeit=Double.parseDouble(jTextField1.getText()); // liest Zahl der eingegebenen Tage aus dem Textfeld
// Eingabe beendet
//Eingabeabsicherung
if (!jTextField1.getText().matches("\\d+"))
throw new Exception ("Error1");
// Berechnung
if(jCheckBox1.isSelected()) // Prüft ob jRadiobutton1 ausgewählt ist
preis=film1*zeit;
if(jCheckBox2.isSelected())
preis=preis +film2*zeit;
if(jCheckBox3.isSelected())
preis=preis +film3*zeit;
if(jCheckBox4.isSelected())
preis=preis +film4*zeit;
if(jCheckBox5.isSelected())
preis=preis +film5*zeit;
if(jCheckBox6.isSelected())
preis=preis +film6*zeit;
if(jCheckBox7.isSelected())
preis=preis +film7*zeit;
if(jCheckBox8.isSelected())
preis=preis +film8*zeit;
if(jCheckBox9.isSelected())
preis=preis +film9*zeit;
}
catch (NumberFormatException s) {
JOptionPane msg = new JOptionPane ();
JOptionPane.showMessageDialog (msg,"Bitte Zahlen eingeben!", "Fehlermeldung", JOptionPane.ERROR_MESSAGE);
}
catch (Exception s) {
JOptionPane msg = new JOptionPane ();
if ((s.toString()).endsWith("Error1"))
JOptionPane.showMessageDialog(msg, "Bitte Zahlen eingeben!", "Fehlermeldung", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(msg, "Bitte Zahlen eingeben!", "Fehlermeldung", JOptionPane.ERROR_MESSAGE);
}
// Ausgabe
jTextField2.setText(df_0.format(preis));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0); // Programm beenden
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Felder löschen
jTextField1.setText("");
jTextField2.setText("");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JCheckBox jCheckBox4;
private javax.swing.JCheckBox jCheckBox5;
private javax.swing.JCheckBox jCheckBox6;
private javax.swing.JCheckBox jCheckBox7;
private javax.swing.JCheckBox jCheckBox8;
private javax.swing.JCheckBox jCheckBox9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
//Formatierte Ausgabe
DecimalFormat df_0 = new DecimalFormat ("###,##0.00 €" ); //Definieren des Formats
}