IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

2D Java Discussion :

[débutant]probleme pour dessiner des shapes


Sujet :

2D Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut [débutant]probleme pour dessiner des shapes
    bonjour,

    j'ai un petit problème pour dessiner des lignes!

    pour lma partie de code qui suit, je récupére le point de départ et d'arrivée des lignes mais je n'arrive pas à les dessiner
    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
    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
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    public class SlipViewerComponent extends JComponent{
    	private static final int WIDTHRECT = 500;//Largeur du cadre
    	private static final int HEIGHTRECT = 200;//Hauteur du cadre
    	private Graphics2D 		g2DViewer;
    	private Slip slip;
     
    	private float              scale = 0.5f;//Echelle par défaut
     
    	public SlipViewerComponent(Slip slip){
    	    // Rendre le composant Opaque
    	    setOpaque(true);
    	    //Modification des propriétés par défaut du composant
    	    setAutoscrolls(true);
    	    System.out.println("slip :"+slip);
    	    addSlipListeners(slip);
    	}
     
    	private void addSlipListeners(final Slip slip) {
    		slip.addLineListener(new LineListener() {
    	      public void lineChanged(LineEvent ev) {
    	        Line line = ev.getLine();
    	        System.out.println("line :"+line);
    	        switch (ev.getType()) {
    	          case ADD :
    	            addLine( slip,line);
    	            break;
    	          case UPDATE :
    	            updateLine(line);
    	            break;
    	          case DELETE :
    	            deleteLine(line);
    	            break;
    	        }
    	      }
    	    });      
    	}
     
    	  private void addLine(final Slip slip,Line line) {		  
    		  System.out.println("add Line aux points :"+line.getPoints());	
    		  paintLines(this.g2DViewer,slip,line);
    		  repaint();
    		  revalidate();
    	  }
     
    	  private void updateLine(Line line) {
    	    if (line.getLineAtStart() != null) {
    	    	System.out.println("mise à jour point x1");               
    	    }
    	    if (line.getLineAtEnd() != null) {
    	    	System.out.println("mise à jour point x2");              
    	    }
    	  }
     
    	  private void deleteLine(Line line) {
    		  System.out.println("suppression de la ligne");
    	  }
     
    	  /**
               * Dessine un composant
               */
    	  @Override
    	  protected void paintComponent(Graphics g) {
    		  //Création d'une copie du contexte graphique
    	    Graphics2D g2DViewer = (Graphics2D)g.create();
    	    //dessin du fond
    	    paintBackground(g2DViewer);
    	    //Dessin des cadres
    	    paintFrame(g2DViewer);  
    	    paintDrawingFrame(g2DViewer);
    	    paintTableFrame(g2DViewer);
     
    	    //libération des ressources associées à l'objet Graphics2D
    	    g2DViewer.dispose();
    	  }
     
    	  /**
               * dessine le fond du composant s'il est opaque
               */
    	  private void paintBackground(Graphics2D g2DViewer) {
    	    if (isOpaque()) {
    	      //Récupération de la couleur de fond d'une fenêtre
    	      //dans le Look and feel
    	      Color backgroundColor = UIManager.getColor("window");
    	      //remplissage du composant avec de la couleur de fond
    	      g2DViewer.setColor(backgroundColor);
    	      g2DViewer.fillRect(0, 0, getWidth(), getHeight());
    	    }
    	  }
    	  /**
               * dessine le cadre de la fiche
               */
    	  private void paintFrame(Graphics2D g2DViewer) {  
    		  //couleur du rectangle
    		  g2DViewer.setColor(Color.BLACK);
    		  //dessine un rectangle
    		  g2DViewer.drawRect(((this.getSize().width- WIDTHRECT)/2),((this.getSize().height-HEIGHTRECT)/2),WIDTHRECT,HEIGHTRECT);
    	  }	  
     
    	  /**
               * dessine le cadre de la partie schéma
               */
    	  private void paintDrawingFrame(Graphics2D g2DViewer) {  
    		  //couleur du rectangle
    		  g2DViewer.setColor(Color.BLACK);
    		  //dessine un rectangle
    		  g2DViewer.drawRect(((this.getSize().width- WIDTHRECT)/2),((this.getSize().height-HEIGHTRECT)/2),WIDTHRECT/2,HEIGHTRECT);
    	  }	
    	  /**
               * dessine le cadre de la partie tableau
               */
    	  private void paintTableFrame(Graphics2D g2DViewer) {  
    		  //couleur du rectangle
    		  g2DViewer.setColor(Color.BLACK);
    		  //dessine un rectangle
    		  g2DViewer.drawRect(((this.getSize().width- WIDTHRECT)/2)+(WIDTHRECT/2),((this.getSize().height-HEIGHTRECT)/2),WIDTHRECT/2,HEIGHTRECT);
    	  }	
     
    	  /**
               * Dessine les trait du schéma
               */
    	  private void paintLines(Graphics2D g2DViewer,Slip slip,Line line) {
    		if(line!=null){
     
    		  System.out.println("line diff de null");
    		  float scaleInverse = 1 / this.scale;
    		  Shape linesArea = getLinesArea(slip.getLines());
    		  g2DViewer.fill(linesArea);
     
    	        // Draw selection border
    	        g2DViewer.draw(getShape(line.getPoints()));
     
    	        AffineTransform previousTransform = g2DViewer.getTransform();
    	        // Draw start point of the wall
    	        g2DViewer.translate(line.getXStart(), line.getYStart());
    	        g2DViewer.scale(scaleInverse, scaleInverse);
     
     
    	        double lineAngle = Math.atan2(line.getYEnd() - line.getYStart(), 
    	            line.getXEnd() - line.getXStart());
    	        g2DViewer.rotate(lineAngle);
    	        g2DViewer.setTransform(previousTransform);
     
    	        // Draw walls area
    	        g2DViewer.setPaint(getForeground());
    	        g2DViewer.setStroke(new BasicStroke(1.5f / this.scale));
    	        g2DViewer.draw(linesArea);
     
    		}
    		else{System.out.println("line egal à null");}
     
    	  }
     
    	  /**
               * Returns an area matching the union of all line shapes. 
               */
    	  private Area getLinesArea(Collection<Line> lines) {
    		System.out.println("getLineArea collection de ligne"+lines);
    	    Area area = new Area();
    	    for (Line line : lines) {
    	      area.add(new Area(getShape(line.getPoints())));
    	    }   
    	    System.out.println("getLineArea area"+area);
    	    return area;
    	  }
     
    	  /**
               * Création d'un chemin qui relie le premier
               * point au autres point.
               */
    	  private Shape getShape(float [][] points) {
    	    GeneralPath linePath = new GeneralPath();
    	    linePath.moveTo(points [0][0], points [0][1]);
    	    for (int i = 1; i < points.length; i++) {
    	      linePath.lineTo(points [i][0], points [i][1]);
    	    }
    	    linePath.closePath();//fermeture du chemin
    	    return linePath;
    	  }
    }
    j'ai une NullPointerException
    J'ai inséser des marqueurs vers la console mais en vain... je n'arrive pas à trouver mon erreur

    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
    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
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    slip :org.vincentdamiens.electricalmanager.model.Slip@e5f46e
    line :org.vincentdamiens.electricalmanager.model.Line@196bac4
    add Line aux points :[[F@bfd10a
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4]
    getLineArea areajava.awt.geom.Area@16b61c3
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@1c6866d
    add Line aux points :[[F@a36b53
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d]
    getLineArea areajava.awt.geom.Area@db3331
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@e0f0ad
    add Line aux points :[[F@1d8f162
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad]
    getLineArea areajava.awt.geom.Area@1cf662f
    line :org.vincentdamiens.electricalmanager.model.Line@801059
    add Line aux points :[[F@1b158db
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad, org.vincentdamiens.electricalmanager.model.Line@801059]
    getLineArea areajava.awt.geom.Area@40b181
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@dc024a
    add Line aux points :[[F@1a70b8
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad, org.vincentdamiens.electricalmanager.model.Line@801059, org.vincentdamiens.electricalmanager.model.Line@dc024a]
    getLineArea areajava.awt.geom.Area@1de6817
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@eb724
    add Line aux points :[[F@19ccba
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad, org.vincentdamiens.electricalmanager.model.Line@801059, org.vincentdamiens.electricalmanager.model.Line@dc024a, org.vincentdamiens.electricalmanager.model.Line@eb724]
    getLineArea areajava.awt.geom.Area@1cfd3b2
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@21447f
    add Line aux points :[[F@182a70
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad, org.vincentdamiens.electricalmanager.model.Line@801059, org.vincentdamiens.electricalmanager.model.Line@dc024a, org.vincentdamiens.electricalmanager.model.Line@eb724, org.vincentdamiens.electricalmanager.model.Line@21447f]
    getLineArea areajava.awt.geom.Area@8a2023
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    line :org.vincentdamiens.electricalmanager.model.Line@1d9e279
    add Line aux points :[[F@1a3aa2c
    line diff de null
    getLineArea collection de ligne[org.vincentdamiens.electricalmanager.model.Line@196bac4, org.vincentdamiens.electricalmanager.model.Line@1c6866d, org.vincentdamiens.electricalmanager.model.Line@e0f0ad, org.vincentdamiens.electricalmanager.model.Line@801059, org.vincentdamiens.electricalmanager.model.Line@dc024a, org.vincentdamiens.electricalmanager.model.Line@eb724, org.vincentdamiens.electricalmanager.model.Line@21447f, org.vincentdamiens.electricalmanager.model.Line@1d9e279]
    getLineArea areajava.awt.geom.Area@1f95165
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.paintLines(SlipViewerComponent.java:158)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.addLine(SlipViewerComponent.java:71)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent.access$0(SlipViewerComponent.java:69)
    	at org.vincentdamiens.electricalmanager.swing.SlipViewerComponent$1.lineChanged(SlipViewerComponent.java:56)
    	at org.vincentdamiens.electricalmanager.model.Slip.fireLineEvent(Slip.java:501)
    	at org.vincentdamiens.electricalmanager.model.Slip.addLine(Slip.java:377)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.createNewLine(PlanController.java:383)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.access$17(PlanController.java:376)
    	at org.vincentdamiens.electricalmanager.swing.PlanController$NewLineState.moveMouse(PlanController.java:1712)
    	at org.vincentdamiens.electricalmanager.swing.PlanController.moveMouse(PlanController.java:206)
    	at org.vincentdamiens.electricalmanager.swing.PlanComponent$5.mouseMoved(PlanComponent.java:324)
    	at java.awt.Component.processMouseMotionEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    merci pour votre aide

  2. #2
    Membre expérimenté
    Avatar de vahid
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 228
    Par défaut
    Slt
    Ou est la ligne 158 dans ta classe ?

  3. #3
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    Hello,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g2DViewer.fill(linesArea);
    dans la méthode paintLines
    merci

  4. #4
    Membre expérimenté
    Avatar de vahid
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 228
    Par défaut
    Ton probleme est tout simplement que ton this.g2DViewer n'est pas initialisé
    je ne vois nullepart dans ton code this.g2dViewer = ...

  5. #5
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    g2DViewer est une copie du contexte graphique

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    	  protected void paintComponent(Graphics g) {
    		  //Création d'une copie du contexte graphique
    	    Graphics2D g2DViewer = (Graphics2D)g.create();
    	    //dessin du fond
    	    paintBackground(g2DViewer);
    	    //Dessin des cadres
    	    paintFrame(g2DViewer);  
    	    paintDrawingFrame(g2DViewer);
    	    paintTableFrame(g2DViewer);
     
    	    //libération des ressources associées à l'objet Graphics2D
    	    g2DViewer.dispose();
    	  }

  6. #6
    Membre expérimenté
    Avatar de vahid
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 228
    Par défaut
    sauf que
    référence le champ
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private Graphics2D 		g2DViewer;
    lequel est null car non initialiser

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 04/06/2006, 17h00
  2. [NetBeans 4.0 Beta 2]Probleme pour monter des jars
    Par nicoo dans le forum NetBeans
    Réponses: 2
    Dernier message: 19/11/2004, 14h14
  3. Réponses: 5
    Dernier message: 07/07/2004, 16h05
  4. Réponses: 3
    Dernier message: 14/02/2004, 10h10
  5. [debutant] Probleme pour dessiner un simple cube
    Par scorpiwolf dans le forum DirectX
    Réponses: 6
    Dernier message: 02/07/2003, 20h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo