Bonjour !
J' ai un probleme de comprehension globale qui m'empeche d'avancer depuis un petit moment. Je vais essayer de presenter ca de maniere comprehensible.
J'ai une JFrame, comprenant elle meme de liste, et un boutons.
Ce clique sur le bouton doit permettre de supprimer le contenu d'une des listes. Mon probleme etant que j' ai un probleme "d`acces" aux methodes de ma liste.
Ce sera peut etre un peu plus clair avec le code. (Veuillez m'excuser pour la non-proprete de mon code, c'est une versiom beta :p )
Mon model pour mes listes :
La structure de laquelle dependent mes deux listes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package input; import javax.swing.AbstractListModel; public class ListeModel extends AbstractListModel { /** * */ private static final long serialVersionUID = 1L; private String[] strings; private static int SIZE = 30; public ListeModel() { super(); strings = new String[SIZE]; } public ListeModel(String[] in){ super(); this.strings = new String[SIZE]; for(int i = 0; i < in.length -1 ; i++){ strings[i] = in[i]; } } public Object getElementAt(int index) { return strings[index]; } public String[] getStrings() { return strings; } public String getString(int index) { return strings[index]; } public void clearString(int index) { strings[index] = null; } public int getSize() { int i = 0; while (strings[i] != null) i++; return i; } }
Mes deux listes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package input; public class ModifiableListeFehler extends ListeModel { private static final long serialVersionUID = 1L; public ModifiableListeFehler() { super(); } public ModifiableListeFehler(String[] in){ super(in); } public void clearAll() { int oldSize = this.getSize(); for (int i = 0; i < this.getSize() ; i++) clearString(i); fireIntervalRemoved(this, 0, oldSize); } public void addString(String string){ String[] tab = getStrings(); tab[getSize()] = string; int size = getSize(); fireIntervalAdded(this, size, size); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package input; public class FehlerListe extends ModifiableListeFehler { private static final long serialVersionUID = 1L; public FehlerListe() { super(); initialize(); } public FehlerListe(String[] in) { super(in); } private void initialize() { this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); this.addString("jkhhjkH"); } // public void ClearAll() }Et enfin ma fenetre, censé englober tout ca :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package input; public class UrsacheListe extends ModifiableListeFehler { private static final long serialVersionUID = 1L; public UrsacheListe() { super(); initialize(); } public UrsacheListe(String[] in) { super(in); } private void initialize() { this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); this.addString("QQQSFADFS"); } }
Concretement, mon probleme se trouve dans la methode SetButtonMehr() .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package gui; import input.UrsacheListe; import input.FehlerListe; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JButton; public class ListeFehlerUrsache2 extends JFrame{ private static final long serialVersionUID = 1L; private JList listeFehler; private JList listeUrsache; private Container content = getContentPane(); public ListeFehlerUrsache2() { super("Fehler - Ursache"); listeFehler = new JList(new FehlerListe()); listeUrsache = new JList(new UrsacheListe()); initialize(); } private void initialize() { content.add(listeFehler, BorderLayout.WEST); content.add(listeUrsache, BorderLayout.CENTER); content.add(SetButtonMehr(), BorderLayout.SOUTH); this.requestFocus(); this.setVisible(true); this.pack(); } private JButton SetButtonMehr() { JButton bMehr = new JButton("MEHR"); bMehr.setFont(new Font("Verdana", Font.BOLD, 25)); // System.out.println("BMEHR" + bMehr.getPreferredSize().width); bMehr.setPreferredSize(new Dimension(57, 60)); bMehr.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { System.out.println("More clicked"); // listeFehler.clearAll(); } }); return bMehr; } public static void main(String[] args) { new ListeFehlerUrsache2(); } }
J'ai donc un listener, et je souhaiterai, en faisant "listeFehler.clearAll();" appeller la methode clearAll (declaree dans ModifiableListeFehler) sur ma liste, pour l'effacer.
Forcement, ca ne marche pasm listeFehler etant une JList. Du coup ca me parait relativement logiquem je ne trouve neanmoins pas de solution.
Merci d'avance a ceux qui auront eu le courage de jetter un oeil sur mon code.
Partager