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 :

Graphics : question simple


Sujet :

2D Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 57
    Points : 26
    Points
    26
    Par défaut Graphics : question simple
    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
    class Test
    {   
       static Graphics ouvreFenetre(int l, int h)
       {
          Frame fenetre = new Frame("Dessin");
          fenetre.addWindowListener(new WindowAdapter()
          {
             public void windowClosing(WindowEvent we) 
             {
                System.out.println("Fenetre fermee, c'est fini.");
                System.exit(0);
             }
          });
     
          fenetre.setBounds(10,10, l, h);
          fenetre.setBackground(Color.white);
          fenetre.setForeground(Color.black);      
          fenetre.setVisible(true);
     
          return fenetre.getGraphics();
       }
     
       static void fenetreRayee(int l, int h, int e)
       {
          Graphics g = ouvreFenetre(l,h);
     
          for(int x=0; x<=l; x+=e)
             g.drawLine(x,0,x,h);
       }
     
       public static void main(String[] args) 
       {
          fenetreRayee(700,700,50);
       }
    }
    Voila ce code compile bien, mais lors de l'execution la fenetre s'affiche mais le dessin apparait comme un flash puis disparait... comment faire ?
    PS : je travaille sous windows xp...

  2. #2
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    C'est tout à fait normal, il faut refaire le dessin à chaque repaint

    La méthode classique est de créer une classe héritant de JComponent ou de l'une de ses classes filles (JPanel dans ton cas), et de redéfinir sa méthode paintComponent

    Voici un exemple de ce genre de choses que j'ai posté cet après midi même:

    http://www.developpez.net/forums/sho...75&postcount=6

    (ici j'ai utilisés un JLabel en tant que classe mère, mais ça aurait parfaitement marché avec un JPanel)

    ++
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 57
    Points : 26
    Points
    26
    Par défaut
    Mais pourquoi sous linux ca fonctionne bien ?

  4. #4
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    La magie des implémentations d'une plateforme à l'autre, enfin ici la magie des appels à repaint que tu ne maitrises pas...
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 57
    Points : 26
    Points
    26
    Par défaut
    très bien ya plus qu'a installer linux ^^

  6. #6
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Euh avant tout y'a plus qu'à changer ton code, même sous linux ça ne fontionnera par forcément bien...
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

Discussions similaires

  1. Réponses: 7
    Dernier message: 28/09/2004, 14h27
  2. Question simple sur la libération des objets
    Par gibet_b dans le forum Langage
    Réponses: 2
    Dernier message: 12/07/2004, 10h01
  3. DTS : Question simple sur sources de données
    Par guignol dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 28/05/2004, 12h09
  4. [LG]Choix du pascal ou autre ? Questions simples...
    Par vlacq dans le forum Langage
    Réponses: 5
    Dernier message: 30/01/2004, 23h42
  5. Question simple sur les threads :)
    Par momox dans le forum C++Builder
    Réponses: 2
    Dernier message: 15/06/2003, 04h13

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