Skip to content

Instantly share code, notes, and snippets.

@everblut
Created February 24, 2012 21:20
Show Gist options
  • Save everblut/1903816 to your computer and use it in GitHub Desktop.
Save everblut/1903816 to your computer and use it in GitHub Desktop.
Interfaz
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.imageio.*;
public class Interfaz extends JFrame{
private JPanel panelPrincipal;
private Luces[] semaGrap;
private Secuenciador sec;
private JLabel[] etiqueta;
private JLabel[] etiquetaCarros;
public Interfaz(){
super("Proyecto Semaforos");
panelPrincipal = new JPanel();
panelPrincipal.setLayout(null);
etiqueta = new JLabel[4];
etiquetaCarros = new JLabel[2];
setLocation(200,200);
setSize(1200,1000);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
crearSemaforos();
llenarPanel();
Hilos();
}
public void crearSemaforos(){
semaGrap = new Luces[4];
semaGrap[0] = new Luces();
semaGrap[1] = new Luces();
semaGrap[2] = new Luces();
semaGrap[3] = new Luces();
}
public void llenarPanel(){
etiqueta[0] = new JLabel();
etiqueta[1] = new JLabel();
etiqueta[2] = new JLabel();
etiqueta[3] = new JLabel();
etiquetaCarros[0] = new JLabel();
etiquetaCarros[1] = new JLabel();
etiqueta[0].setText("A");
etiqueta[1].setText("B");
etiqueta[2].setText("C");
etiqueta[3].setText("D");
etiquetaCarros[0].setText("CarrosX");
etiquetaCarros[1].setText("CarrosY");
panelPrincipal.add(semaGrap[0]);
semaGrap[0].setBounds(10,250,48,140);
panelPrincipal.add(etiqueta[0]);
etiqueta[0].setBounds(20,370,50,50);
panelPrincipal.add(etiquetaCarros[0]);
etiquetaCarros[0].setBounds(40, 400,100,100); // NUM ALT
panelPrincipal.add(semaGrap[1]);
semaGrap[1].setBounds(460,20,48,140);
panelPrincipal.add(etiqueta[1]);
etiqueta[1].setBounds(466,150,50,50);
panelPrincipal.add(semaGrap[2]);
semaGrap[2].setBounds(680,500,48,140);
panelPrincipal.add(etiqueta[2]);
etiqueta[2].setBounds(686,600,48,140);
panelPrincipal.add(etiquetaCarros[1]); //DEB
etiquetaCarros[1].setBounds(686,380,100,100); // NUM ALT
panelPrincipal.add(semaGrap[3]);
semaGrap[3].setBounds(530,20,48,140);
panelPrincipal.add(etiqueta[3]);
etiqueta[3].setBounds(537,150,50,50);
}
public void Hilos(){
semaforoThread[] semaforo = new semaforoThread[4];
semaforo[0] = new semaforoThread('A');
semaforo[1] = new semaforoThread('B');
semaforo[2] = new semaforoThread('C');
semaforo[3] = new semaforoThread('D');
sec = new Secuenciador(semaforo,semaGrap,etiquetaCarros);
}
public void Desplegar(){
Container contenedor = getContentPane();
contenedor.add(panelPrincipal,BorderLayout.CENTER );
setVisible(true);
sec.iniciar();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment