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 :

Afficher deux images


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 Afficher deux images
    Bonjour, je souhaiterai alterner toutes les secondes, deux images. Ceci dans un panel. C'est à dire, afficher une image, attendre une seconde puis afficher la seconde, réafficher la 1ère, etc.

    Comment puis-je faire? sachant que je suis débutant.

    Merci d'avance.

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 5
    Par défaut
    Voici une solution en utilisant un JLabel dans ton JPanel.

    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
     
    import java.util.Timer;
    import java.util.TimerTask;
     
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class PanneauImage extends JPanel {
    	private static final String IMAGES[] = { "image1.jpg", "image2.jpg" };
    	private JLabel label = new JLabel();
    	private static final Icon ICONE1 = new ImageIcon(IMAGES[0]);
    	private static final Icon ICONE2 = new ImageIcon(IMAGES[1]);
    	private static final Icon ICONES[] = { ICONE1, ICONE2 };
    	private int compteur = 0;
    	private Timer timer;
     
    	public PanneauImage() {
    		super();
    		compteur = 0;
    		label.setIcon(ICONES[compteur]);
    		add(label);
     
    		// Création et lancement du timer
    		timer = new Timer();
    		timer.schedule(new Action(this), 0, 1 * 1000);
    	}
     
    	class Action extends TimerTask {
    		PanneauImage panel;
     
    		public Action(PanneauImage panel) {
    			this.panel = panel;
    		}
     
    		public void run() {
    			compteur = (compteur+1) % 2;
    			panel.getLabel().setIcon(ICONES[compteur]);
    		}
    	}
     
    	/**
             * @return the label
             */
    	public JLabel getLabel() {
    		return label;
    	}
    }

  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
    comment faire appel à la classe PanneauImage depuis ma classe Alarme ?

    voici le code de ma classe Alarme (c'est un JFrame):
    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
     
    /*
     * Alarme.java
     *
     * Created on 3 avril 2008, 08:35
     */
     
    package Test;
     
    import java.awt.*;
    import java.util.*;
    /**
     *
     * @author  GRESLON Jérémy
     */
    public class Alarme extends javax.swing.JFrame {
     
        /** Creates new form Alarme */
        public Alarme() {
            initComponents();
     
        }
     
     
     
        /** 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:
     
     
     
     
     
    }                                             
     
        /**
         * @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                   
     
    }
    Merci encore.

Discussions similaires

  1. Comment afficher deux images avec Node js ?
    Par keokaz dans le forum NodeJS
    Réponses: 5
    Dernier message: 03/10/2014, 06h11
  2. Réponses: 8
    Dernier message: 27/11/2013, 17h40
  3. [subplot] afficher deux images
    Par abdouccu dans le forum MATLAB
    Réponses: 4
    Dernier message: 16/08/2012, 11h37
  4. Afficher deux images côte à côte
    Par FirePrawn dans le forum GTK+ avec C & C++
    Réponses: 12
    Dernier message: 11/10/2011, 15h15
  5. afficher deux images indépendantes
    Par jojob dans le forum Java ME
    Réponses: 1
    Dernier message: 23/05/2007, 11h28

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