Semaforo Timer
Semaforo Timer
De Comalcalco
Semaforo
Ingeniería:
Electrónica
Módulo:
Programación Visual
Docente:
Elías Rodríguez Rodríguez
Alumno:
Ángel Gustavo del Ángel Magaña-TE210698
Josué Alejandro Lázaro-TE210076
Grupo: 4to A
Turno: Matutino
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this
license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package com.mycompany.examen_uidad_1;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.util.Timer;
import javax.swing.Timer;
/**
*
* @author 52933
*/
public class Semaforo extends javax.swing.JFrame {
case 2:
jPanel4.setBackground(Color.green);
jPanel3.setBackground(Color.white);
jPanel2.setBackground(Color.white);
jLabel1.setText("Siga");
cont=-1;
break;
}
});
/**
* Creates new form Semaforo
*/
public Semaforo() {
initComponents();
jLabel1.setVisible(false);
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Estados"));
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(71, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addContainerGap())
);
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Control"));
switch_btn.setText("Apagado");
switch_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
switch_btnActionPerformed(evt);
}
});
pack();
}// </editor-fold>
private void switch_btnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jLabel1.setVisible(true);
semaforo.setInitialDelay(0);
semaforo.start();
if (switch_btn.isSelected()) {
System.out.println("Encendido");
switch_btn.setText("Encendido");
} else {
jLabel1.setVisible(false);
System.out.println("Apagado");
switch_btn.setText("Apagado");
semaforo.stop();
jPanel4.setBackground(Color.gray);
jPanel3.setBackground(Color.gray);
jPanel2.setBackground(Color.gray);
cont=-1;
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Semaforo.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Semaforo.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Semaforo.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Semaforo.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
}
//</editor-fold>