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
| import javax.swing.*;
import java.awt.*;
public class FenetreQuitter extends FenetreBoutonsListener {
private JLabel label;
private JLabel image;
public FenetreQuitter(){
super();
build();//On initialise notre fenêtre
}
private void build(){
setTitle("Quitter"); //On donne un titre à l'application
setSize(800,650); //On donne une taille à notre fenêtre
setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
setResizable(true); //On permet le redimensionnement
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
setContentPane(buildContentPane());
}
private JPanel buildContentPane(){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JLabel label = new JLabel("J'espère que mon application vous a plu =D",JLabel.CENTER);
panel.add(label,BorderLayout.NORTH);
ImageIcon icone = new ImageIcon("quitter.gif");
JLabel image = new JLabel(icone,JLabel.CENTER);
panel.add(image,BorderLayout.CENTER);
return panel;
}
public static void main(String[] args) {
//On crée une nouvelle instance de notre FenetreTexte
FenetreQuitter fenetre = new FenetreQuitter();
fenetre.setVisible(true);//On la rend visible
try {
Thread.sleep(5000);
fenetre.dispose();
}
catch(InterruptedException e)
{
//TODO error to handle
fenetre.dispose();
}
}
} |