Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * Combobox.java
- *
- * Created on 05.11.2018, 11:56:35
- */
- package combobox;
- import java.text.DecimalFormat;
- import javax.swing.JOptionPane;
- /**
- *
- * @author B309U09
- */
- public class Combobox extends javax.swing.JFrame {
- /** Creates new form Combobox */
- public Combobox() {
- initComponents();
- varianteLabel.setVisible(false);
- milchOptionCombo.setEnabled(false);
- vorspeiseLabel.setVisible(false);
- hauptgangLabel.setVisible(false);
- nachspeiseLabel.setVisible(false);
- endbetragLabel.setVisible(false);
- extraLabel.setVisible(false);
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- headerlabel = new javax.swing.JLabel();
- vorLabel = new javax.swing.JLabel();
- hauptLabel = new javax.swing.JLabel();
- nachLabel = new javax.swing.JLabel();
- vorCombo = new javax.swing.JComboBox();
- hauptCombo = new javax.swing.JComboBox();
- nachCombo = new javax.swing.JComboBox();
- varianteLabel = new javax.swing.JLabel();
- milchOptionCombo = new javax.swing.JComboBox();
- vorspeiseLabel = new javax.swing.JLabel();
- hauptgangLabel = new javax.swing.JLabel();
- nachspeiseLabel = new javax.swing.JLabel();
- extraLabel = new javax.swing.JLabel();
- endbetragLabel = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- headerlabel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- headerlabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- headerlabel.setText("Bitte wählen sie Ihr Menü");
- vorLabel.setText("Wähle eine Vorspeise:");
- hauptLabel.setText("Wähle einen Hauptgang:");
- nachLabel.setText("Wähle eine Nachspeise:");
- vorCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bitte auswählen", "Salat", "Suppe", "Bruscetta" }));
- vorCombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- vorComboActionPerformed(evt);
- }
- });
- hauptCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bitte auswählen", "Pizza", "Sphagetti", "Döner" }));
- nachCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bitte auswählen", "Kirschquark", "Schokoeis", "Milchreis" }));
- nachCombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- nachComboActionPerformed(evt);
- }
- });
- varianteLabel.setForeground(new java.awt.Color(255, 0, 0));
- varianteLabel.setText("Sie können eine Milchreisvariante wählen:");
- milchOptionCombo.setForeground(new java.awt.Color(255, 0, 0));
- milchOptionCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Standard (+0,00€)", "Zimt (+0,20€)", "Schokolade (+0,20€)" }));
- milchOptionCombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- milchOptionComboActionPerformed(evt);
- }
- });
- vorspeiseLabel.setText("Vorspeise:XX€");
- vorspeiseLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
- hauptgangLabel.setText("Hautpgang:XX€");
- hauptgangLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
- nachspeiseLabel.setText("Nachspeise:XX€");
- nachspeiseLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
- extraLabel.setForeground(new java.awt.Color(0, 0, 255));
- extraLabel.setText("Zuschlag Milchreis: 0,20€");
- endbetragLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- endbetragLabel.setText("Gesammtbetrag:XX€");
- jButton1.setText("Berechne Preis");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(headerlabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(vorLabel)
- .addComponent(hauptLabel)
- .addComponent(nachLabel)
- .addComponent(varianteLabel))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(milchOptionCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(vorCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(hauptCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(nachCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, 166, Short.MAX_VALUE)))))
- .addGroup(layout.createSequentialGroup()
- .addGap(99, 99, 99)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(extraLabel))
- .addComponent(nachspeiseLabel)
- .addComponent(endbetragLabel)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(vorspeiseLabel)
- .addComponent(hauptgangLabel)))
- .addGap(63, 63, 63)
- .addComponent(jButton1)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(headerlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(vorLabel)
- .addComponent(vorCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(hauptLabel)
- .addComponent(hauptCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(nachLabel)
- .addComponent(nachCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(varianteLabel)
- .addComponent(milchOptionCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(vorspeiseLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(hauptgangLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(nachspeiseLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(extraLabel)
- .addGap(18, 18, 18)
- .addComponent(endbetragLabel))
- .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap(17, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void milchOptionComboActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void vorComboActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- DecimalFormat f = new DecimalFormat("#0.00");
- double [] preiseVorspeise={0.00,2.99,3.45,2.35};
- double [] preiseHauptspeise={0.00,3.50,3.95,3.55};
- double [] preisNachspeise={0.00,1.50,2.55,1.95};
- int auswahl1 = vorCombo.getSelectedIndex();
- int auswahl2 = hauptCombo.getSelectedIndex();
- int auswahl3 = nachCombo.getSelectedIndex();
- int auswahlmilch= milchOptionCombo.getSelectedIndex();
- int extra = milchOptionCombo.getSelectedIndex();
- double preisVorspeise = preiseVorspeise[auswahl1];
- vorspeiseLabel.setText("Vorspeise: "+f.format(preisVorspeise)+"€");
- vorspeiseLabel.setVisible(true);
- double preisHaupt = preiseHauptspeise[auswahl2];
- hauptgangLabel.setText("Vorspeise: "+f.format(preisHaupt)+"€");
- hauptgangLabel.setVisible(true);
- double preisNach = preisNachspeise[auswahl3];
- nachspeiseLabel.setText("Vorspeise: "+f.format(preisNach)+"€");
- nachspeiseLabel.setVisible(true);
- if(auswahlmilch==0){
- extraLabel.setVisible(false);
- double ergebnis = preisVorspeise+preisHaupt+preisNach;
- endbetragLabel.setText("Gesammtbetrag: "+f.format(ergebnis)+"€");
- endbetragLabel.setVisible(true);
- }
- else{
- double ergebnis = preisVorspeise+preisHaupt+preisNach+0.20;
- JOptionPane.showMessageDialog(null,"Schoko/Zimt kostet 20 Cent Aufpreis!", "Hinweis", JOptionPane.CANCEL_OPTION);
- extraLabel.setVisible(true);
- endbetragLabel.setText("Gesammtbetrag: "+f.format(ergebnis)+"€");
- endbetragLabel.setVisible(true);
- }
- }
- private void nachComboActionPerformed(java.awt.event.ActionEvent evt) {
- if (nachCombo.getSelectedIndex()==3){
- milchOptionCombo.setEnabled(true);
- varianteLabel.setVisible(true);
- }
- else {milchOptionCombo.setEnabled(false);
- varianteLabel.setVisible(false);}
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Combobox.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Combobox.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Combobox.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Combobox.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Combobox().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel endbetragLabel;
- private javax.swing.JLabel extraLabel;
- private javax.swing.JComboBox hauptCombo;
- private javax.swing.JLabel hauptLabel;
- private javax.swing.JLabel hauptgangLabel;
- private javax.swing.JLabel headerlabel;
- private javax.swing.JButton jButton1;
- private javax.swing.JComboBox milchOptionCombo;
- private javax.swing.JComboBox nachCombo;
- private javax.swing.JLabel nachLabel;
- private javax.swing.JLabel nachspeiseLabel;
- private javax.swing.JLabel varianteLabel;
- private javax.swing.JComboBox vorCombo;
- private javax.swing.JLabel vorLabel;
- private javax.swing.JLabel vorspeiseLabel;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement