2024-03-11 01:43:27 +00:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
2024-03-16 01:47:59 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2024-03-20 00:57:51 +00:00
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.Statement;
|
2024-03-11 01:43:27 +00:00
|
|
|
|
2024-03-14 02:13:12 +00:00
|
|
|
public class SeleccionarAsientoV extends JPanel {
|
2024-03-11 01:43:27 +00:00
|
|
|
|
2024-03-16 01:47:59 +00:00
|
|
|
JPanel panel;
|
2024-03-11 01:43:27 +00:00
|
|
|
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);
|
|
|
|
|
2024-03-20 00:57:51 +00:00
|
|
|
private JLabel lFuncion = new JLabel("Función: XXX");
|
2024-03-11 01:43:27 +00:00
|
|
|
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-16 01:47:59 +00:00
|
|
|
List<Asiento> asientosSeleccionados = new ArrayList<Asiento>();
|
2024-03-11 03:12:56 +00:00
|
|
|
public SeleccionarAsientoV(Asiento [][] parAsientos) throws HeadlessException {
|
2024-03-11 01:43:27 +00:00
|
|
|
this.setLayout(new BorderLayout());
|
|
|
|
|
2024-03-11 03:12:56 +00:00
|
|
|
asientos = parAsientos;
|
|
|
|
|
2024-03-11 01:43:27 +00:00
|
|
|
agregarComponentes();
|
2024-03-16 01:47:59 +00:00
|
|
|
añadirListeners();
|
|
|
|
|
2024-03-11 01:43:27 +00:00
|
|
|
crearCeldas(7,10);
|
|
|
|
}
|
|
|
|
|
2024-03-20 00:57:51 +00:00
|
|
|
public SeleccionarAsientoV() throws HeadlessException {
|
|
|
|
this.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
llenarAsientos();
|
|
|
|
|
|
|
|
agregarComponentes();
|
|
|
|
añadirListeners();
|
|
|
|
|
|
|
|
crearCeldas(7,10);
|
|
|
|
}
|
|
|
|
|
2024-03-11 01:43:27 +00:00
|
|
|
public void agregarComponentes(){
|
|
|
|
pSuperior.add(this.bRegresar);
|
|
|
|
pSuperior.add(lSeleccionar);
|
2024-03-20 00:57:51 +00:00
|
|
|
pSuperior.add(this.lFuncion);
|
2024-03-11 01:43:27 +00:00
|
|
|
|
|
|
|
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-16 01:47:59 +00:00
|
|
|
tfAux.addActionListener(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);
|
|
|
|
}
|
|
|
|
|
2024-03-16 01:47:59 +00:00
|
|
|
public void añadirListeners(){
|
|
|
|
//bRegresar.addActionListener(new GestiónBotónCambiarVentana(this,new ventana2().panelV2));
|
|
|
|
}
|
|
|
|
|
2024-03-20 00:57:51 +00:00
|
|
|
public void llenarAsientos(){
|
|
|
|
asientos = new Asiento[7][10];
|
|
|
|
String zona = "";
|
|
|
|
for(int i = 0; i < 7; i++) {
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
if( ( (j >= 2) && (j <= 7) ) && ( (i >= 2) && (i <= 6) ) ){
|
|
|
|
zona = "A";
|
|
|
|
}
|
|
|
|
if( ((i == 1) && (j > 0) && (j < 9)) || ((j == 1) && (i > 0)) || ((j == 8) && (i > 0)) ){
|
|
|
|
zona = "B";
|
|
|
|
}
|
|
|
|
if( (i == 0) || (j == 0) || (j == 9)){
|
|
|
|
zona = "C";
|
|
|
|
}
|
|
|
|
asientos[i][j]=new Asiento(i,j,zona,false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-11 01:43:27 +00:00
|
|
|
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;
|
2024-03-16 01:47:59 +00:00
|
|
|
asientosSeleccionados.add(asiento);
|
2024-03-11 03:12:56 +00:00
|
|
|
} else {
|
|
|
|
noAsientosSeleccionados--;
|
|
|
|
total -= precio;
|
2024-03-16 01:47:59 +00:00
|
|
|
|
|
|
|
for(int a = 0; a < asientosSeleccionados.size() ;a++){
|
|
|
|
if(asientosSeleccionados.get(a).equals(asiento)){
|
|
|
|
asientosSeleccionados.remove(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-11 03:12:56 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2024-03-16 01:47:59 +00:00
|
|
|
System.out.print("[");
|
|
|
|
for(int a = 0; a < asientosSeleccionados.size() ;a++){
|
|
|
|
System.out.print(asientosSeleccionados.get(a).getX() + " " + asientosSeleccionados.get(a).getY() + ", " );
|
|
|
|
}
|
|
|
|
System.out.println("]");
|
|
|
|
|
2024-03-11 01:43:27 +00:00
|
|
|
lSeleccionar.setText("Asientos seleccionados: " + noAsientosSeleccionados);
|
|
|
|
lTotal.setText("Total: " + total + "$");
|
|
|
|
}
|
2024-03-20 00:57:51 +00:00
|
|
|
|
|
|
|
public void obtenerDatos(){
|
|
|
|
ConexionBD con = new ConexionBD();
|
|
|
|
Connection connection;
|
|
|
|
PreparedStatement ps;
|
|
|
|
ResultSet rs;
|
|
|
|
Statement st;
|
|
|
|
|
|
|
|
String consulta = "SELECT * FROM ASIENTOS WHERE idFkZona INNER JOIN";
|
|
|
|
}
|
2024-03-11 01:43:27 +00:00
|
|
|
}
|