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
| public class Fenetre extends JFrame {
ImageIcon img =new ImageIcon("E:\\3.jpg");
JLabel label= new JLabel(img);
public Fenetre (){
//Définit un titre pour notre fenêtre
this.setTitle("fenetre");
//Définit sa taille : 550 pixels de large et 450 pixels de haut
this.setSize(550,450);
//Termine le processus lorsqu'on clique sur la croix rouge
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//se positionner au centre
this.setLocationRelativeTo(null);
JPanel pan = new JPanel();
pan.setLayout(new GridBagLayout());
//L'objet servant à positionner les composants
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=this.WIDTH;
gbc.gridheight=2;
pan.add(label,gbc);
this.setContentPane(pan); |
Partager