Bonjour,
Je doit réaliser un programme pilotant un afficheur lumineu à led. Pour cela, j'ai commencé par réaliser un petit programme me s'imbolisant le deffilement du texte sur l'afficheur (le texte défile) :
Mais mon probleme est que ce programme monopolise 100% du proc durant son fonctionnement.
Pour réaliser ça, je crée des points via fillOval() aux endroits qu'il faut pour générer une image, puis pour l'image suivante (image d'éplacé d'une led) je refait de meme puis j'invoque la methode repaint() sur ma frame :
Comment réduire l'occupation CPU de ce programme ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class Demo1 extends JPanel { private static final long serialVersionUID = -1849563652669618448L; public static byte [] matriceAffichage; public void paint(Graphics g) { g.setColor(Color.RED); for (int i = 0; i < 60; i++) { for (int j = 0; j < 8; j++) { if( ((matriceAffichage[i] >> j) & 0x01) == 1) { g.fillOval(10 + (i * 6), 10 + (j * 6), 5, 5); } } } } public static void main(String[] args) { String chaine = args[0]; for (int i = 1; i < args.length; i++) { chaine = chaine+" "+args[i]; } Animation1 anim = new Animation1(chaine); anim.init(); int nbAnim = chaine.length() * 5 + (chaine.length() - 1) + 62; long time = System.currentTimeMillis(); matriceAffichage = anim.matriceAffichage; Demo1 jc = new Demo1(); jc.setBackground(Color.WHITE); jc.setPreferredSize(new Dimension(379, 61)); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBackground(Color.BLACK); frame.getContentPane().add(jc); frame.pack(); frame.setVisible(true); for (int a = 0; a < nbAnim; a++) { while (time + 50 > System.currentTimeMillis()) { } time = System.currentTimeMillis(); matriceAffichage = anim.matriceAffichage; frame.repaint(); anim.avance(); } System.exit(0); } }
Merci d'avance
Partager