127 lines
4.0 KiB
Java
127 lines
4.0 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class SeleccionarAsientoV extends JPanel {
|
|
|
|
private JPanel pSuperior = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
|
private JButton bRegresar = new JButton("Regresar.");
|
|
private int noAsientosSeleccionados = 0;
|
|
private JLabel lSeleccionar = new JLabel("Asientos seleccionados: " + noAsientosSeleccionados);
|
|
|
|
private JPanel pInferior = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
|
private int total = 0;
|
|
private JLabel lTotal = new JLabel("Total: " + total + "$");
|
|
private JButton bSeleccionar = new JButton("Seleccionar");
|
|
|
|
private JPanel pSala = new JPanel(new GridBagLayout());
|
|
|
|
private JToggleButton [][]bAsientos;
|
|
|
|
private Asiento [][] asientos;
|
|
|
|
|
|
public SeleccionarAsientoV(Asiento [][] parAsientos) throws HeadlessException {
|
|
this.setLayout(new BorderLayout());
|
|
|
|
asientos = parAsientos;
|
|
|
|
agregarComponentes();
|
|
crearCeldas(7,10);
|
|
}
|
|
|
|
public void agregarComponentes(){
|
|
pSuperior.add(this.bRegresar);
|
|
pSuperior.add(lSeleccionar);
|
|
|
|
pInferior.add(this.lTotal);
|
|
pInferior.add(this.bSeleccionar);
|
|
|
|
this.add(pSuperior,BorderLayout.NORTH);
|
|
this.add(pInferior,BorderLayout.SOUTH);
|
|
}
|
|
|
|
public void crearCeldas(int parX, int parY){
|
|
|
|
GridBagConstraints con = new GridBagConstraints();
|
|
|
|
bAsientos = new JToggleButton[parX][parY];
|
|
|
|
String zona = "";
|
|
|
|
JToggleButton tfAux;
|
|
for(int i = 0; i < parX; i++){
|
|
for(int j = 0; j < parY; j ++){
|
|
tfAux = new JToggleButton("");
|
|
if( ( (j >= 2) && (j <= 7) ) && ( (i >= 2) && (i <= 6) ) ){
|
|
tfAux.setBackground(Color.PINK);
|
|
zona = "A";
|
|
tfAux.setText("200$");
|
|
}
|
|
if( ((i == 1) && (j > 0) && (j < 9)) || ((j == 1) && (i > 0)) || ((j == 8) && (i > 0)) ){
|
|
tfAux.setBackground(Color.ORANGE);
|
|
zona = "B";
|
|
tfAux.setText("130$");
|
|
}
|
|
if( (i == 0) || (j == 0) || (j == 9)){
|
|
tfAux.setBackground(Color.YELLOW);
|
|
zona = "C";
|
|
tfAux.setText("65$");
|
|
}
|
|
if(asientos[i][j].isDisponibilidad()){
|
|
tfAux.setBackground(Color.DARK_GRAY);
|
|
tfAux.setText("ND");
|
|
}
|
|
tfAux.setSize(100,100);
|
|
//tfAux.addKeyListener(new GestiónTecladoEscribirCaracter(this,i,j));
|
|
tfAux.addChangeListener(new GestiónBotónSeleccionarAsiento(new Asiento(i,j,zona,asientos[i][j].isDisponibilidad()),this));
|
|
con.gridx = j;
|
|
con.gridy = i;
|
|
con.gridheight = 1;
|
|
con.gridwidth = 1;
|
|
System.out.println(i+" "+j+ " "+bAsientos.length);
|
|
bAsientos[i][j] = tfAux;
|
|
pSala.add(bAsientos[i][j],con);
|
|
}
|
|
}
|
|
|
|
pSala.setBounds(0,0,700,700);
|
|
this.add(pSala,BorderLayout.CENTER);
|
|
}
|
|
|
|
public void seleccionarAsientos(Asiento asiento){
|
|
int precio = 0;
|
|
|
|
int x = asiento.getX(), y = asiento.getY();
|
|
String zona = asiento.getZona();
|
|
|
|
switch (zona){
|
|
case "A":
|
|
precio = 200;
|
|
break;
|
|
|
|
case "B":
|
|
precio = 130;
|
|
break;
|
|
|
|
case "C":
|
|
precio = 65;
|
|
break;
|
|
}
|
|
|
|
if(!bAsientos[x][y].getText().equals("ND")) {
|
|
if (bAsientos[x][y].isSelected()) {
|
|
noAsientosSeleccionados++;
|
|
total += precio;
|
|
} else {
|
|
noAsientosSeleccionados--;
|
|
total -= precio;
|
|
}
|
|
}else{
|
|
bAsientos[x][y].setSelected(false);
|
|
}
|
|
|
|
lSeleccionar.setText("Asientos seleccionados: " + noAsientosSeleccionados);
|
|
lTotal.setText("Total: " + total + "$");
|
|
}
|
|
}
|