mezontleTeam/SeleccionarAsientoV.java

136 lines
4.2 KiB
Java
Raw Normal View History

2024-03-11 01:43:27 +00:00
import javax.swing.*;
import java.awt.*;
public class SeleccionarAsientoV extends JFrame {
private JPanel pSuperior = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JButton bRegresar = new JButton("Regresar.");
2024-03-11 02:31:19 +00:00
private int noAsientosSeleccionados = 0;
2024-03-11 01:43:27 +00:00
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());
2024-03-11 02:31:19 +00:00
private JToggleButton [][]bAsientos;
private Asiento [][] asientos;
2024-03-11 01:43:27 +00:00
2024-03-11 03:12:56 +00:00
public SeleccionarAsientoV(Asiento [][] parAsientos) throws HeadlessException {
2024-03-11 01:43:27 +00:00
super("Seleccionar Asiento");
this.setLayout(new BorderLayout());
2024-03-11 03:12:56 +00:00
asientos = parAsientos;
2024-03-11 01:43:27 +00:00
agregarComponentes();
crearCeldas(7,10);
iniciar();
}
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();
2024-03-11 02:31:19 +00:00
bAsientos = new JToggleButton[parX][parY];
2024-03-11 01:43:27 +00:00
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";
2024-03-11 02:31:19 +00:00
tfAux.setText("200$");
2024-03-11 01:43:27 +00:00
}
if( ((i == 1) && (j > 0) && (j < 9)) || ((j == 1) && (i > 0)) || ((j == 8) && (i > 0)) ){
tfAux.setBackground(Color.ORANGE);
zona = "B";
2024-03-11 02:31:19 +00:00
tfAux.setText("130$");
2024-03-11 01:43:27 +00:00
}
if( (i == 0) || (j == 0) || (j == 9)){
tfAux.setBackground(Color.YELLOW);
zona = "C";
2024-03-11 02:31:19 +00:00
tfAux.setText("65$");
2024-03-11 01:43:27 +00:00
}
2024-03-11 03:12:56 +00:00
if(asientos[i][j].isDisponibilidad()){
tfAux.setBackground(Color.DARK_GRAY);
tfAux.setText("ND");
}
2024-03-11 01:43:27 +00:00
tfAux.setSize(100,100);
//tfAux.addKeyListener(new GestiónTecladoEscribirCaracter(this,i,j));
2024-03-11 03:12:56 +00:00
tfAux.addChangeListener(new GestiónBotónSeleccionarAsiento(new Asiento(i,j,zona,asientos[i][j].isDisponibilidad()),this));
2024-03-11 01:43:27 +00:00
con.gridx = j;
con.gridy = i;
con.gridheight = 1;
con.gridwidth = 1;
2024-03-11 02:31:19 +00:00
System.out.println(i+" "+j+ " "+bAsientos.length);
bAsientos[i][j] = tfAux;
pSala.add(bAsientos[i][j],con);
2024-03-11 01:43:27 +00:00
}
}
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;
}
2024-03-11 03:12:56 +00:00
if(!bAsientos[x][y].getText().equals("ND")) {
if (bAsientos[x][y].isSelected()) {
noAsientosSeleccionados++;
total += precio;
} else {
noAsientosSeleccionados--;
total -= precio;
}
2024-03-11 01:43:27 +00:00
}else{
2024-03-11 03:12:56 +00:00
bAsientos[x][y].setSelected(false);
2024-03-11 01:43:27 +00:00
}
lSeleccionar.setText("Asientos seleccionados: " + noAsientosSeleccionados);
lTotal.setText("Total: " + total + "$");
}
public void iniciar(){
this.setBounds(100,100,700,700);
//this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}