Risolto
package parcheggio;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Parcheggio implements Runnable {
int nauto;
static final int MAXAUTO = 200;
Auto[] auto;
double credito;
GregorianCalendar gc;
DecimalFormat df = new DecimalFormat("#,##0.00");
int oraentrata, minutientrata;
JTextArea display;
JComboBox selezionaAuto;
int massimoauto;
public Parcheggio() {
this.auto = new Auto[MAXAUTO];
this.nauto = 0;
this.selezionaAuto = new JComboBox();
this.massimoauto = MAXAUTO;
}
public Parcheggio(JTextArea display) {
this.display = display;
}
public int getAuto() {
return nauto;
}
public Auto getAuto(int i) {
return auto[i];
}
public String getAperto() {
while (true) {
gc = new GregorianCalendar();
int ore = gc.get(Calendar.HOUR_OF_DAY);
int oraapertura = 8;
int orachiusura = 24;
if (ore >= oraapertura && ore <= orachiusura) {
return "siamo aperti";
} else {
return "siamo chiusi" + "\n" + "l'orario apertura è dalle:" + "\t" + oraapertura + "alle:" + "\t" + orachiusura;
}
}
}
public String acetta10cent(String par) {
if (par.equalsIgnoreCase("0.1")) {
credito += 0.1;
}
return df.format(credito) + "\t" + "€";
}
public String acetta20cent(String par) {
if (par.equalsIgnoreCase("0.2")) {
credito += 0.2;
}
return df.format(credito) + "\t" + "€";
}
public String acetta50cent(String par) {
if (par.equalsIgnoreCase("0.5")) {
credito += 0.5;
}
return df.format(credito) + "\t" + "€";
}
public String acettaUno(String par) {
if (par.equalsIgnoreCase("1.0")) {
credito += 1.0;
}
return df.format(credito) + "\t" + "€";
}
public String acettaDue(String par) {
if (par.equalsIgnoreCase("2.0")) {
credito += 2.0;
}
return df.format(credito) + "\t" + "€";
}
public String acettaCinque(String par) {
if (par.equalsIgnoreCase("5.0")) {
credito += 5.0;
}
return df.format(credito) + "€";
}
public String acettaDieci(String par) {
if (par.equalsIgnoreCase("10.0")) {
credito += 10.0;
}
return df.format(credito) + "\t" + "€";
}
public String acettaVenti(String par) {
if (par.equalsIgnoreCase("20.0")) {
credito += 20.0;
}
return df.format(credito) + "\t" + "€";
}
public double getCredito() {
return credito;
}
public void entraAuto(String targa, int oraentrata, int minutientrata) {
if (nauto < MAXAUTO) {
auto[nauto++] = new Auto(targa, oraentrata, minutientrata);
} else {
JOptionPane.showMessageDialog(null, "posti esauriti", " Errore", JOptionPane.ERROR_MESSAGE);
}
}
public String datiScontrino(int orauscita, int minutiuscita) {
String tariffa = "";
String r = "";
String tempopassato = "";
String importo = "";
String orarioUscita = "";
String scontrino = "";
String risultato = "";
double resto = 0.0;
int orepassate = Math.abs(oraentrata - orauscita);
double prezzo = 0.0;
int minutipassati = Math.abs(minutientrata - minutiuscita);
if (orepassate <= 1) {
prezzo = 1.80;
} else if ((orepassate == 1 && minutipassati >= 30) || orepassate == 2) {
prezzo = 3.60;
} else if ((orepassate == 2 && minutipassati >= 30) || orepassate == 3) {
prezzo = 5.40;
} else if ((orepassate == 3 && minutipassati >= 30) || orepassate == 4) {
prezzo = 7.20;
} else if ((orepassate == 4 && minutipassati >= 30) || orepassate <= 8) {
prezzo = 7.50;
} else if (orepassate <= 10) {
prezzo = 7.50 + 1.80;
} else {
prezzo = 12.50;
}
if (getCredito() == 0) {
JOptionPane.showMessageDialog(null, "devi pagare!", " Errore", JOptionPane.ERROR_MESSAGE);
risultato = "";
} else if (getCredito() < prezzo) {
double creditomancante = prezzo - getCredito();
JOptionPane.showMessageDialog(null, "lei deve ancora:" + "\t" + df.format(creditomancante) + "\t" + "€", " Errore", JOptionPane.ERROR_MESSAGE);
risultato = "";
} else {
resto = getCredito() - prezzo;
importo = "l'importo pagato:" + "\t" + df.format(getCredito()) + "\t" + "€";
tariffa = "totale complessivo:" + "\t" + df.format(prezzo) + "\t" + "€";
if (resto == 0) {
r = "";
} else {
r = "il resto è:" + "\t" + df.format(resto) + "\t" + "€";
}
tempopassato = "ore passate:" + "\t" + orepassate + "\t" + "minuti passati:" + minutipassati;
[b] orarioUscita = "ora uscita:" + "\t" + orauscita + "\t" + "minuti uscita:" + minutiuscita;[/b]
risultato = orarioUscita + "\n" + tempopassato + "\n" + tariffa + "\n" + importo + "\n" + r;
}
return risultato;
}
public String Ticket() {
String s = "";
for (int i = 0; i < nauto; i++) {
s += "ticket n°" + "\t" + i + "\n" + auto[i].stampaTarga() + "\n" + auto[i].stampaoraEntrata() + "\n";
}
return s;
}
@Override
public void run() {
display.setText(getAperto());
}
}
package parcheggio;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Interfaccia extends javax.swing.JDialog {
Integer oraentrata, minutientrata, orauscita, minutiuscita, postiliberi, postioccupati,numeroscontrino;
String targa;
Parcheggio p;
public Interfaccia(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(null);
Thread t = new Thread(new Orologio(orologio));
t.start();
Thread t2 = new Thread(new Parcheggio(display));
t2.start();
p = new Parcheggio();
postiliberi = p.massimoauto;
postioccupati = 0;
numeroscontrino=0;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
lbloraentrata = new javax.swing.JLabel();
lblminutientrata = new javax.swing.JLabel();
txtoraentrata = new javax.swing.JTextField();
txtminutientrata = new javax.swing.JTextField();
entraAuto = new javax.swing.JButton();
lbltarga = new javax.swing.JLabel();
txttarga = new javax.swing.JTextField();
orologio = new javax.swing.JLabel();
esceAuto = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtscontrino = new javax.swing.JTextArea();
acetta10cent = new javax.swing.JButton();
acetta20cent = new javax.swing.JButton();
acetta50cent = new javax.swing.JButton();
acetta1euro = new javax.swing.JButton();
acetta2euro = new javax.swing.JButton();
acetta5euro = new javax.swing.JButton();
acetta10euro = new javax.swing.JButton();
acetta20euro = new javax.swing.JButton();
txtcredito = new javax.swing.JTextField();
lblpostiauto = new javax.swing.JLabel();
selezionaAuto = new javax.swing.JComboBox();
lblorauscita = new javax.swing.JLabel();
lblminutiuscita = new javax.swing.JLabel();
txtorauscita = new javax.swing.JTextField();
txtminutiuscita = new javax.swing.JTextField();
jScrollPane3 = new javax.swing.JScrollPane();
display = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
txtticket = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Parcheggio");
setBackground(java.awt.Color.white);
lbloraentrata.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lbloraentrata.setText("ora entrata:");
lblminutientrata.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lblminutientrata.setText("minuti entrata:");
txtoraentrata.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
txtoraentrata.setToolTipText("");
txtoraentrata.setName(""); // NOI18N
txtminutientrata.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
entraAuto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
entraAuto.setForeground(java.awt.Color.blue);
entraAuto.setText("entraAuto");
entraAuto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
entraAutoActionPerformed(evt);
}
});
lbltarga.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lbltarga.setText("targa:");
txttarga.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
orologio.setBackground(java.awt.Color.white);
orologio.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
orologio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
orologio.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.red, java.awt.Color.red, java.awt.Color.red, java.awt.Color.red));
orologio.setEnabled(false);
orologio.setOpaque(true);
esceAuto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
esceAuto.setForeground(java.awt.Color.blue);
esceAuto.setText("esceAuto");
esceAuto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
esceAutoActionPerformed(evt);
}
});
txtscontrino.setEditable(false);
txtscontrino.setColumns(20);
txtscontrino.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
txtscontrino.setRows(5);
txtscontrino.setDisabledTextColor(java.awt.Color.black);
txtscontrino.setEnabled(false);
jScrollPane1.setViewportView(txtscontrino);
acetta10cent.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta10cent.setForeground(java.awt.Color.blue);
acetta10cent.setText("0.1 €");
acetta10cent.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta10centActionPerformed(evt);
}
});
acetta20cent.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta20cent.setForeground(java.awt.Color.blue);
acetta20cent.setText("0.2 €");
acetta20cent.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta20centActionPerformed(evt);
}
});
acetta50cent.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta50cent.setForeground(java.awt.Color.blue);
acetta50cent.setText("0.5 €");
acetta50cent.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta50centActionPerformed(evt);
}
});
acetta1euro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta1euro.setForeground(java.awt.Color.blue);
acetta1euro.setText("1 €");
acetta1euro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta1euroActionPerformed(evt);
}
});
acetta2euro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta2euro.setForeground(java.awt.Color.blue);
acetta2euro.setText("2 €");
acetta2euro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta2euroActionPerformed(evt);
}
});
acetta5euro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta5euro.setForeground(java.awt.Color.blue);
acetta5euro.setText("5 €");
acetta5euro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta5euroActionPerformed(evt);
}
});
acetta10euro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta10euro.setForeground(java.awt.Color.blue);
acetta10euro.setText("10 €");
acetta10euro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta10euroActionPerformed(evt);
}
});
acetta20euro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
acetta20euro.setForeground(java.awt.Color.blue);
acetta20euro.setText("20 €");
acetta20euro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acetta20euroActionPerformed(evt);
}
});
txtcredito.setEditable(false);
txtcredito.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
txtcredito.setForeground(java.awt.Color.red);
lblpostiauto.setBackground(java.awt.Color.black);
lblpostiauto.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lblpostiauto.setForeground(java.awt.Color.white);
lblpostiauto.setEnabled(false);
selezionaAuto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
selezionaAuto.setForeground(java.awt.Color.blue);
selezionaAuto.setToolTipText("");
lblorauscita.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lblorauscita.setText("ora uscita:");
lblminutiuscita.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lblminutiuscita.setText("minuti uscita:");
display.setEditable(false);
display.setColumns(20);
display.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
display.setRows(5);
display.setDisabledTextColor(java.awt.Color.black);
display.setEnabled(false);
jScrollPane3.setViewportView(display);
txtticket.setEditable(false);
txtticket.setColumns(20);
txtticket.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
txtticket.setRows(5);
txtticket.setDisabledTextColor(java.awt.Color.black);
txtticket.setEnabled(false);
jScrollPane2.setViewportView(txtticket);
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.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblminutientrata, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtminutientrata, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lbloraentrata, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtoraentrata, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(lbltarga)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txttarga))
.addComponent(entraAuto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(lblminutiuscita)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtminutiuscita))
.addGroup(layout.createSequentialGroup()
.addComponent(lblorauscita)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtorauscita, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(selezionaAuto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(4, 4, 4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblpostiauto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(acetta10cent)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(acetta20cent)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(acetta50cent))
.addGroup(layout.createSequentialGroup()
.addComponent(acetta2euro, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(acetta5euro, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(acetta10euro)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(acetta20euro, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(acetta1euro, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtcredito, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(esceAuto, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(orologio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGap(454, 454, 454))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblminutiuscita, lblorauscita, txtminutiuscita, txtorauscita});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(orologio, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbloraentrata)
.addComponent(txtoraentrata)
.addComponent(lbltarga)
.addComponent(txttarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblminutientrata, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtminutientrata))
.addGap(18, 18, 18)
.addComponent(entraAuto)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(acetta10cent)
.addComponent(acetta20cent)
.addComponent(acetta50cent)
.addComponent(acetta1euro))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(acetta2euro)
.addComponent(acetta5euro)
.addComponent(acetta10euro)
.addComponent(acetta20euro)))
.addComponent(txtcredito))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblpostiauto, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(esceAuto)
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblorauscita)
.addComponent(txtorauscita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(selezionaAuto, 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(lblminutiuscita)
.addComponent(txtminutiuscita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(286, 286, 286))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {lblminutiuscita, lblorauscita, txtminutiuscita, txtorauscita});
pack();
}// </editor-fold>
private void entraAutoActionPerformed(java.awt.event.ActionEvent evt) {
inizializzaEntrata();
if (p.getAperto().equals("siamo aperti")) {
p.entraAuto(targa, oraentrata, minutientrata);
selezionaAuto.addItem(targa);
try {
FileWriter w = new FileWriter("ticket.txt");
BufferedWriter b = new BufferedWriter(w);
b.write(p.Ticket() + "\n");
b.flush();
b.close();
} catch (IOException ex) {
Logger.getLogger(Interfaccia.class.getName()).log(Level.SEVERE, null, ex);
}
txtticket.setText(p.Ticket());
postiliberi--;
postioccupati++;
if (postioccupati == p.massimoauto) {
lblpostiauto.setText("posti esauriti");
} else {
lblpostiauto.setText("posti liberi:" + postiliberi + "\t" + "postioccupati:" + postioccupati);
}
txtoraentrata.setText("");
txtminutientrata.setText("");
txttarga.setText("");
txtoraentrata.grabFocus();
txtminutientrata.grabFocus();
txttarga.grabFocus();
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtminutientrata.setText("");
txttarga.setText("");
txtoraentrata.grabFocus();
txtminutientrata.grabFocus();
txttarga.grabFocus();
lblpostiauto.setText("");
}
}
private void esceAutoActionPerformed(java.awt.event.ActionEvent evt) {
inizializzaUscita();
if (p.getAperto().equals("siamo aperti")) {
if (p.datiScontrino(orauscita, minutiuscita) != "") {
[b]String seleziona = selezionaAuto.getSelectedItem().toString();
numeroscontrino++;[/b]
[b] String numeroScontrino = "scontrino n°" + "\t" + numeroscontrino ;
String Scontrino = numeroScontrino+"\n"+p.datiScontrino(orauscita, minutiuscita) + "\n" + "targa:" + "\t" + seleziona;[/b]
try {
FileWriter w = new FileWriter("scontrino.txt");
BufferedWriter b = new BufferedWriter(w);
b.write(Scontrino + "\n");
b.flush();
b.close();
} catch (IOException ex) {
Logger.getLogger(Interfaccia.class.getName()).log(Level.SEVERE, null, ex);
}
postiliberi++;
postioccupati--;
lblpostiauto.setText("posti liberi:" + postiliberi + "\t" + "postioccupati:" + postioccupati);
txtscontrino.setText(Scontrino);
p.credito = 0.0;
txtcredito.setText("");
txtorauscita.setText("");
txtminutiuscita.setText("");
txttarga.setText("");
txtorauscita.grabFocus();
txtminutiuscita.grabFocus();
txttarga.grabFocus();
selezionaAuto.removeItem(targa);
} else {
txtscontrino.setText("");
lblpostiauto.setText("posti liberi:" + postiliberi + "\t" + "postioccupati:" + postioccupati);
}
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtminutiuscita.setText("");
txttarga.setText("");
txtorauscita.grabFocus();
txtminutiuscita.grabFocus();
txttarga.grabFocus();
lblpostiauto.setText("");
}
}
private void acetta10centActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acetta10cent("0.1"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta20centActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acetta20cent("0.2"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta50centActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acetta50cent("0.5"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta1euroActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acettaUno("1.0"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta2euroActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acettaDue("2.0"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta5euroActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acettaCinque("5.0"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta10euroActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acettaDieci("10.0"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
private void acetta20euroActionPerformed(java.awt.event.ActionEvent evt) {
if (p.getAperto().equals("siamo aperti")) {
txtcredito.setText(p.acettaVenti("20.0"));
} else {
JOptionPane.showMessageDialog(null, "non puoi inserire dati", " Errore", JOptionPane.ERROR_MESSAGE);
txtcredito.setText("");
}
}
// Variables declaration - do not modify
private javax.swing.JButton acetta10cent;
private javax.swing.JButton acetta10euro;
private javax.swing.JButton acetta1euro;
private javax.swing.JButton acetta20cent;
private javax.swing.JButton acetta20euro;
private javax.swing.JButton acetta2euro;
private javax.swing.JButton acetta50cent;
private javax.swing.JButton acetta5euro;
private javax.swing.JTextArea display;
private javax.swing.JButton entraAuto;
private javax.swing.JButton esceAuto;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JLabel lblminutientrata;
private javax.swing.JLabel lblminutiuscita;
private javax.swing.JLabel lbloraentrata;
private javax.swing.JLabel lblorauscita;
private javax.swing.JLabel lblpostiauto;
private javax.swing.JLabel lbltarga;
private javax.swing.JLabel orologio;
private javax.swing.JComboBox selezionaAuto;
private javax.swing.JTextField txtcredito;
private javax.swing.JTextField txtminutientrata;
private javax.swing.JTextField txtminutiuscita;
private javax.swing.JTextField txtoraentrata;
private javax.swing.JTextField txtorauscita;
private javax.swing.JTextArea txtscontrino;
private javax.swing.JTextField txttarga;
private javax.swing.JTextArea txtticket;
// End of variables declaration
public void inizializzaEntrata() {
if (txtminutientrata.getText().isEmpty() && txtoraentrata.getText().isEmpty() && txttarga.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "inserisci il valore richiesto!", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtminutientrata.setText("");
txttarga.setText("");
txtoraentrata.grabFocus();
txtminutientrata.grabFocus();
txttarga.grabFocus();
} else {
try {
oraentrata = new Integer(txtoraentrata.getText());
minutientrata = new Integer(txtminutientrata.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtminutientrata.setText("");
txtoraentrata.grabFocus();
txtminutientrata.grabFocus();
}
try {
oraentrata = new Integer(txtoraentrata.getText());
minutientrata = new Integer(txtminutientrata.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici interi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtoraentrata.grabFocus();
txtminutientrata.setText("");
txtminutientrata.grabFocus();
if (oraentrata < 0) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici positivi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtoraentrata.grabFocus();
}
if (minutientrata < 0) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici positivi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtminutientrata.setText("");
txtminutientrata.grabFocus();
}
if (oraentrata > 24) {
JOptionPane.showMessageDialog(null, "inserisci solo minori di 24", " Errore", JOptionPane.ERROR_MESSAGE);
txtoraentrata.setText("");
txtoraentrata.grabFocus();
}
if (minutientrata >= 60) {
JOptionPane.showMessageDialog(null, "inserisci solo minori di 60!", " Errore", JOptionPane.ERROR_MESSAGE);
txtminutientrata.setText("");
txtminutientrata.grabFocus();
}
}
targa = txttarga.getText();
p.minutientrata = minutientrata;
p.oraentrata = oraentrata;
}
}
public void inizializzaUscita() {
if (txtminutiuscita.getText().isEmpty() && txtorauscita.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "inserisci il valore richiesto!", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtminutiuscita.setText("");
txtorauscita.grabFocus();
txtminutiuscita.grabFocus();
} else {
try {
orauscita = new Integer(txtorauscita.getText());
minutiuscita = new Integer(txtminutiuscita.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtminutiuscita.setText("");
txtorauscita.grabFocus();
txtminutiuscita.grabFocus();
}
try {
orauscita = new Integer(txtorauscita.getText());
minutiuscita = new Integer(txtminutiuscita.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici interi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtminutiuscita.setText("");
txtorauscita.grabFocus();
txtminutiuscita.grabFocus();
if (orauscita < 0) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici positivi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtorauscita.grabFocus();
}
if (minutiuscita < 0) {
JOptionPane.showMessageDialog(null, "inserisci solo valori numerici positivi!", " Errore", JOptionPane.ERROR_MESSAGE);
txtminutiuscita.setText("");
txtminutiuscita.grabFocus();
}
if (orauscita > 24) {
JOptionPane.showMessageDialog(null, "inserisci solo minori di 24", " Errore", JOptionPane.ERROR_MESSAGE);
txtorauscita.setText("");
txtorauscita.grabFocus();
}
if (minutiuscita >= 60) {
JOptionPane.showMessageDialog(null, "inserisci solo minori di 60!", " Errore", JOptionPane.ERROR_MESSAGE);
txtminutiuscita.setText("");
txtminutiuscita.grabFocus();
}
}
}
}
}
package parcheggio;
public class Auto {
[b]
String targa;
int oraentrata, minutientrata;
public Auto(String targa, int oraentrata, int minutientrata ) {
this.targa = targa;
this.minutientrata=minutientrata;
this.oraentrata=oraentrata;
}[/b]
[b] public String stampaTarga() {
return "targa:"+targa;
}[/b]
[b] public String stampaoraEntrata(){
return "ore entrata:"+"\t"+oraentrata+"\t"+"minuti entrata:"+"\t"+minutientrata;
}[/b]
}