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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class FenetreAvecBouton extends JFrame implements ActionListener{
private JPanel container = null;
private FlowLayout layout = null ;
private JLabel texte = null;
private JButton bouton = null;
private int nombre = 0;
public FenetreAvecBouton(){
super();
build();
}
private void build(){
this.setTitle("Projet d'été: Smilateur d'une zonz fractal en 3D");
this.setSize(700,700);
this.setLocationRelativeTo(null);
this.setResizable(false) ;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getContainer());
}
public static void main(String[] args){
FenetreAvecBouton gui = new FenetreAvecBouton(); //On crée une nouvelle instance de notre fenêtre
gui.setVisible(true);
}
private JPanel getContainer(){
layout = new FlowLayout();
layout.setAlignment(FlowLayout.CENTER);
container = new JPanel() ;
container.setLayout(layout);
container.setBackground(Color.white);
texte = new JLabel() ;
texte.setPreferredSize(new Dimension(250,45)) ;
texte.setText("réaliser par : ");
container.add(texte);
ImageIcon image = new ImageIcon("dhs498fk_1crfvw5hr_b.png");
JLabel l = new JLabel(image);
container.add(l);
bouton = new JButton () ;
bouton.setPreferredSize(new Dimension(125,25)) ;
bouton.setText("entrer") ;
bouton.addActionListener(this);
container.add(bouton);
return container ;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == bouton){
nombre++;
texte.setText("Vous avez cliqué " + nombre + " fois sur le bouton");
}
}
} |
Partager