import java.awt.GridLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author alex_2
*/
public class Configuratore extends javax.swing.JFrame {
static PreventivoAuto preventivo;
/**
* Creates new form Configuratore
*/
public Configuratore() {
initComponents();
PreventivoAuto.recuperaDati();
String modelli[] = PreventivoAuto.getModelli();
for (int i=0; i < modelli.length; i++)
cmbModello.addItem(modelli[i]);
String colori[] = PreventivoAuto.getColori();
for (int i=0; i < colori.length; i++)
cmbColore.addItem(colori[i]);
/*Qui viene usata una tecnica non pulitissima ma semplice
*per gestire i radio button in modo quanto più simile
* ai comboBox
*/
JRadioButton radio[] = new JRadioButton[4];
radio[0] = rdbUno;
radio[1] = rdbDue;
radio[2] = rdbTre;
radio[3] = rdbQuattro;
String motorizzazioni[] = PreventivoAuto.getMotorizzazioni();
//Li nascondo tutti
for (int i=0; i < motorizzazioni.length; i++)
radio[i].setVisible(false);
//Faccio riapparire solo quelli realmente combinati con una motorizzazione
//in questo caso particolare tutti e quattro
for (int i=0; i < motorizzazioni.length; i++)
{
radio[i].setText(motorizzazioni[i]);
radio[i].setVisible(true);
}
//Setto il primo pulsante come selezionato
radio[0].setSelected(true);
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
btnGroupMotorizzazione = new javax.swing.ButtonGroup();
cmbModello = new javax.swing.JComboBox();
btnCalcola = new javax.swing.JButton();
cmbColore = new javax.swing.JComboBox();
lblPreventivo = new javax.swing.JLabel();
rdbUno = new javax.swing.JRadioButton();
rdbDue = new javax.swing.JRadioButton();
rdbTre = new javax.swing.JRadioButton();
rdbQuattro = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Preventivo auto");
cmbModello.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbModelloActionPerformed(evt);
}
});
btnCalcola.setText("Calcola");
btnCalcola.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCalcolaActionPerformed(evt);
}
});
cmbColore.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbColoreActionPerformed(evt);
}
});
lblPreventivo.setText("Preventivo: ");
btnGroupMotorizzazione.add(rdbUno);
rdbUno.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdbUnoActionPerformed(evt);
}
});
btnGroupMotorizzazione.add(rdbDue);
rdbDue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdbDueActionPerformed(evt);
}
});
btnGroupMotorizzazione.add(rdbTre);
rdbTre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdbTreActionPerformed(evt);
}
});
btnGroupMotorizzazione.add(rdbQuattro);
rdbQuattro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdbQuattroActionPerformed(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()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(rdbUno)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPreventivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(cmbModello, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnCalcola)
.addComponent(cmbColore, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(41, 41, 41))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rdbQuattro)
.addComponent(rdbTre)
.addComponent(rdbDue))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmbModello, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbColore, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addComponent(rdbUno)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rdbDue)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rdbTre)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rdbQuattro)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
.addComponent(btnCalcola)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblPreventivo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnCalcolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalcolaActionPerformed
lblPreventivo.setText("Preventivo: " + preventivo.getPreventivo() + " euro.");
}//GEN-LAST:event_btnCalcolaActionPerformed
private void cmbModelloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbModelloActionPerformed
preventivo.setModello(cmbModello.getSelectedIndex());
}//GEN-LAST:event_cmbModelloActionPerformed
private void cmbColoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbColoreActionPerformed
preventivo.setColore(cmbColore.getSelectedIndex());
}//GEN-LAST:event_cmbColoreActionPerformed
private void rdbUnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbUnoActionPerformed
preventivo.setMotorizzazione(0);
}//GEN-LAST:event_rdbUnoActionPerformed
private void rdbDueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbDueActionPerformed
preventivo.setMotorizzazione(1);
}//GEN-LAST:event_rdbDueActionPerformed
private void rdbTreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbTreActionPerformed
preventivo.setMotorizzazione(2);
}//GEN-LAST:event_rdbTreActionPerformed
private void rdbQuattroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbQuattroActionPerformed
preventivo.setMotorizzazione(3);
}//GEN-LAST:event_rdbQuattroActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
preventivo = new PreventivoAuto();
/* 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(Configuratore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Configuratore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Configuratore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Configuratore.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 Configuratore().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCalcola;
private javax.swing.ButtonGroup btnGroupMotorizzazione;
private javax.swing.JComboBox cmbColore;
private javax.swing.JComboBox cmbModello;
private javax.swing.JLabel lblPreventivo;
private javax.swing.JRadioButton rdbDue;
private javax.swing.JRadioButton rdbQuattro;
private javax.swing.JRadioButton rdbTre;
private javax.swing.JRadioButton rdbUno;
// End of variables declaration//GEN-END:variables
}