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

AWT/Swing Java Discussion :

Affichage avec Canvas


Sujet :

AWT/Swing Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 45
    Points : 35
    Points
    35
    Par défaut Affichage avec Canvas
    Bonjour,

    j'ai du graphisme a afficher mais j'arrive pas a la faire voici mon code, une classe heritant de JFrame, et une autre haritant de Canvas.Donc est ce que le probelme au niveau de la methode paintConponent(Graphics g)?. Est t'il possible d'afficher dans Canvas avec une autre methode, par exemple une methode dessin(), si oui comment je peux le faire svp.Si non comment je le fais avec un panneau(JPanel).

    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
     
    import java.awt.BorderLayout;
     
    import javax.swing.JFrame;
     
     
     
    public class frame extends JFrame{
    panneau pan;
    	frame()
    {
     
    	super("Titre ####"); 		   
        setBounds(20,20,800,600);
        setLayout(new BorderLayout());
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
        pan=new panneau();
        add("Center",pan);
    }
    		public static void main(String[] args) {
            new frame();
    	}
     
     
    }
     
     
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
     
    import javax.swing.JPanel;
     
     
    public class panneau extends Canvas{
    int xx=10;int yy=10;
    Image im=null;
    panneau()
    {
    	setSize(200,300);
    	setBackground(Color.WHITE);
    }
    public void paintComponent(Graphics g)	
    {
    	Graphics2D surface=(Graphics2D)g;
    if (im==null)g=getGraphics();
    else g=im.getGraphics();
    if (g!=null){
    	g.fillRect(xx,yy,10,10);
    	}
    g.dispose();
     
     
    if(im!=null)
    {
     g=getGraphics();	
     if(g!=null && im!=null) 
      {
       g.drawImage(im,0,0,this);	
       g.dispose();
      }
    } 
    else System.out.println("null");
    surface.fillRect(xx,yy,10,10);
     
    }
     
     
     
     
    }
    Merci d'avance .

  2. #2
    Membre émérite
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Points : 2 582
    Points
    2 582
    Par défaut
    JFrame est un composant de la famille swing, tandis que Canvas est un composant de la famille awt ; or il vaut mieux éviter de mélanger les deux, sauf bonne (et rare) raison.

    Comme à te lire je vois pas quelle raison tu aurais, je te conseille de travailler à partir d'un JPanel, et non d'un Canvas.
    Mieux que Google, utilisez Sur Java spécialisé sur la plate-forme java !
    Pour réaliser vos applications Java dans le cadre de prestations, forfait, conseil, contactez-moi en message privé.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 45
    Points : 35
    Points
    35
    Par défaut
    Bonjour;


    D'apres ce que j'ai compris, je tavaille avec des JPanel, avec la methodes paintComponent(Graphics g).

    Je vais essyer .Merci

  4. #4
    Membre émérite
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Points : 2 582
    Points
    2 582
    Par défaut
    Oui, tout à fait, la méthode paintComponent te permet de te concentrer sur ce qui est BEAU pour ton composant
    Mieux que Google, utilisez Sur Java spécialisé sur la plate-forme java !
    Pour réaliser vos applications Java dans le cadre de prestations, forfait, conseil, contactez-moi en message privé.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 45
    Points : 35
    Points
    35
    Par défaut
    Bonjour Monsieur,

    J'ai fais une applet d'animation voici le code
    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
    298
    299
    300
    301
    302
    303
    304
     
     
    package Applet;
     
    import java.awt.*;
    import java.util.Random;
     
    public class SimpleCA extends java.applet.Applet implements Runnable {
     
       CACanvas CA;
       Thread runner = null;
     
       public void init() {
          setLayout(new BorderLayout());
          CA = new CACanvas();
          add("Center",CA);
          setBackground(Color.black);
       }
     
       public Insets insets() {
          return new Insets(2,2,2,2);
       }
     
       public void run() {
          CA.properties(2,3,null,null,true);
          CA.set(null);
          while (true) {
             CA.next();
             try { Thread.sleep(25); }
             catch (InterruptedException e) { }
          }
       }
     
       public void start() {
          if (runner == null) {
             runner = new Thread(this);
             runner.start();
          }
       }
     
       public void stop() {
          if (runner != null) {
             runner.stop();
             runner = null;
             CA.disposeOSC();
         }
       }
     
       public boolean mouseDown(Event evt, int x, int y) {
          if (evt.shiftDown())
             CA.reset();
          CA.next();
          return true;
       }
    }
     
     
     
    package Applet;
     
    import java.awt.*;
     
    class CACanvas extends Canvas {
     
       private boolean backedUp = true;
       private Image OSC = null;
       private int[] rule = null;
       private int ruleCt = 8;
       private int states = 2;
       private int neighbors = 3;
       private int halfNeighborCt = 1;
       private int[] startWorld = null;
       private int[] world = null;
       private int[] newWorld = null;
       private Color[] stateColor = null;
       private int width = 0;
       private int height = 0;
       private int lineCt = 0;
     
       synchronized void properties(int stateCt, int neighborCt, 
                                    int[] theRules, Color[] theColors, 
                                    boolean useOffScreenCanvas) {
          backedUp = useOffScreenCanvas;
          states = stateCt;
          if (states < 2)
             states = 2;
          neighbors = neighborCt;
          if (neighbors % 2 == 0)
            neighbors++;
          if (neighborCt < 3)
             neighborCt = 3;
          ruleCt = 1;
          for (int i=0; i<neighbors; i++) {
             if (ruleCt > 32768) {
                states = 2;
                neighbors = 3;
                ruleCt = 8;
                break;
             }
             ruleCt = ruleCt*states;
          }
          halfNeighborCt = neighbors / 2;
          if (theRules != null && theRules.length >= ruleCt)
             rule = theRules;
          else 
             rule = null;
          if (theColors != null && theColors.length >= states)
             stateColor = theColors;
          else
             theColors = null;
       }
     
       int getwidth() {
         return (width == 0)? size().width : width;
       }
     
       void disposeOSC() {
          OSC = null;
       }
     
       synchronized void set(int[] theWorld) {
           if ((width != size().width || height != size().height))
              OSC = null;
           width = size().width;
           height = size().height;
           if (world == null || world.length < width)
              world = new int[width];
           if (newWorld == null || newWorld.length < width)
              newWorld = new int[width];
           if (rule == null || rule.length < ruleCt) {
              rule = new int[ruleCt];
              for (int i = 0; i < ruleCt; i++)
                 rule[i] = 1;
              rule[0] = 0;
              rule[ruleCt-1] = 0;
           }
           if (stateColor == null || stateColor.length < states) {
              stateColor = new Color[states];
              stateColor[0] = Color.white;
              stateColor[1] = Color.black;
              if (states>2) {
                 float hue = 0.0F;
                 for (int i = 2; i < states; i++) {
                     stateColor[i] = Color.getHSBColor(hue,1.0F,1.0F); 
                     hue = hue + (1.0F / (states - 2));
                 }
              }
           }
           if (theWorld == null) {
              for (int i=0; i<width; i++)
                 world[i] = 0;
              world[width/2] = 1;
           }
           else {
              for (int i=0; i<width; i++)
                 if (i < theWorld.length && theWorld[i] >= 0 && theWorld[i] < states)
                    world[i] = theWorld[i];
                 else
                   world[i] = 0;
           }
           if (startWorld == null || startWorld.length < width)
              startWorld = new int[width];
           for (int i = 0; i<width; i++)
              startWorld[i] = world[i];
           if (backedUp && OSC == null)
               OSC = createImage(width,height);
           clear();
       }
     
       void reset() {
          if (startWorld != null) {
              if (world == null || world.length < width)
                 world = new int[width];
              for (int i=0; i<width; i++)
                 if (i < startWorld.length && startWorld[i] >= 0 && startWorld[i] < states)
                    world[i] = startWorld[i];
                 else
                   world[i] = 0;
             clear();
          }
       }
     
       void setStart() {
          if (world != null) {
             if (startWorld == null || startWorld.length < world.length)
                startWorld = new int[world.length];
             for (int i=0; i<world.length; i++)
                startWorld[i] = world[i];
          }
       }
     
       synchronized void setCell(int cellNum, int state) {
           if (world != null && cellNum >= 0 && cellNum < world.length && state >= 0 && state < states)
                world[cellNum] = state;
       }
     
       synchronized void clear() {
          if (OSC != null) {
             Graphics g = OSC.getGraphics();
             if (stateColor != null)
                g.setColor(stateColor[0]);
             else
                g.setColor(Color.black);
             g.fillRect(0,0,width,height);
             g.dispose();
             repaint();
          }
          else {
             Graphics g = getGraphics();
             if (stateColor != null)
                g.setColor(stateColor[0]);
             else
                g.setColor(Color.black);
             g.fillRect(0,0,width,height);
             g.dispose();
          }
          lineCt = 0;
       }
     
       synchronized void  setRules(int[] theRules) {
          if (theRules.length >= ruleCt)
             rule = theRules;
       }
     
       synchronized void  setRule(int ruleNum, int value) {
          if ((rule != null) && (value >= 0) && (value < states) && (ruleNum >= 0) && (ruleNum < rule.length))
             rule[ruleNum] = value;
       }
     
       synchronized void  setColors(Color[] theColors) {
          if (theColors.length >= states)
             stateColor = theColors;
       }
     
       synchronized void  setColor(int colorNum, Color value) {
          if ((stateColor != null) && (value != null) && (colorNum >= 0) && (colorNum < stateColor.length))
             stateColor[colorNum] = value;
       }
     
       public void update(Graphics g) {
          paint(g);
       }
     
       public void paint(Graphics g) {
          if (OSC != null)
             g.drawImage(OSC,0,0,this);
       }
     
       synchronized void putWorld() {
          Graphics g=null;
          if (OSC == null)
             g = getGraphics();
          else
             g = OSC.getGraphics();
          if (lineCt >= height && g != null) {
             g.copyArea(0,0,width,height,0,-1);
             lineCt = height-1;
          }
          if (g != null) {
             for (int i=0; i< width; i++) {
                g.setColor(stateColor[world[i]]);
                g.fillRect(i,lineCt,1,1);
             }
             lineCt++;
             g.dispose();
          }
          if (OSC != null) {
             g = getGraphics();
             if (g != null && OSC != null) {
                g.drawImage(OSC,0,0,this);
                g.dispose();
             }
          }
       }
     
       synchronized void next() {
          if (width > 0) {
            for (int i=0; i < width; i++) {
               int left = i - halfNeighborCt;
               if (left<0)
                  left = width+left;
               int right = i + halfNeighborCt;
               if (right>=width)
                  right = right-width;
               int k = 0;
               if (left < right) {
                  for (int j=left; j<=right; j++)
                     k = states*k + world[j];
               }
               else {
                  for (int j=left; j<width; j++)
                    k = states*k + world[j];
                  for (int j=0; j<=right; j++)
                    k = states*k + world[j];
               }
               newWorld[i] = rule[k];
             }
             putWorld();
             for (int i = 0; i < width; i++)
                world[i] = newWorld[i];
          }
       }   // next()
     
    }  // class CACanvas


    Je veux maintenant faire mon affichage dans une fenetre pour que je puisse le developper apres. Voici mob code mais rien , j'ai pas comris ou est le probleme.
    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
     
     
    package Conteneur_1;
     
     
    import javax.swing.JFrame;
     
    public class fenetre extends JFrame implements Runnable{
    	panneau_1 pan1;
    	panneau_2 pan2;
    	Thread runner=new Thread(this);
     
    	fenetre()
    	{   super("Application...");
    		setBounds(20,20,800,600);	
    		setDefaultCloseOperation(EXIT_ON_CLOSE);		
    		setLayout(null);
    		pan1=new panneau_1();
    		pan2=new panneau_2();
    		add(pan1);
    		add(pan2);
            runner.start();	
    	}
    	public static void main(String[] args) {
    		new fenetre().setVisible(true);
    	}
    	public void run() 
    	{
    	  pan1.proprietes(2,3,null,null,true);
    	  pan1.set(null);
    	  while (true) 
    	  {
    	   pan1.next();
    	   try { Thread.sleep(10);}
    	       catch (InterruptedException e) { }
     
    	  }
     
    }
     
    }
     
    package Conteneur_1;
     
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
     
    import javax.swing.BorderFactory;
    import javax.swing.JPanel;
    import javax.swing.border.Border;
     
    public class panneau_1 extends JPanel{
    Image lattice=null;
    Graphics g=null;
    private int voisinage =3;//Chaque cellule a deux voisine voisinage a trois
    private int demi_VoisinageCt=1;
    private int etats=2;//Automate a deux etat(0/1);
    private int regleCt=8;
    private int[]regle=null;//tableau de regle 
    private boolean backedUp=true;
    /*############# Le monde cellulaire #########################*/
     
    private int []cellules_avant=null;
    private int []cellules=null;
    private int []cellules_Apres=null;
    private Color []etat_Couleur=null;
     
    /*############# proprieté du Lattice #####################"*/
     
    	private int largeur=0,hauteur=0,ligneCt=0;
     
     
    	panneau_1()
    {
    setBounds(2,2,600,500);
    setBackground(Color.white);
    setBorder(BorderFactory.createEtchedBorder());
    }
    //"""""""""""""""""""""""""""""""""""""""""""
    synchronized	void proprietes(int etatCt,int voisinageCt,int[]lesRegles,Color[]lesCouleurs,boolean useOffScreenCanvas)	
    	{
            backedUp = useOffScreenCanvas;
            etats = etatCt;
            if (etats < 2)
               etats = 2;
            voisinage = voisinageCt;
            if (voisinage % 2 == 0)
              voisinage++;
            if (voisinageCt < 3)
               voisinageCt = 3;
            regleCt = 1;
            for (int i=0; i<voisinage; i++) {
               if (regleCt > 32768) {
                  etats = 2;
                  voisinage = 3;
                  regleCt = 8;
                  break;
               }
               regleCt = regleCt*etats ;
            }
            demi_VoisinageCt = voisinage / 2;
            if (lesRegles != null && lesRegles.length >= regleCt)
               regle = lesRegles;
            else 
               regle= null;
            if (lesCouleurs != null && lesCouleurs.length >= etats)
            	etat_Couleur = lesCouleurs;
            else
            	etat_Couleur = null;
     
    		System.out.println("proprietres"+" "+etats+" "+voisinage+" "+regleCt);
     
     
    	}
     
    //****************************************************
     
    synchronized void set(int[]lesCellules)
    	{
    	 if ((largeur != size().width || hauteur != size().height))
             lattice = null;
          largeur = size().width;
          hauteur = size().height;
          if (cellules == null || cellules.length < largeur)
             cellules = new int[largeur];
          if (cellules_Apres == null || cellules_Apres.length < largeur)
             cellules_Apres = new int[largeur];
          if (regle == null || regle.length < regleCt) {
             regle = new int[regleCt];
             for (int i = 0; i < regleCt; i++)
                regle[i] = 1;
             regle[0] = 0;
             regle[regleCt-1] = 0;
          }
          if (etat_Couleur == null || etat_Couleur.length < etats) {
             etat_Couleur = new Color[etats ];
             etat_Couleur[0] = Color.white;
            etat_Couleur[1] = Color.black;
             if (etats>2) {
                float hue = 0.0F;
                for (int i = 2; i < etats; i++) {
                    etat_Couleur[i] = Color.getHSBColor(hue,1.0F,1.0F); 
                    hue = hue + (1.0F / (etats - 2));
                }
             }
          }
          if (lesCellules == null) {
             for (int i=0; i<largeur; i++)
                cellules[i] = 0;
             cellules[largeur/2] = 1;
          }
          else {
             for (int i=0; i<largeur; i++)
                if (i < lesCellules.length && lesCellules[i] >= 0 && lesCellules[i] < etats)
                   cellules[i] = lesCellules[i];
                else
                  cellules[i] = 0;
          }
          if (cellules_avant == null || cellules_avant.length < largeur )
             cellules_avant = new int[largeur];
          for (int i = 0; i<largeur; i++)
             cellules_avant[i] = cellules[i];
          if (backedUp && lattice == null)
              lattice = createImage(largeur,hauteur);
          System.out.println("set"+" "+largeur+" "+hauteur);
         clear();
      }
     
     
     
     
    synchronized void clear()
    {
    	if (lattice != null) {
            Graphics g = lattice.getGraphics();
            if (etat_Couleur != null)
               g.setColor(etat_Couleur[0]);
            else
               g.setColor(Color.black);
            g.fillRect(0,0,largeur,hauteur);
            g.dispose();
            repaint();
         }
         else {
            Graphics g = getGraphics();
            if (etat_Couleur != null)
               g.setColor(etat_Couleur[0]);
            else
            g.setColor(Color.black);
            g.fillRect(0,0,largeur,hauteur);
            g.dispose();
         }
         ligneCt = 0;	
     
    }
    synchronized void next() {
    	 System.out.println("next");
     
    	if (largeur > 0) {
          for (int i=0; i < largeur; i++) {
             int left = i - demi_VoisinageCt;
             if (left<0)
                left = largeur+left;
             int right = i + demi_VoisinageCt;
             if (right>=largeur)
                right = right-largeur;
             int k = 0;
             if (left < right) {
                for (int j=left; j<=right; j++)
                   k = etats*k + cellules[j];
             }
             else {
                for (int j=left; j<largeur; j++)
                  k = etats *k + cellules[j];
                for (int j=0; j<=right; j++)
                  k = etats*k + cellules[j];
             }
             cellules_Apres[i] = regle[k];
           }
          paintComponent(g);
           for (int i = 0; i < largeur; i++)
              cellules[i] = cellules_Apres[i];
        }
     }		
    public  void paintComponent(Graphics g)
    {
    	//Graphics g=null;
     
    	if (lattice == null)g = getGraphics();
    	    else  g = lattice.getGraphics();
    	    if (ligneCt >= hauteur && g != null) 
    	    {
    	       g.copyArea(0,0,largeur,hauteur,0,-1);
    	       ligneCt = hauteur-1;
    	    }
    	    if (g != null) 
    	    {
    	       for (int i=0; i< largeur; i++) 
    	       {
    	          g.setColor(etat_Couleur[cellules[i]]);
    	          g.fillRect(i,ligneCt,10,10);
    	       }
    	       ligneCt++;
    	       g.dispose();
    	     }
    	    if (lattice != null) 
    	    {
    	       g = getGraphics();
    	       if (g != null && lattice != null) 
    	       {
    	          g.drawImage(lattice,0,0,this);
    	          g.dispose();
    	       }	
    	    }
     
    repaint();
    }
     
    }
     
    package Conteneur_1;
     
    import java.awt.Color;
     
    import javax.swing.BorderFactory;
    import javax.swing.JPanel;
     
    public class panneau_2 extends JPanel{
    panneau_2()
    {
    	setBounds(604,2,176,500);
    	//setBackground(Color.red);
    	setBorder(BorderFactory.createEtchedBorder());
     
    }
    }


    POuvez vous m'aider SVP.

    Merci d'avance.

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 45
    Points : 35
    Points
    35
    Par défaut
    Bonjour la monde;

    Mon probleme n'a pas de solution!!!!!!!!

    Qu'est ce que dois faire alors




    Thanks for all.

  7. #7
    Membre émérite
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Points : 2 582
    Points
    2 582
    Par défaut
    Cela n'a pas l'air mal dans l'ensemble, mais il y a diverses maladresses... je te suggère, pour bien comprendre les mécanismes, de faire une mini-appli de démo dans laquelle tu dessines un cercle dans un JPanel dans une JFrame (par ex.).

    Et, bien sûr, de lire quelques guides de formation.

    Sut ton code à ce que je peux voir :
    - ne pas utiliser de Graphics en dehors des méthodes de la famille paintXx : cela ne donne qu'un affichage ponctuel.
    - dans les méthodes de la famille paintXx, ne pas utiliser de repaint : cela risque de provoquer une boucle infinie.


    Bon courage.
    Mieux que Google, utilisez Sur Java spécialisé sur la plate-forme java !
    Pour réaliser vos applications Java dans le cadre de prestations, forfait, conseil, contactez-moi en message privé.

Discussions similaires

  1. Textview et affichage avec canvas
    Par goute dans le forum Composants graphiques
    Réponses: 0
    Dernier message: 25/12/2014, 22h21
  2. Réponses: 6
    Dernier message: 19/10/2004, 13h46
  3. Resolution d'affichage avec x11
    Par cosmos38240 dans le forum Applications et environnements graphiques
    Réponses: 4
    Dernier message: 06/06/2004, 23h26
  4. Pb affichage avec un PaintBox (pour eviter scintillement)
    Par juan64 dans le forum C++Builder
    Réponses: 7
    Dernier message: 08/04/2004, 09h21
  5. Problème d'affichage avec trace
    Par WriteLN dans le forum Flash
    Réponses: 10
    Dernier message: 22/10/2003, 16h59

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