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

avec Java Discussion :

mon rond affiche pas


Sujet :

avec Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut mon rond affiche pas
    bonjour
    j’écris le prg suivant,en l’exécutant le fenêtre apparait, mais il n' y rien dedans;
    aucune erreur non plus
    aidez moi svp

    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
     
    import java.awt.Dimension;
    import javax.swing.JFrame;
    public class Fenetre extends JFrame
    {
      private Panneau pan=new Panneau();
     
    	 public Fenetre()
    	 {
    	   this.setTitle("Animation");
    	   this.setSize(300,300);
    	   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	   this.setLocationRelativeTo(null);
    	   this.setContentPane(pan);
    	   this.setVisible(true);
    	   go();
           }
           private void go()
    	           {
    	        	   int x=pan.getPosX(),y=pan.getPosY();
    	        	   boolean backX=false;
    	        	   boolean backY=false;
    	        	   while(true)
    	        	   {
    	        		   if(x<1)backX=false;
    	        		   if(x>pan.getWidth()-50)backX=true;
    	        		   if(y<1)backY=false;
    	        		   if(y>pan.getHeight()-50)backY=true;
    	        		   if(!backX)
    	        			   pan.setPosX(++x);
    	        		   else
    	        			   pan.setPosX(--x);
    	        		   if(!backY)
    	        			   pan.setPosX(++y);
    	        		   else
    	        			   pan.setPosX(--y);
    	        		   pan.repaint();
     
    	        	   try
    	        	   {
    	        		   Thread.sleep(3);
    	        	   }
    	        	   catch(InterruptedException e)
    	        	   {
    	        		   e.printStackTrace();
    	        	   }
    	        	   }
                            }    
    	       public static void main(String[]args)
    	        {   
    	                Fenetre pan=new Fenetre();    
    	        }
    	    } 
     
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Panneau extends JPanel
    {
    	private int posX=-50;
    	private int posY=-50;
     
    	public void paintComponent(Graphics g)
    	    { 
    		g.setColor(Color.white);
    		g.fillRect(0,0,this.getWidth(),this.getHeight());
    		g.setColor(Color.red);//on redéfinit une couleur pour notre rond
    		g.fillOval(posX,posY,50,50);
    	    }
    	public int getPosX()
    	{
    		return posX;
    	}
    	public void setPosX(int posX)
    	{
    		this.posX=posX;
    	}
    	public int getPosY()
    	{
    		return posY;
    	}
    	public void setPosY(int posY)
    	{
    		this.posY=posY;
    	}
    }

  2. #2
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Salut

    j'avais répondu à ton dernier post relatif à ce programme
    Tu pourrais poster la classe Panneau s'il te plait, car s'il y'a un problème d'affichage ça doit venir de là ?

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    il y est inclus dans le prg
    j'ai changé les codes mon prg:
    pour que le rond puisse détecter les bords de notre Panneau et ricoche sur ceux-ci
    regardez bien svp

  4. #4
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    essaye ça
    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
     
    import java.awt.Color;
    import java.awt.Graphics;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Fenetre extends JFrame
    {
      private Panneau pan=new Panneau();
     
    	 public Fenetre()
    	 {
    	   this.setTitle("Animation");
    	   this.setSize(300,300);
    	   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	   this.setLocationRelativeTo(null);
    	   this.setContentPane(pan);
    	   this.setVisible(true);
    	   go();
           }
           private void go() {
     
        	   int x=pan.getPosX(),y=pan.getPosY();
    	       boolean backX=false;
    	       boolean backY=false;
     
    	       while(true) {
    	    	   if(x<1)backX=false;
    	    	   if(x>pan.getWidth()-50)backX=true;
     
    	    	   if(y<1)backY=false;
    	    	   if(y>pan.getHeight()-50)backY=true;
     
    	    	   if(!backX) pan.setPosX(++x);
    	    	   else pan.setPosX(--x);
     
    	    	   if(!backY) pan.setPosX(++y);
    	    	   else pan.setPosX(--y);
     
    	    	   pan.repaint();
     
    	    	   try {
    	    		   Thread.sleep(3);
    	    	   } catch(InterruptedException e) {}
    	       }
           }    
    	       public static void main(String[]args)
    	        {   
    	                Fenetre pan=new Fenetre();    
    	        }
     
    	       public class Panneau extends JPanel
    	       {
    	       	private int posX=10;
    	       	private int posY=10;
     
    	       	public void paintComponent(Graphics g)
    	       	    { 
    	       		g.setColor(Color.white);
    	       		g.fillRect(0,0,this.getWidth(),this.getHeight());
    	       		g.setColor(Color.red);//on redéfinit une couleur pour notre rond
    	       		g.fillOval(posX,posY,50,50);
    	       	    }
    	       	public int getPosX()
    	       	{
    	       		return posX;
    	       	}
    	       	public void setPosX(int posX)
    	       	{
    	       		this.posX=posX;
    	       	}
    	       	public int getPosY()
    	       	{
    	       		return posY;
    	       	}
    	       	public void setPosY(int posY)
    	       	{
    	       		this.posY=posY;
    	       	}
    	       }
    	    }
    en fait ton code marche bien
    j'ai juste changé les coordonnées du cercle rouge

    mais je ne sais pas si c'est vraiment ce que tu cherches ?

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    ok j'ai trouvé mon erreur
    erreur était dans ces lignes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
      if(!backX)
    	        			   pan.setPosX(++x);
     
    	        		   else
    	        			   pan.setPosX(--x);
     
     
    	        		   if(!backY)
    	        			   pan.setPosY(++y);
     
    	        		   else
    	        			   pan.setPosY(--y);
    au lieu de marquer
    pan.setPosY(++y);
    else
    pan.setPosY(--y);

    j'avais écrit deux fois pour X

    merci beaucoup

  6. #6
    Membre confirmé
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Points : 646
    Points
    646
    Par défaut
    Ah oui ça m'a échappé moi aussi

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

Discussions similaires

  1. Problème mon écran affiche (pas de signal)
    Par Belywin dans le forum Composants
    Réponses: 9
    Dernier message: 25/11/2011, 17h15
  2. Mon écran affiche "Pas de signal"
    Par jad777 dans le forum Périphériques
    Réponses: 4
    Dernier message: 24/01/2008, 11h08
  3. [XSL]Comment faire ceci ?? Mon for-each n'affiche pas tout !
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 27/07/2005, 15h04
  4. Mon dessin ne s'affiche pas au lancement...
    Par Deedier dans le forum MFC
    Réponses: 6
    Dernier message: 02/05/2005, 16h29
  5. [JApplet]mon applet ne s'affiche pas.
    Par yannick56 dans le forum Applets
    Réponses: 6
    Dernier message: 27/05/2004, 17h05

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