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
| package jeux.memory.images;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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 implements ActionListener
{
private GestionDonnees gestionDonnees;
private int delai;
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("+");
plus.addActionListener (this);
moins = new JButton("-");
moins.addActionListener (this);
delai = 3000;
afficheDelai = new JLabel("timing entre deux images = " + (int)(delai/1000) + " 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();
}
});
}
}
}).start();
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
private Diaporama fenetre;
public void run()
{
fenetre = new Diaporama(new GestionDonnees());
}
});
}
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == plus) augmenterDelai();
if (evt.getSource() == moins) diminuerDelai();
}
private void diminuerDelai()
{
System.out.println("diminuer délai");
delai = Math.max(1000, delai -1000);
Runnable code = new Runnable()
{
public void run()
{
afficheDelai.setText("timing entre deux images = " + delai + " s");
}
};
if (SwingUtilities.isEventDispatchThread())
{
code.run();
}
else
{
SwingUtilities.invokeLater(code);
}
// afficheDelai.revalidate();
}
private void augmenterDelai()
{
System.out.println("augmenter délai");
}
} |
Partager