franksisca
06-10-2005, 15:40
eccolo in tutto il suo splendore(vi prego non commentate...... :( :( )
public class GestoreGrafica extends JFrame {
private JPanel pannello;
private JButton esci, connetti, seleziona, calcola, dettagli;
private Gestore gestore;
private JScrollPane scrollerOperatori, scrollerAssociazioni;
private JList listaAssociazioni, elencoOperatori;
private JComboBox anno;
private JLabel budget, cRimanente, elencoOp, selezionata, costoT, costoA, costoR,
elencoAss, oreT, oreE, oreR, rilE, rilS, rilN, attuale, connesso;
private JTextArea budgetT, cRimanenteT, costoTT, costoAT, costoRT,
oreTT, oreET, oreRT, rilET, rilST, rilNT, attualeT;
private Toolkit tk=Toolkit.getDefaultToolkit();
private JFrame altro;
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 3256722862164161593L;
public GestoreGrafica() throws HeadlessException {
super();
// TODO Auto-generated constructor stub
inizializzazioneGrafica();
}
public GestoreGrafica(GraphicsConfiguration arg0) {
super(arg0);
// TODO Auto-generated constructor stub
inizializzazioneGrafica();
}
public GestoreGrafica(String arg0) throws HeadlessException {
super(arg0);
// TODO Auto-generated constructor stub
inizializzazioneGrafica();
}
public GestoreGrafica(String arg0, GraphicsConfiguration arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
inizializzazioneGrafica();
}
private void inizializzazioneGrafica() {
// TODO Auto-generated method stub
inserimentoPulsanti();
this.altro=new JFrame("Dati particolareggiati");
this.connetti=new JButton("Connetti al database");
this.calcola=new JButton("Calcola spesa.");
this.esci=new JButton ("Esci.");
this.seleziona=new JButton("Seleziona.");
this.dettagli=new JButton("Dettagli");
this.esci.addActionListener(new Azione());
this.calcola.addActionListener(new Azione());
this.seleziona.addActionListener(new Azione());
this.connetti.addActionListener(new Azione());
this.dettagli.addActionListener(new Azione());
//Localizzazione del frame
Dimension schermo=tk.getScreenSize();
this.setResizable(false);
this.setSize(600,450);
this.setLocation((int)schermo.getWidth()/2-300,(int)schermo.getHeight()/2-225);
settaPulsanti();
aggiungiPulsanti();
this.setVisible(true);
}
private void inserimentoPulsanti() {
// TODO Auto-generated method stub
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pannello=new JPanel(null);
this.attualeT=new JTextArea();
this.budgetT=new JTextArea();
this.costoAT=new JTextArea();
this.costoRT=new JTextArea();
this.costoTT=new JTextArea();
this.cRimanenteT=new JTextArea();
this.oreET=new JTextArea();
this.oreRT=new JTextArea();
this.oreTT=new JTextArea();
this.rilET=new JTextArea();
this.rilST=new JTextArea();
this.rilNT=new JTextArea();
this.attuale=new JLabel();
this.budget=new JLabel();
this.cRimanente=new JLabel();
this.connesso=new JLabel();
this.elencoAss=new JLabel();
this.elencoOp=new JLabel();
this.oreE=new JLabel();
this.oreR=new JLabel();
this.oreT=new JLabel();
this.rilE=new JLabel();
this.costoT=new JLabel();
this.costoR=new JLabel();
this.costoA=new JLabel();
this.rilS=new JLabel();
this.rilN=new JLabel();
this.selezionata=new JLabel();
this.attuale.setText("Costo attuale:");
this.budget.setText("Budget associazione:");
this.cRimanente.setText("Costo rimanente:");
this.elencoAss.setText("Elenco Associazioni:");
this.elencoOp.setText("Elenco Operatori:");
this.oreE.setText("Ore effettuate:");
this.oreR.setText("Ore rimanenti:");
this.oreT.setText("Ore totali:");
this.rilE.setText("Rilevazioni effettuate:");
this.rilN.setText("Rilevazioni fallite:");
this.rilS.setText("Rilevazioni positive:");
this.selezionata.setText("Associazione:");
this.costoA.setText("Costo attuale:");
this.costoR.setText("Costo rimanente:");
this.costoT.setText("Costo totale:");
this.connesso.setText("DATABASE DISCONNESSO.");
//faccio selezionare l'anno accademico
this.anno=new JComboBox();
this.anno.addItem("2004/2005");
this.anno.addItem("2005/2006");
this.anno.addItem("2006/2007");
this.anno.setSelectedItem("2004/2005");
this.listaAssociazioni=new JList();
this.elencoOperatori=new JList();
this.scrollerAssociazioni=new JScrollPane(this.listaAssociazioni);
this.scrollerOperatori=new JScrollPane(this.elencoOperatori);
}
private void aggiungiPulsanti() {
// TODO Auto-generated method stub
this.pannello.add(this.connetti);
this.pannello.add(this.esci);
this.pannello.add(this.scrollerAssociazioni);
this.pannello.add(this.elencoAss);
this.pannello.add(this.budget);
this.pannello.add(this.attuale);
this.pannello.add(this.cRimanente);
this.pannello.add(this.seleziona);
this.pannello.add(this.selezionata);
this.pannello.add(this.scrollerOperatori);
this.pannello.add(this.elencoOp);
this.pannello.add(this.costoT);
this.pannello.add(this.costoA);
this.pannello.add(this.costoR);
this.pannello.add(this.oreE);
this.pannello.add(this.oreT);
this.pannello.add(this.oreR);
this.pannello.add(this.rilE);
this.pannello.add(this.rilS);
this.pannello.add(this.rilN);
this.pannello.add(this.calcola);
this.pannello.add(this.attualeT);
this.pannello.add(this.budgetT);
this.pannello.add(this.cRimanenteT);
this.pannello.add(this.costoAT);
this.pannello.add(this.costoRT);
this.pannello.add(this.costoTT);
this.pannello.add(this.oreET);
this.pannello.add(this.oreRT);
this.pannello.add(this.oreTT);
this.pannello.add(this.rilET);
this.pannello.add(this.rilST);
this.pannello.add(this.rilNT);
this.pannello.add(this.dettagli);
this.pannello.add(this.connesso);
this.pannello.add(this.anno);
this.add(this.pannello);
}
private void settaPulsanti() {
// TODO Auto-generated method stub
this.connesso.setBounds(160,10,160,20);
this.connetti.setBounds(0,0,150,30);
this.esci.setBounds(520,405,70,20);
this.dettagli.setBounds(10,380,80,30);
this.scrollerAssociazioni.setBounds(10,80,120,150);
this.listaAssociazioni.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.elencoOperatori.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.elencoAss.setBounds(10,50,120,30);
this.budget.setBounds(10,250,130,20);
this.attuale.setBounds(10,280,100,20);
this.cRimanente.setBounds(10,310,100,20);
this.seleziona.setBounds(140,140,100,30);
this.selezionata.setBounds(140,180,100,20);
this.scrollerOperatori.setBounds(250,80,150,150);
this.elencoOp.setBounds(250,50,120,30);
this.costoT.setBounds(250,250,100,20);
this.costoA.setBounds(250,280,100,20);
this.costoR.setBounds(250,310,100,20);
this.oreT.setBounds(410,80,100,20);
this.oreE.setBounds(410,100,100,20);
this.oreR.setBounds(410,120,100,20);
this.rilE.setBounds(410,140,130,20);
this.rilS.setBounds(410,160,130,20);
this.rilN.setBounds(410,180,130,20);
this.calcola.setBounds(430,250,150,30);
this.attualeT.setBounds(140,280,70,20);
this.attualeT.setEditable(false);
this.budgetT.setBounds(140,250,70,20);
this.budgetT.setEditable(false);
this.cRimanenteT.setBounds(140,310,70,20);
this.cRimanenteT.setEditable(false);
this.costoAT.setBounds(350,280,70,20);
this.costoAT.setEditable(false);
this.costoRT.setBounds(350,310,70,20);
this.costoRT.setEditable(false);
this.costoTT.setBounds(350,250,70,20);
this.costoTT.setEditable(false);
this.oreET.setBounds(540,100,50,15);
this.oreET.setEditable(false);
this.oreRT.setBounds(540,120,50,15);
this.oreRT.setEditable(false);
this.oreTT.setBounds(540,80,50,15);
this.oreTT.setEditable(false);
this.rilET.setBounds(540,140,50,15);
this.rilET.setEditable(false);
this.rilST.setBounds(540,160,50,15);
this.rilST.setEditable(false);
this.rilNT.setBounds(540,180,50,15);
this.rilNT.setEditable(false);
this.anno.setBounds(450,0,120,20);
}
class Azione implements ActionListener{
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Object chiamante=arg0.getSource();
if(chiamante == esci){
System.exit(0);
}
if(chiamante == seleziona){
String valore=(String) listaAssociazioni.getSelectedValue();
if(!(valore==null)){
gestore.setAnnoAccademico((String) anno.getSelectedItem());
gestore.caricaOperatori();
gestore.caricaRilevatori();
gestore.caricaOreEffettuate();
gestore.caricaRilevazioni();
gestore.assegnaOperatori();
gestore.assegnaRilevatori();
gestore.assegnaRilevazioni();
selezionata.setText(valore);
//adesso gli faccio caricare l'elenco degli operatori nella JList operatori.
List<Associazione> ass=gestore.getAssociazioni();
Associazione a=new Associazione("");
a.setDescrizione(valore);
Associazione asso=ass.get(ass.indexOf(a));
List<Operatore>op=asso.getOperatori();
elencoOp.setText("Elenco Operatori: "+op.size());
String []elenco=new String[op.size()];
for(int i=0;i<elenco.length;++i){
elenco[i]=op.get(i).toString();
}
double costoA=asso.costoAssociazione()+0.000000001;
double costoT=25000.00000;
double costoR=costoT-costoA;
String w=""+costoA;
String l=w.substring(0,w.indexOf(".")+3);
String ww=""+costoT+"00000";
String ll=ww.substring(0,ww.indexOf(".")+3);
String www=""+(costoR);
String lll=www.substring(0,www.indexOf(".")+3);
budgetT.setText(ll);
attualeT.setText(l);
cRimanenteT.setText(lll);
elencoOperatori.setListData(elenco);
}
else{
JOptionPane.showMessageDialog(null,"Nessuna Associazione selezionata","Errore selezione",JOptionPane.ERROR_MESSAGE);
}
}
if(chiamante == calcola){
String nomi=(String) elencoOperatori.getSelectedValue();
Associazione ass=new Associazione();
ass.setDescrizione(selezionata.getText());
List associazioni=gestore.getAssociazioni();
Associazione a=(Associazione) associazioni.get(associazioni.indexOf(ass));
List operatori=a.getOperatori();
try{
AltriOperatori aop=new AltriOperatori();
StringTokenizer st=new StringTokenizer(nomi,"_");
aop.setCognome(st.nextToken());
aop.setNome(st.nextToken());
AltriOperatori r=(AltriOperatori) operatori.get(operatori.indexOf(aop));
String c=""+r.calcola()+"000";
costoAT.setText(c.substring(0,c.indexOf(".")+3));
String cc=""+(r.getNumeroOre()*Operatore.costoOra)+"0000000001";
costoTT.setText(cc.substring(0,cc.indexOf(".")+3));
double ct=r.getNumeroOre()*Operatore.costoOra;
double ca=r.calcola();
String tot=""+(ct-ca)+"0.000001";
costoRT.setText(tot.substring(0,tot.indexOf(".")+3));
int oreT=r.getNumeroOre();
int oreE=r.getOreEffettuate();
oreTT.setText(oreT+"");
oreET.setText(oreE+"");
oreRT.setText((oreT-oreE)+"");
rilET.setText("0");
rilNT.setText("0");
rilST.setText("0");
}
catch(Exception e){
Rilevatore aopp=new Rilevatore();
StringTokenizer st=new StringTokenizer(nomi,"_");
aopp.setCognome(st.nextToken());
aopp.setNome(st.nextToken());
Rilevatore r=(Rilevatore) operatori.get(operatori.indexOf(aopp));
String c=""+r.calcola();
costoAT.setText(c.substring(0,c.indexOf(".")+3));
costoRT.setText("0");
costoTT.setText(c.substring(0,c.indexOf(".")+3));
oreTT.setText("0");
oreET.setText("0");
oreRT.setText("0");
List l=r.getRilevazioni();
int numero=l.size();
rilET.setText(numero+"");
rilST.setText(r.numRilevazioniSi()+"");
rilNT.setText((numero-r.numRilevazioniSi())+"");
}
}
if(chiamante == connetti){
gestore=new Gestore();
if(gestore.connesso()){
connesso.setText("DATABASE CONNESSO.");
gestore.caricaAssociazioni();
String elencoAss[];
List <Associazione>l=gestore.getAssociazioni();
elencoAss=new String[l.size()];
for(int i=0;i<l.size();++i)
elencoAss[i]=l.get(i).getDescrizione();
String elencoAttive[]=attive(elencoAss);
listaAssociazioni.setListData(elencoAttive);
}
else connesso.setText("DATABASE DISCONNESSO.");
//ora devo caricare i dati e metterli in memoria
}
if(chiamante == dettagli){
altro=new JFrame("Dettagli associazione");
altro.setSize(300,300);
altro.setLocation(tk.getScreenSize().width/2-150,tk.getScreenSize().height/2-150);
JPanel p=new JPanel(null);
int c=10;
JLabel supporto=new JLabel(), almalaurea=new JLabel(), nucleo=new JLabel(),
informatico=new JLabel(), rilevazioni=new JLabel(), statistico=new JLabel();
supporto.setBounds(20,20+c,120,30);
almalaurea.setBounds(20,60+c,120,30);
nucleo.setBounds(20,100+c,120,30);
statistico.setBounds(20,140+c,120,30);
informatico.setBounds(20,180+c,120,30);
rilevazioni.setBounds(20,220+c,120,30);
supporto.setText("Supporto Ivadis:");
almalaurea.setText("Almalaurea:");
nucleo.setText("Lettore:");
statistico.setText("Statistico:");
informatico.setText("Informatico:");
rilevazioni.setText("Rilevatori:");
p.add(supporto);
p.add(almalaurea);
p.add(nucleo);
p.add(statistico);
p.add(informatico);
p.add(rilevazioni);
JTextArea supp=new JTextArea(), alma=new JTextArea(), nuc=new JTextArea(),
inf=new JTextArea(), ril=new JTextArea(), stat=new JTextArea();
supp.setEditable(false);
alma.setEditable(false);
nuc.setEditable(false);
stat.setEditable(false);
inf.setEditable(false);
ril.setEditable(false);
supp.setBounds(140,20+c,60,30);
alma.setBounds(140,60+c,60,30);
nuc.setBounds(140,100+c,60,30);
stat.setBounds(140,140+c,60,30);
inf.setBounds(140,180+c,60,30);
ril.setBounds(140,220+c,60,30);
p.add(supp);
p.add(alma);
p.add(inf);
p.add(stat);
p.add(ril);
p.add(nuc);
JTextArea suppt=new JTextArea(), almat=new JTextArea(), nuct=new JTextArea(),
inft=new JTextArea(), rilt=new JTextArea(), statt=new JTextArea();
suppt.setEditable(false);
almat.setEditable(false);
nuct.setEditable(false);
statt.setEditable(false);
inft.setEditable(false);
rilt.setEditable(false);
suppt.setBounds(220,20+c,60,30);
almat.setBounds(220,60+c,60,30);
nuct.setBounds(220,100+c,60,30);
statt.setBounds(220,140+c,60,30);
inft.setBounds(220,180+c,60,30);
rilt.setBounds(220,220+c,60,30);
p.add(suppt);
p.add(almat);
p.add(inft);
p.add(statt);
p.add(rilt);
p.add(nuct);
JLabel spesi=new JLabel("Spesi:"), rimasti=new JLabel("Rimanenti:");
spesi.setBounds(140,0,80,30);
rimasti.setBounds(220,0,80,30);
p.add(spesi);
p.add(rimasti);
Associazione ass=new Associazione();
ass.setDescrizione(selezionata.getText());
Associazione a=(Associazione) gestore.getAssociazioni().get(gestore.getAssociazioni().indexOf(ass));
String supc=a.costoSupporto()+"";
String almac=a.costoAlmalaurea()+"";
String nucc=a.costoLettore()+"";
String statc=a.costoStatistico()+"";
String infc=a.costoInformatico()+"";
String rilc=a.costoRilevatori()+"";
supp.setText(supc);
alma.setText(almac);
nuc.setText(nucc);
stat.setText(statc);
inf.setText(infc);
ril.setText(rilc);
altro.add(p);
altro.setVisible(true);
altro.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
altro.setResizable(false);
}
}
/**
* @param elencoAss
* @return
*/
private String[] attive(String[] elencoAss) {
// TODO Auto-generated method stub
String[]att=new String[5];
int cnt=0;
for(int i=0;i<elencoAss.length;++i){
if(elencoAss[i].equals("UDU")||elencoAss[i].equals("ICU")||elencoAss[i].equals("ALFA")||elencoAss[i].equals("RDU")||elencoAss[i].equals("UF")){
att[cnt]=elencoAss[i];
cnt++;
}
}
return att;
}
}
}
se preferisci il file, o anche l'intero package, fammi sapere.
P.S.: ho notato che se la prima volta scelgo un anno, poi non mi fa cambiare, o forse sto solo dando i numeri :cry: :cry: :cry:
EDIT: il problema dovrebbe essere quando chiamante == seleziona
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.