IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Faire clignoter un panel


Sujet :

avec Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 140
    Par défaut Faire clignoter un panel
    Bonjour, je voudrais faire clignoter un panel lorsque je clique sur un bouton. C'est à dire, alterné la couleur rouge et grise par exemple. Pouvez-vous m'aider s'il vous plait?

    Merci d'avance.

  2. #2
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Par défaut
    Utilise la méthode "setBackground( java.awt.Color)" pour changer la couleur.
    Ensuite, crée un javax.swing.Timer qui va faire l'alternance des couleurs.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 140
    Par défaut
    je n'arrive pas à utiliser la javax.swing.Time

    Pouvez-vous m'aider.

    Merci encore

  4. #4
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Par défaut
    Citation Envoyé par mimi51340 Voir le message
    je n'arrive pas à utiliser la javax.swing.Time

    Pouvez-vous m'aider.

    Merci encore
    Donne le code que tu as fais, on va tenter de le debugger avec toi.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 140
    Par défaut
    j'ai pratiquement rien fait

    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
    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
     
     
    /*
     * Alarme.java
     *
     * Created on 3 avril 2008, 08:35
     */
     
    package Test;
     
    import java.awt.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    /**
     *
     * @author  GRESLON Jérémy
     */
    public class Alarme extends javax.swing.JFrame {
     
        /** Creates new form Alarme */
        public Alarme() {
            initComponents();
           /* CirclePanel test = new CirclePanel();
            test.CirclePanel(Color.BLUE, 50, 50);*/
        }
     
        public void color(){
     
    Thread t = new Thread();  
                    t.run();
                try {
     
                    jPanelAlarme.setBackground(Color.RED);
                    Thread.sleep(1000);
     
                    jPanelAlarme.setBackground(Color.GRAY);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Alarme.class.getName()).log(Level.SEVERE, null, ex);
                }
     
     
     
     
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jPanelAlarme = new javax.swing.JPanel();
            jButtonAlarme = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
     
            jPanelAlarme.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
     
            javax.swing.GroupLayout jPanelAlarmeLayout = new javax.swing.GroupLayout(jPanelAlarme);
            jPanelAlarme.setLayout(jPanelAlarmeLayout);
            jPanelAlarmeLayout.setHorizontalGroup(
                jPanelAlarmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanelAlarmeLayout.setVerticalGroup(
                jPanelAlarmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
     
            jButtonAlarme.setText("Déclenchement alarme");
            jButtonAlarme.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButtonAlarmeActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(146, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButtonAlarme)
                            .addGap(113, 113, 113))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(134, 134, 134))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(67, 67, 67)
                    .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(46, 46, 46)
                    .addComponent(jButtonAlarme)
                    .addContainerGap(60, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>
     
        private void jButtonAlarmeActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            color();
     
     
    }
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Alarme().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton jButtonAlarme;
        private javax.swing.JPanel jPanelAlarme;
        // End of variables declaration
     
    }
    c'est pas grand chose

  6. #6
    Membre Expert
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Par défaut
    Je ne devrais pas te donner la solution mais je pense que si tu ne connais pas le Timer, tu ne pourras pas l'inventer.
    Le clignotement est un bon exemple de son utilisation, après ça tu devrais savoir t'en servir.
    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
    import java.awt.Color;
    import java.util.Timer;
    import java.util.TimerTask;
     
    import javax.swing.JPanel;
    public class MonClignoteur extends Timer {
        private static final int PERIODE = 1000;
     
        private JPanel _panel;
        private boolean _greyPanel = false;
        public MonClignoteur(JPanel panel) {
            super("MonClignoteur");
            _panel = panel;
        }
     
        public void start() {
            schedule(new MyTask(), 0, PERIODE);
        }
     
        private class MyTask extends TimerTask {
            public void run() {
                //changer la couleur du panel
                if(!_greyPanel){
                    _panel.setBackground(Color.GRAY);
                    _greyPanel = true;
                }
                else {
                    _panel.setBackground(Color.RED);
                    _greyPanel = false;
                }
            }
        }
    }

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2008
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 140
    Par défaut
    oui mais sans le main, je fais comment pour compiler ?

    Merci encore.

  8. #8
    Membre Expert
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Par défaut
    Citation Envoyé par mimi51340 Voir le message
    oui mais sans le main, je fais comment pour compiler ?
    On peut très bien compiler une classe qui n'a pas de main, et heureusement.

    Tu dois juste adapter le clignoteur à ton besoin et l'instancier dans ta classe précédente.

Discussions similaires

  1. Réponses: 2
    Dernier message: 13/12/2004, 15h16
  2. [Label] Comment faire clignoter un label ?
    Par delphicrous dans le forum Composants VCL
    Réponses: 7
    Dernier message: 09/07/2004, 16h50
  3. Faire clignoter la barre des tâches
    Par SteelBox dans le forum C++Builder
    Réponses: 2
    Dernier message: 18/01/2004, 18h16
  4. [Sans MFC]Faire clignoter l'icone d'une application?
    Par Melchisedec dans le forum MFC
    Réponses: 4
    Dernier message: 16/07/2003, 12h14
  5. Faire clignoter un caractère
    Par gtr dans le forum x86 16-bits
    Réponses: 2
    Dernier message: 11/01/2003, 00h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo