Affichage JFrame simple avec Swing
Bonjour,
je suis novice en java et je suis le tuto suivant:
http://baptiste-wicht.developpez.com...?page=afficher
Tout allait bien avec JWindow et JDialog. Mais avec Jframe, j'ai l'impression que le méthode "initialiserFrame" n'est pas lue.
En fait, lorsque je lance, il m'affiche juste une fenêtre sans tenir compte des spécifictions mises dans "initialiserFrame".
J'ai 2 classes:
la classe Fenetre
Code:
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
|
package tutoswing;
//import java.awt.Graphics;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
public class Fenetre extends JFrame
{
public Fenetre ()
{
super();
initialiserFrame(); //initialisation du frame
}
private void initialiserFrame()
{
setTitle(" Tic tac toe "); //titre
setSize(600, 600); //taille
setLocationRelativeTo(null); //centrer la fenêtre sur l'écran
setResizable(false); //pas de redimensionnement de la fenêtre
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //fermer lors du clic sur la croix
setContentPane(contenuFrame());
// setVisible(true);
}
private JPanel contenuFrame()
{
JPanel panelHaut = new JPanel();
// panelHaut.setBackground(Color.BLACK);
panelHaut.setLayout(new FlowLayout());
JLabel label = new JLabel("Bienvenue dans cette partie de TIC TAC TOE ");
panelHaut.add(label);
return panelHaut;
}
} |
et la classe main qui lance le programme:
Code:
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
|
package tutoswing;
import java.io.IOException;
import javax.swing.SwingUtilities;
//import javax.swing.JFrame;
public class Main
{
public static void main(String[] args) throws IOException
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
Fenetre mainFenetre = new Fenetre();
mainFenetre.setVisible(true);
}
});
}
} |
le titre de la fenêtre ne s'affiche pas, ni la le texte que j'ai mis dans le JPanel, rien de tout ce qui est dans "initialiserFrame"