/* * Alarme.java * * Created on 23 avril 2008, 23:14 */ package Test; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; /** * * @author Jérémy GRESLON */ 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); 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("Intervention sécurité"); 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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(133, 133, 133) .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(121, 121, 121) .addComponent(jButtonAlarme))) .addContainerGap(146, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(39, 39, 39) .addComponent(jPanelAlarme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(33, 33, 33) .addComponent(jButtonAlarme) .addContainerGap(105, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButtonAlarmeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JPanel panelQuiVaClignoter = new JPanel(); Clignoteur clignoteur = new Clignoteur(Color.white, Color.red, 1000, 1000, panelQuiVaClignoter); jPanelAlarme.add(panelQuiVaClignoter); jPanelAlarme.setVisible(true); clignoteur.demarrer(); } /** * @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 }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Test; import java.awt.Color; import java.awt.Component; public class Clignoteur extends Thread { private Color couleur1, couleur2; private long temps1, temps2; private Component composantQuiDoitClignoter; private boolean estEnTrainDeClignoter; public Clignoteur(Color couleur1, Color couleur2, long temps1, long temps2, Component composantQuiDoitClignoter) { this.couleur1 = couleur1; this.couleur2 = couleur2; this.temps1 = temps1; this.temps2 = temps2; this.composantQuiDoitClignoter = composantQuiDoitClignoter; estEnTrainDeClignoter = false; } public void demarrer() { estEnTrainDeClignoter = true; start(); } public void arreter() { estEnTrainDeClignoter = false; } public void run() { while (estEnTrainDeClignoter) { composantQuiDoitClignoter.setBackground(couleur1); try { sleep(temps1); } catch (InterruptedException e) { } composantQuiDoitClignoter.setBackground(couleur2); try { sleep(temps2); } catch (InterruptedException e) { } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question