difficulte avec mon List <Shape>
Voilà mon but est de récuperer des lignes, et franchement je debute en Java , et je crois que je pourrai pas résoudre ça sans votre aide
J'ai un classe qui dérive de JPanel dans laquelle on trace des courbe GraphePh, j'y ai inseré un attribut private
Code:
1 2 3 4
|
public Class GraphePh{ ....
private List <Shape> shapes ;
...} |
Plus loin dans le constructeur j'ai défini mes shapes comme :
Code:
1 2
|
shapes = new ArrayList<Shape>(); // collection de forme utilisable à la pause |
Ensuite les courbes se dessinent au fil du temps alors je remplis en meme temps ma collection de forme dans une methode AfficherPoint (en fait c des lignes)
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
public Afficher Point(){ .....
if(ok){
g.drawLine(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][0], abcisseEnCours+x, tab_coor[indiceTab][i][0]);
shapes.add(new Line2D.Double(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][0], abcisseEnCours+x, tab_coor[indiceTab][i][0]));
}
....
if(ok){
{g.drawLine(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][c], abcisseEnCours+x, tab_coor[indiceTab][i][c]);
shapes.add(new Line2D.Double(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][c], abcisseEnCours+x, tab_coor[indiceTab][i][c]));
}
} |
et J'ai aussi fait un accesseur pour la List, je sais pas si c correc, parce que je m'y connais pas trop
Code:
1 2 3 4
|
public List <Shape> getmesShapes() { // On ajoutera les shapes au JPanel
return shapes;
} |
Ensuite j'ai crée une JPanel, qui affichera cette fameuse collec de Shape, comme ça j'affiche à part sur une autre fenetre :
Code:
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
|
public class affichShapes extends JPanel{
private AppletPh2 app;
private List <Shape> shapes ;
public affichShapes (){
super();
this.setSize(600,600);
//List <Shape> shapes = new ArrayList<Shape>();
}
protected void paintComponent(Graphics g) {
// TODO Raccord de méthode auto-généré
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//Pour chaque forme de la collection
shapes = app.getFenetreGraphe().getGraphePh().getmesShapes();
for(Shape shape : shapes) {
//On dessine la forme
g2d.draw(shape);
}
}
} |
mais les messages arrivent au moment où la fen contenant le panel surgit !
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at AppletPh2.fenetreGraphe.affichShapes.paintComponent(affichShapes.java:35)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
c'est ça qui me dit qui va pas :
Code:
shapes = app.getFenetreGraphe().getGraphePh().getmesShapes();
MERCI