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...