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
| package jeux.memory.images;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
public class Diaporama extends JFrame
{
private GestionDonnees gestionDonnees;
private int delai = 1000;
private JLabel afficheDelai;
private Cartouche cartouche;
private static JPanel panneauCentral = new JPanel();
private JButton plus, moins;
private JProgressBar progression;
private JLabel test;
public Diaporama(GestionDonnees gd)
{
super("Diaporama");
this.gestionDonnees = gd;
this.setSize (800,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
// this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
JPanel panneauCentral = new JPanel();
JPanel panneauBas = new JPanel();
progression = new JProgressBar(0,100);
progression.setPreferredSize(new Dimension(500,20));
progression.setStringPainted(true);
plus = new JButton("+");
String police = plus.getFont().getFontName();
int taille = 20;
Font font = new Font(police,Font.BOLD,taille);
plus.setFont(font);
plus.setFocusPainted(false);
moins = new JButton("-");
moins.setFont(font);
moins.setFocusPainted(false);
// delai = 3000;
afficheDelai = new JLabel(delai + " s");
panneauBas.add(progression);
panneauBas.add(plus);
panneauBas.add(moins);
panneauBas.add(afficheDelai);
String liste = gestionDonnees.getImages(0);
String nom = liste.split(";")[0];
ListeImages listeImages = new ListeImages(nom,liste,800);
cartouche = new Cartouche(listeImages);
panneauCentral.add(cartouche);
getContentPane().add(panneauBas, BorderLayout.SOUTH);
getContentPane().add(panneauCentral,BorderLayout.CENTER);
setVisible(true);
afficher();
}
private void afficher()
{
new Thread(new Runnable()
{
public void run()
{
for (int i = 1 ; i < gestionDonnees.getNbDonnees() ; i++)
{
try
{
Thread.sleep(delai);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String listeImages = gestionDonnees.getImages(i);
String nom = gestionDonnees.getNom(i);
final ListeImages images = new ListeImages(nom,listeImages,800);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
cartouche.modifieImages(images);
cartouche.revalidate();
panneauCentral.revalidate();
}
});
}
}
}).start();
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
private Diaporama fenetre;
public void run()
{
fenetre = new Diaporama(new GestionDonnees());
}
});
}
} |