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
| // importation pour la classe graphique Frame
import java.awt.*;
import java.lang.*;
import java.io.*;
// importation pour la classe String
//import java.lang.*;
class GestionnaireTrace
{
public static void main(String [] args)
{
Frame f ;
String [] texte =
{ "texte1", "texte2", "texte3", "texte4", "texte5" };
// Le choix du gestionnaire de tracé est précisé dans args[0]
if(args.length > 0)
{
f = new Frame("Affichage de textes");
System.out.println(args[0]);
if(args[0].compareTo("BL") == 0)
{
// on choisit un BorderLayout
f.setLayout(new BorderLayout());
f.add(new Label(texte[0],Label.CENTER),BorderLayout.NORTH);
f.add(new Label(texte[1],Label.CENTER),BorderLayout.SOUTH);
f.add(new Label(texte[2],Label.CENTER),BorderLayout.EAST);
f.add(new Label(texte[3],Label.CENTER),BorderLayout.WEST);
f.add(new Label(texte[4],Label.CENTER),BorderLayout.CENTER);
}
else if(args[0].compareTo("GL") == 0)
{
// on choisit un GridLayout à deux colonnes
f.setLayout(new GridLayout(0,2));
for(int i = 0; i < texte.length; i++)
f.add(new Label(texte[i],Label.CENTER));
}
else if(args[0].compareTo("FL") == 0)
{
// on choisit un FlowLayout
f.setLayout(new FlowLayout());
for(int i = 0; i < texte.length; i++)
f.add(new Label(texte[i],Label.CENTER));
}
// On taille la fenêtre
f.setSize(180,100);
//affichage de la fenêtre
f.setVisible(true);
}
else
// aucun argument n'a été passé
System.out.println("aucun argument !!!");
}
} |
Partager