|
//workspace/LibrettoScolastico/Frame.java
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
private static final long serialVersionUID = 1L;
private JPanel menu,rightPanel ;
addVotoButton,
removeVotoButton,
matAddButton,
matModButton,
matRemoveButton;
private LibrettoScolastico LS;
super("Libretto Scolastico");
LS=new LibrettoScolastico();
//Creazione Menu
riepilogoButton =new JButton("Riepilogo");
addVotoButton =new JButton("Inserisci Voto");
removeVotoButton =new JButton("Cancella Voto");
matAddButton =new JButton("Aggiungi Materia");
matModButton =new JButton("Modifica Materia");
matRemoveButton =new JButton("Cancella Materia");
menu.add(riepilogoButton);
menu.add(addVotoButton);
menu.add(removeVotoButton);
menu.add(matAddButton);
menu.add(matModButton);
menu.add(matRemoveButton);
menu.add(vediVoti);
if(LS.size()==0)
rightPanel.add(new MaterieAddPanel());
else
rightPanel.add(new RiepilogoPanel());
//Gestione Eventi
MenuHelander menuHelander=new MenuHelander();
riepilogoButton.addActionListener(menuHelander);
addVotoButton.addActionListener(menuHelander);
removeVotoButton.addActionListener(menuHelander);
vediVoti.addActionListener(menuHelander);
matAddButton.addActionListener(menuHelander);
matModButton.addActionListener(menuHelander);
matRemoveButton.addActionListener(menuHelander);
}
public boolean scegliMateria(){
if(LS.size()==0){
errNessunaMateria();
return false;
}
String[] materie =LS. getStringArrMaterie();
null, "Scegli", "Scegli",
materie, materie[0]);
if(sel==null)
return false;
for(int i=0;i<LS.size();i++){
if(LS.get(i).getNome().equals(sel)){
LS.setMat(i);
break;
}
}
return true;
}
public void errNessunaMateria(){
JOptionPane. showMessageDialog(null, "Nessuna materia inserita!",
"Nessuna materia inserita!", JOptionPane. ERROR_MESSAGE);
rightPanel.removeAll();
rightPanel.add(new MaterieAddPanel());
rightPanel.repaint();
rightPanel.validate();
}
public void errNessunVoto(){
JOptionPane. showMessageDialog(null, "Nessuna materia inserita!",
"Nessuna voto inserito di "+LS.get(LS.getMat())+"!",
rightPanel.removeAll();
rightPanel.add(new RiepilogoPanel());
rightPanel.repaint();
rightPanel.validate();
}
if(LS.size()==0&&src!=matAddButton){
errNessunaMateria();
return;
}
if(src==riepilogoButton){
rightPanel.removeAll();
rightPanel.add(new RiepilogoPanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==addVotoButton&&scegliMateria()==true){
rightPanel.removeAll();
rightPanel.add(new AddVotoPanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==removeVotoButton&&scegliMateria()==true){
rightPanel.removeAll();
rightPanel.add(new RemoveVotoPanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==matAddButton){
rightPanel.removeAll();
rightPanel.add(new MaterieAddPanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==matModButton){
rightPanel.removeAll();
rightPanel.add(new MaterieModPanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==matRemoveButton){
rightPanel.removeAll();
rightPanel.add(new MaterieRemovePanel());
rightPanel.repaint();
rightPanel.validate();}
if(src==vediVoti&&scegliMateria()==true){
rightPanel.removeAll();
rightPanel.add(new VediVotiPanel());
rightPanel.repaint();
rightPanel.validate();}
}
}
class RiepilogoPanel extends JPanel{
private static final long serialVersionUID = 1L;
RiepilogoPanel(){
"Materie: "+LS.size():
"Nessuna materia inserita");
"Media generale: "+
String. format("%.2f", Math. round(LS. getMedia()*100.0)/100.0):
"Nessun voto inserito");
riepilogoLabelPanel.add(riepMateriePanel);
riepilogoLabelPanel.add(mediaLabel);
riepilogo.setText(LS.riepilogo());
riepilogo.setEditable(false);
scroll. setMaximumSize(new Dimension(100,100 ));
}
}
class AddVotoPanel extends JPanel{
private static final long serialVersionUID = 1L;
JSpinner annoSpinner,meseSpinner,giornoSpinner;
AddVotoPanel(){
LS.get(LS.getMat()).getNome()+" ");
Box center =Box. createVerticalBox();
for(int i =0;i <3;i ++)center. add(new JPanel());
votoPanel.add(votoLabel);
votoPanel.add(votoText);
center.add(votoPanel);
giornoSpinner=new JSpinner();
giornoSpinner.setModel(new SpinnerNumberModel(1,1,31,1));
giornoPanel.add(giornoLabel);
giornoPanel.add(giornoSpinner);
giornoPanel. add(new JPanel());
center.add(giornoPanel);
meseSpinner=new JSpinner();
meseSpinner.setModel(new SpinnerNumberModel(1,1,12,1));
mesePanel.add(meseLabel);
mesePanel.add(meseSpinner);
center.add(mesePanel);
x =(calendar. get(Calendar. MONTH)>=9 ?a :a -1 );
annoSpinner=new JSpinner();
annoSpinner.setModel(new SpinnerNumberModel(a,x,x+1,1));
annoSpinner.setEditor(new JSpinner.NumberEditor(annoSpinner, "#"));
annoPanel.add(annoLabel);
annoPanel.add(annoSpinner);
center.add(annoPanel);
radioGroup.add(scrittoRB);
radioGroup.add(oraleRB);
radioGroup.add(laboratorioRB);
radioPanel.add(scrittoRB);
radioPanel.add(oraleRB);
radioPanel.add(laboratorioRB);
center.add(radioPanel);
buttonPanel. add(new JPanel());
buttonPanel.add(add);
buttonPanel. add(new JPanel());
center.add(buttonPanel);
add.addActionListener(
double v;
int g,m,a;
try{
int i=s.indexOf(",");
if(i!=-1)
s.setCharAt(i,'.');
v =Double. parseDouble(s. toString());
g =Integer. parseInt(giornoSpinner. getValue(). toString());
m =Integer. parseInt(meseSpinner. getValue(). toString())-1;
a =Integer. parseInt(annoSpinner. getValue(). toString());
"Errore: "+e+"\n\n\tInserire tutti i valori e in modo corretto!",
votoText.setText("");
return;
return;
}
int ggMesi[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(g>ggMesi[m]||(m==2&&(g==29&&(a%400==0||(a%4==0||a%100!=0))))){
JOptionPane. showMessageDialog(null, "Inserire data corretta",
return;
}
if(v<0||v>10){
JOptionPane. showMessageDialog(null, "Inserire una valutazione Valida",
votoText.setText("");
return;
}
Voto voto=new Voto();
voto.setValore(v);
voto.setData(a, m, g);
if(laboratorioRB.getSelectedObjects()!=null)
voto.setTipo(Voto.Tipo.Laboratorio);
else if(oraleRB.getSelectedObjects()!=null)
voto.setTipo(Voto.Tipo.Orale);
else
voto.setTipo(Voto.Tipo.Scritto);
LS.get(LS.getMat()).addVoto(voto);
LS.salvaFile();
"Voto Inserito, inserirne un altro?","Voto Inserito",
rightPanel.removeAll();
rightPanel.add(new AddVotoPanel());
rightPanel.add(new VediVotiPanel());
rightPanel.repaint();
rightPanel.validate();
}
}
);
}
}
class RemoveVotoPanel extends JPanel{
private static final long serialVersionUID = 1L;
int n=1,s,o,l;
RemoveVotoPanel(){
if(LS.get(LS.getMat()).size()==0){
errNessunVoto();
return;
}
LS.get(LS.getMat()).getNome()+" ");
Materia mat=LS.get(LS.getMat());
center. add(new JLabel("Voto da cancellare: "));
for(int i=0;i<mat.size();i++)
array[i]=""+(i+1);
center.add(jcb);
center.add(button);
if(mat.getGVS().size()!=0){
//Stampa voti Scritti
st =String. format("Voti Scritti:\n%2s %4s Data\n", "N", "Voto");
for(int i=0;i<mat.getGVS().size();i++,n++){
st +=String. format(" %-1.2f ",mat. getGVS(). get(i ). getValore());
st +=String. format("%11s\n",mat. getGVS(). get(i ). getData());
s=n;
}
}
if(mat.getGVO().size()!=0){
//Stampa voti Orale
st +=String. format("\nVoti Orali:\n%2s %4s Data\n", "N", "Voto");
for(int i=0;i<mat.getGVO().size();i++,n++){
st +=String. format(" %-1.2f ",mat. getGVO(). get(i ). getValore());
st +=String. format("%11s\n",mat. getGVO(). get(i ). getData());
o=n;
}
}
if(mat.getGVL().size()!=0){
//Stampa voti di Laboratorio
st +=String. format("\nVoti di Laboratorio:\n%2s %4s Data\n", "N", "Voto");
for(int i=0;i<mat.getGVL().size();i++,n++){
st +=String. format(" %-1.2f ",mat. getGVL(). get(i ). getValore());
st +=String. format("%11s\n",mat. getGVL(). get(i ). getData());
l=n;
}
}
text.setText(st);
text.setEditable(false);
button.addActionListener(
Voto voto;
char gv;
int i,scelta=jcb.getSelectedIndex();
if(0<=scelta&&scelta<s){
i=scelta;
voto=LS.get(LS.getMat()).getGVS().get(i);
gv='s';
}else if(s<=scelta&&scelta<o){
i=scelta-s;
voto=LS.get(LS.getMat()).getGVO().get(i);
gv='o';
}else{
i=scelta-o;
voto=LS.get(LS.getMat()).getGVL().get(i);
gv='l';
}
int risp =JOptionPane. showConfirmDialog(null, "Cancellare voto "+
voto.getValore()+" del "+voto.getData()+" ?",
return;
switch(gv){
case 's':LS.get(LS.getMat()).getGVS().removeVoto(i);break;
case 'o':LS.get(LS.getMat()).getGVO().removeVoto(i);break;
case 'l':LS.get(LS.getMat()).getGVL().removeVoto(i);break;
}
LS.salvaFile();
rightPanel.removeAll();
if(LS.get(LS.getMat()).size()!=0)
rightPanel.add(new RemoveVotoPanel());
else
rightPanel.add(new RiepilogoPanel());
rightPanel.repaint();
rightPanel.validate();
}
}
);
}
}
class VediVotiPanel extends JPanel{
private static final long serialVersionUID = 1L;
VediVotiPanel(){
LS.get(LS.getMat()).getNome()+" ");
if(LS.get(LS.getMat()).getMediaSO()!=-1){
Math. round(LS. get(LS. getMat()). getMediaSO()*100 )/100.0 );
center.add(mediaSOLabel);
}
if(LS.get(LS.getMat()).getGVL().getMedia()!=-1){
Math. round(LS. get(LS. getMat()). getGVL(). getMedia()*100 )/100.0 );
center.add(mediaLabLabel);
}
boolean s,o,l;
s=o=l=false;
jspS=jspO=jspL=null;
if(LS.get(LS.getMat()).getGVS().size()!=0){
s=true;
String sS =String. format("Voti Scritti:\n%5s Data\n", "Voto");
GruppoVoti g=LS.get(LS.getMat()).getGVS();
for(int i=0;i<g.size();i++){
sS +=String. format(" %-3.2f ",g. get(i ). getValore());
sS +=String. format("%11s\n",g. get(i ). getData());
}
textS. setFont(new Font("Serif", Font. PLAIN,18 ));
textS.setText(sS);
textS.setEditable(false);
}
if(LS.get(LS.getMat()).getGVO().size()!=0){
o=true;
GruppoVoti g=LS.get(LS.getMat()).getGVO();
for(int i=0;i<g.size();i++){
sO +=String. format(" %-3.2f ",g. get(i ). getValore());
sO +=String. format("%11s\n",g. get(i ). getData());
}
textO. setFont(new Font("Serif", Font. PLAIN,18 ));
textO.setText(sO);
textO.setEditable(false);
}
if(LS.get(LS.getMat()).getGVL().size()!=0){
l=true;
String sL =String. format("Voti di Laboratorio:\n%5s Data\n", "Voto");
GruppoVoti g=LS.get(LS.getMat()).getGVL();
for(int i=0;i<g.size();i++){
sL +=String. format(" %-3.2f ",g. get(i ). getValore());
sL +=String. format("%11s\n",g. get(i ). getData());
}
textL. setFont(new Font("Serif", Font. PLAIN,18 ));
textL.setText(sL);
textL.setEditable(false);
}
//Varie disposizioni
//Nessun Voto
if(!s&&!o&&!l){
return;
}
//Tre tipologie di voti
if(s&&o&&l){
}
//Solo una tipologia di voti
if(!o&&!l){
}else if(!s&&!l){//Solo voti Orali
}else if(!s&&!l){//Solo voti di Laboratorio
}
//Due tipologie di voti
else if(s&&(o||l)){
if(o){
}else{
}
}else if(o&&(s||l)){
}
}
}
class MaterieAddPanel extends JPanel{
private static final long serialVersionUID = 1L;
MaterieAddPanel(){
panel.add(nomeLabel);
panel.add(nomeTextField);
panel.add(aggiungi);
if(LS.size()!=0){
mat.setEditable(false);
for(int i=0;i<LS.size();i++)
mat.append(" - "+LS.get(i).getNome()+"\n");
}
aggiungi.addActionListener(
String n = nomeTextField. getText();
if(n=="")return;
n=n.substring(0,1).toUpperCase()+n.substring(1);
nomeTextField.setText(n);
LS.addMateria(n);
JOptionPane. showMessageDialog(null, "Inserita nuova materia \""+n +"\"",
"Nuova Materia Inserita", JOptionPane. INFORMATION_MESSAGE);
nomeTextField.setText("");
rightPanel.removeAll();
rightPanel.add(new MaterieAddPanel());
rightPanel.repaint();
rightPanel.validate();
}
}
);
}
}
class MaterieModPanel extends JPanel{
private static final long serialVersionUID = 1L;
MaterieModPanel(){
String[] materie =LS. getStringArrMaterie();
for(int i =0;i <3;i ++)center. add(new JPanel());
center.add(label1);
center.add(matComboBox);
center.add(label2);
center.add(nome);
center.add(modifica);
modifica.addActionListener(
if(n=="")return;
n=n.substring(0,1).toUpperCase()+n.substring(1);
nome.setText(n);
"Modificare \""+LS.get(matComboBox.getSelectedIndex())
+"\" in \""+n +"\"?", "ConfermaModifica", JOptionPane. YES_NO_OPTION,
LS.modMateria(matComboBox.getSelectedIndex(),nome.getText());
rightPanel.removeAll();
rightPanel.add(new MaterieModPanel());
rightPanel.repaint();
rightPanel.validate();
}
}
);
}
}
class MaterieRemovePanel extends JPanel{
private static final long serialVersionUID = 1L;
MaterieRemovePanel(){
String[] materie =LS. getStringArrMaterie();
for(int i =0;i <3;i ++)center. add(new JPanel());
center.add(label);
center.add(matComboBox);
center.add(remove);
remove.addActionListener(
"Cancellare \""+LS.get(matComboBox.getSelectedIndex())+"\"?",
return;
LS.remove(matComboBox.getSelectedIndex());
rightPanel.removeAll();
if(LS.size()!=0)
rightPanel.add(new MaterieRemovePanel());
else
rightPanel.add(new MaterieAddPanel());
rightPanel.repaint();
rightPanel.validate();
}
}
);
}
}
}
|
|