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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import mu.ateliersoleil.gestionDB.RequetesEnregistrées;
public class Affichage extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private JPanel panel = new JPanel(); //fonction appelée lors du démarage de l'application (affiche uniquement les boutons)
Panneau pan = new Panneau();
List<JButton> listeBouton = new ArrayList<JButton>();
public void AffichageDepart(){
this.setTitle("Atelier Soleil");
this.setSize(1440,870);
panel.setLayout(new BorderLayout());
JPanel listeOnglets = new JPanel();
initBoutons();
for(int i = 0; i < listeBouton.size(); i++){
listeBouton.get(i).addActionListener(this);
listeOnglets.add(listeBouton.get(i));
}
panel.add(listeOnglets, BorderLayout.NORTH);
this.setContentPane(panel);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void AffichageSaison(){ //fonction appellée lors du click sur le bouton Saison
panel.removeAll();
panel.setLayout(new BorderLayout());
JPanel listeOnglets = new JPanel();
initBoutons();
for(int i = 0; i < listeBouton.size(); i++){
listeBouton.get(i).addActionListener(this);
listeOnglets.add(listeBouton.get(i));
}
JPanel gauche = new JPanel();
AffichageSaison AS = new AffichageSaison(); //affiche le contenu de la fenetre
gauche = AS.init();
panel.add(listeOnglets, BorderLayout.NORTH);
panel.add(gauche, BorderLayout.WEST);
panel.repaint();
this.setContentPane(panel);
this.repaint();
System.out.println("test");
}
public void AffichageTheme(){ //fonction appellée lors du click sur le bouton Theme
panel.removeAll();
panel.setLayout(new BorderLayout());
JPanel listeOnglets = new JPanel();
initBoutons();
for(int i = 0; i < listeBouton.size(); i++){
listeBouton.get(i).addActionListener(this);
listeOnglets.add(listeBouton.get(i));
}
JPanel gauche = new JPanel();
AffichageListePerles ALP = new AffichageListePerles();
gauche = ALP.init();
panel.add(listeOnglets, BorderLayout.NORTH);
panel.add(gauche, BorderLayout.WEST);
panel.repaint();
this.remove(panel);
this.setContentPane(panel);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.repaint();
}
public void initBoutons() {
List<String> nomBouton = new ArrayList<String>();
nomBouton.add("Saison");
nomBouton.add("Theme");
nomBouton.add("Model");
nomBouton.add("...");
nomBouton.add("...");
nomBouton.add("...");
nomBouton.add("...");
nomBouton.add("...");
nomBouton.add("...");
nomBouton.add("...");
for(int i = 0; i < nomBouton.size(); i++){
Boutton bouton = new Boutton(nomBouton.get(i));
Dimension dim = new Dimension((this.getWidth() - 75) / nomBouton.size(), 25);
bouton.setPreferredSize(dim);
listeBouton.add(bouton);
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == listeBouton.get(0)){
System.out.println("Clik bouton 1");
resetBoutonClicable(); //réinitialiser le statut des boutons
listeBouton.get(0).setEnabled(false);//le bouton cliké ne soit plus clickable
AffichageSaison();
}
if (e.getSource() == listeBouton.get(1)){
System.out.println("Clik bouton 2");
resetBoutonClicable();
listeBouton.get(1).setEnabled(false);
AffichageTheme();
}
if (e.getSource() == listeBouton.get(2)){
System.out.println("Clik bouton 3");
resetBoutonClicable();
listeBouton.get(2).setEnabled(false);
}
}
public void resetBoutonClicable(){
for(int i = 0; i < listeBouton.size(); i++){
listeBouton.get(i).setEnabled(true);
}
}
public Image recupImage(String nomModel ,Connection connexion){ //fonction pour récupérer des image dans la DB
RequetesEnregistrées requete = new RequetesEnregistrées();
ResultSet result = requete.SelectModelByNom(nomModel, connexion);
Image img = null;
try {
while(result.next()){
Blob blob = result.getBlob(7);
InputStream in = blob.getBinaryStream();
img = ImageIO.read(in);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}
} |
Partager