1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
class EquipementPanel extends JPanel implements FocusListener{
private Vector ancienMatos=new Vector();////Pour comparaison vectors
private Vector vector = new Vector();
private JPanel jp = new JPanel();
private JLabel jlab=new JLabel();
private ImageIcon imIcon=new ImageIcon();
private Enumeration en;
private JScrollPane scroll;
private JListBackdrop matosJList=new JListBackdrop();
private Entite objet=new Entite();
private PanneauJeu jeuPan;
private Font police;
public EquipementPanel(PanneauJeu pj){
police=pj.getPolice();
jeuPan=pj;
matosJList.setCellRenderer(new CustomCellRenderer());
setLayout(null);
scroll = new JScrollPane(matosJList);
scroll.setBounds(0,0,195,450);
add(scroll);
matosJList.addFocusListener(this);
}
///////VERIFIE S'IL Y A UNE MODIFICATION DE L'EQUIPEMENT/////
public void verifModif(Vector matosVct){
if(!matosVct.isEmpty()){
if(ancienMatos.isEmpty()){
updateEquipementList(matosVct);
System.out.println("CHANGEMENT EQUIPEMENT");
}
else{
for(en = matosVct.elements();en.hasMoreElements();){
try{
objet=(Entite)en.nextElement();
if(!ancienMatos.elementAt(matosVct.indexOf(objet)).equals(objet)){
updateEquipementList(matosVct);
System.out.println("CHANGEMENT EQUIPEMENT");
break;
}
}
catch(NoSuchElementException exc){};
}
}
}
}
///////////LA METHODE INCRIMINEE/////////////////////
public void updateEquipementList(Vector matosVct){
//matosVct est le vector equipement du personnage.
////////j'ai ajouté ça pour essayer de tout vider
////////mais ça ne change rien
this.removeAll();
scroll.removeAll();
scroll = new JScrollPane(matosJList);
scroll.setBounds(0,0,195,450);
this.add(scroll);
//////////////////////////////
ancienMatos=matosVct;
vector.clear();
if(!matosVct.isEmpty()){
for(en = matosVct.elements();en.hasMoreElements();){
try{
objet=(Entite) en.nextElement();
jp = new JPanel();
//IMAGE DE L'OBJET
imIcon=new ImageIcon(objet.getTileStr());
jlab=new JLabel(imIcon);
jp.add(jlab);
//NOM DE L'OBJET
jlab=new JLabel(objet.getNom());
jlab.setFont(police);
jp.add(jlab);
jp.setLayout(new FlowLayout(FlowLayout.LEFT,5,2));
vector.addElement(jp);
}
catch(NoSuchElementException exc){};
}
}
matosJList.setListData(vector);
System.out.println("MISE A JOUR EQUIPEMENT");
System.out.println("TAILLE Vector "+vector.size() );
}
public void focusGained(FocusEvent e){
jeuPan.requestFocus();
}
public void focusLost(FocusEvent e){
}
}
///////////////////////////////////////////////////////////////////////// |
Partager