avance 10

This commit is contained in:
xFractu 2024-03-18 13:23:30 -06:00
parent 84fc1c6189
commit 300bd747cc
4 changed files with 122 additions and 75 deletions

View File

@ -8,10 +8,11 @@ import java.awt.event.ActionListener;
class BotonConImagen extends JButton {
int cambio = 0;
int precio = 150;
private int id; // Campo id privado
private String id; // Campo id privado
private boolean isAmarillo = false; // Estado para indicar si está utilizando el color amarillo
public BotonConImagen(int id) {
public BotonConImagen(String id) {
this.id = id;
ImageIcon icono = new ImageIcon("C:/Users/mario/OneDrive/Documentos/NetBeansProjects/Imagene/src/asdasdasdasd.png");
setIcon(icono); // Establece la imagen en el botón
@ -30,23 +31,25 @@ class BotonConImagen extends JButton {
setPreferredSize(new Dimension(icono.getIconWidth(), icono.getIconHeight())); // Establece el tamaño del botón según el tamaño de la imagen
cambio = 1;
isAmarillo = true;
System.out.println("Selecciono "+id);
} else {
ImageIcon icono = new ImageIcon("C:/Users/mario/OneDrive/Documentos/NetBeansProjects/Imagene/src/asdasdasdasd.png");
setIcon(icono); // Establece la imagen en el botón
setPreferredSize(new Dimension(icono.getIconWidth(), icono.getIconHeight())); // Establece el tamaño del botón según el tamaño de la imagen
cambio = 0;
isAmarillo = false;
System.out.println("Deselecciono"+id);
}
}
});
}
// Métodos getter y setter para el campo id
public int getId() {
public String getId() {
return id;
}
public void setId(int id) {
public void setId(String id) {
this.id = id;
}

View File

@ -126,6 +126,19 @@
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="volver"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="1032" y="30" width="130" height="60"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelSeleccion">
@ -1595,8 +1608,8 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel4" max="32767" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Component id="jPanel5" alignment="0" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -1618,8 +1631,28 @@
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="horizontalScrollBarPolicy" type="int" value="31"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="asientosSelecc">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="321" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="551" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
@ -1641,33 +1674,15 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="136" max="32767" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="115" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="31" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="75" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="volver"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>

View File

@ -101,6 +101,7 @@ public class VentanaConciertos extends javax.swing.JFrame {
banda = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
fondoportada = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
panelSeleccion = new javax.swing.JPanel();
panelMapaAsientos = new javax.swing.JPanel();
panelMapaSala = new javax.swing.JPanel();
@ -161,9 +162,9 @@ public class VentanaConciertos extends javax.swing.JFrame {
LabelNums = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
asientosSelecc = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
panelFilas = new javax.swing.JPanel();
LabelA = new javax.swing.JLabel();
LabelB = new javax.swing.JLabel();
@ -190,6 +191,14 @@ public class VentanaConciertos extends javax.swing.JFrame {
barraSuperior.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 70, 300, 30));
barraSuperior.add(fondoportada, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1260, 130));
jButton1.setText("volver");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
barraSuperior.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1032, 30, 130, 60));
panelSeleccion.setBackground(new java.awt.Color(255, 255, 255));
panelMapaAsientos.setBackground(new java.awt.Color(255, 255, 255));
@ -1252,6 +1261,21 @@ public class VentanaConciertos extends javax.swing.JFrame {
jPanel1.setBackground(new java.awt.Color(204, 204, 204));
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
javax.swing.GroupLayout asientosSeleccLayout = new javax.swing.GroupLayout(asientosSelecc);
asientosSelecc.setLayout(asientosSeleccLayout);
asientosSeleccLayout.setHorizontalGroup(
asientosSeleccLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 321, Short.MAX_VALUE)
);
asientosSeleccLayout.setVerticalGroup(
asientosSeleccLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 551, Short.MAX_VALUE)
);
jScrollPane1.setViewportView(asientosSelecc);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
@ -1263,28 +1287,15 @@ public class VentanaConciertos extends javax.swing.JFrame {
.addGap(0, 0, Short.MAX_VALUE)
);
jButton1.setText("volver");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(136, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(115, 115, 115))
.addGap(0, 0, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jButton1)
.addContainerGap(31, Short.MAX_VALUE))
.addGap(0, 75, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
@ -1295,8 +1306,8 @@ public class VentanaConciertos extends javax.swing.JFrame {
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
@ -2127,6 +2138,7 @@ public class VentanaConciertos extends javax.swing.JFrame {
private javax.swing.JLabel LabelF;
private javax.swing.JLabel LabelNums;
private javax.swing.JPanel Principal;
private javax.swing.JPanel asientosSelecc;
private javax.swing.JLabel banda;
private javax.swing.JPanel barraSuperior;
private javax.swing.JLabel fondoportada;

View File

@ -22,51 +22,57 @@ public class panelAsientos extends JPanel {
private JLabel precioLabel;
public panelAsientos(String zona, String artista) {
setPreferredSize(new Dimension(737, 737));
setLayout(null); // Ajusta el diseño a null para posicionar los componentes manualmente
setLayout(new BorderLayout()); // Establecer un BorderLayout
setBackground(Color.white);
JPanel panelCentral = new JPanel(); // Crear un nuevo panel para el contenido central
panelCentral.setLayout(null); // Ajusta el diseño a null para posicionar los componentes manualmente
panelCentral.setBackground(Color.white);
String nombreTabla = artista + zona;
ImageIcon imageIcon = new ImageIcon("C:/Users/mario/OneDrive/Documentos/NetBeansProjects/Imagene/src/asdasdasdasd.png"); // Cambiar la ruta de la imagen
JLabel imagenLabel = new JLabel(imageIcon);
imagenLabel.setBounds(130, 10, imageIcon.getIconWidth(), imageIcon.getIconHeight());
add(imagenLabel);
panelCentral.add(imagenLabel);
JLabel asientoDisponibleDialogo = new JLabel("Asiento disponible");
asientoDisponibleDialogo.setBounds(210, 5, 130, 50);
add(asientoDisponibleDialogo);
panelCentral.add(asientoDisponibleDialogo);
ImageIcon imageIcon2 = new ImageIcon("C:/Users/mario/OneDrive/Documentos/NetBeansProjects/Imagene/src/asiento seleccion.png"); // Cambiar la ruta de la imagen
JLabel imagenLabel2 = new JLabel(imageIcon2);
imagenLabel2.setBounds(330, 10, imageIcon.getIconWidth(), imageIcon.getIconHeight());
add(imagenLabel2);
panelCentral.add(imagenLabel2);
JLabel asientoSeleccionadoDialogo = new JLabel("Asiento seleccionado");
asientoSeleccionadoDialogo.setBounds(410, 5, 130, 50);
add(asientoSeleccionadoDialogo);
panelCentral.add(asientoSeleccionadoDialogo);
ImageIcon imageIcon3 = new ImageIcon("C:/Users/mario/OneDrive/Documentos/NetBeansProjects/Imagene/src/asiento noDisponible.png"); // Cambiar la ruta de la imagen
JLabel imagenLabel3 = new JLabel(imageIcon3);
imagenLabel3.setBounds(545, 10, imageIcon.getIconWidth(), imageIcon.getIconHeight());
add(imagenLabel3);
panelCentral.add(imagenLabel3);
JLabel asientoNoDisponibleoDialogo = new JLabel("No Disponible");
asientoNoDisponibleoDialogo.setBounds(630, 5, 130, 50);
add(asientoNoDisponibleoDialogo);
panelCentral.add(asientoNoDisponibleoDialogo);
JLabel sala = new JLabel("" );
sala.setBounds(210, 5, 130, 50);
add(sala);
panelCentral.add(sala);
precioLabel = new JLabel("Precio total: $0");
precioLabel.setBounds(0, 70, 100, 30);
add(precioLabel);
panelCentral.add(precioLabel);
int botonesACrear = 7;
int posX = 30;
int posY = 150;
int filas = 6;
int columnas = 7;
char[] letrasFilas = {'A', 'B', 'C', 'D', 'E', 'F'};
try {
Connection connection = conexion.getInstance();
@ -79,7 +85,7 @@ public class panelAsientos extends JPanel {
if (!resultSet.next()) {
// Si la tabla no existe, crearla
PreparedStatement createStatement = connection.prepareStatement(
"CREATE TABLE " + nombreTabla + " (id INT, estado VARCHAR(255))"
"CREATE TABLE " + nombreTabla + " (id VARCHAR(255), estado VARCHAR(255))"
);
createStatement.executeUpdate();
createStatement.close();
@ -89,9 +95,6 @@ public class panelAsientos extends JPanel {
System.out.println("Error al interactuar con la base de datos: " + ex.getMessage());
}
try {
Connection connection = conexion.getInstance();
PreparedStatement checkStatement = connection.prepareStatement("SELECT COUNT(*) as count FROM "+nombreTabla);
@ -107,12 +110,12 @@ public class panelAsientos extends JPanel {
ResultSet rs = selectStatement.executeQuery();
int contador = 0; // Contador para llevar el seguimiento de los botones creados
while (rs.next()) {
int id = rs.getInt("id");
String id = rs.getString("id");
String estado = rs.getString("estado");
BotonConImagen boton = new BotonConImagen(id);
boton.setBounds(posX, posY, 70, 70);
add(boton);
panelCentral.add(boton);
// Establecer el estado del botón según los datos recuperados de la base de datos
if (estado.equals("disponible")) {
@ -134,15 +137,18 @@ public class panelAsientos extends JPanel {
selectStatement.close();
} else {
// Si no hay datos en la tabla, crear asientos nuevos
for (int fila = 0; fila < 6; fila++) {
for (int i = 0; i < botonesACrear; i++) {
DesignarId = Incremental++;
BotonConImagen boton = new BotonConImagen(DesignarId);
for (int fila = 0; fila < filas; fila++) {
for (int columna = 0; columna < columnas; columna++) {
char letraFila = letrasFilas[fila];
int numeroColumna = columna + 1;
String idAsiento = String.valueOf(letraFila) + numeroColumna;
BotonConImagen boton = new BotonConImagen(idAsiento);
boton.setBounds(posX, posY, 70, 70);
add(boton);
panelCentral.add(boton);
PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO "+nombreTabla+" (id, estado) VALUES (?, ?)");
insertStatement.setInt(1, DesignarId);
insertStatement.setString(1, idAsiento);
insertStatement.setString(2, "disponible");
insertStatement.executeUpdate();
insertStatement.close();
@ -157,9 +163,6 @@ public class panelAsientos extends JPanel {
System.out.println("Error al interactuar con la base de datos: " + ex.getMessage());
}
JButton boton2 = new JButton("Comprar");
boton2.setBounds(10, 10, 100, 30);
boton2.addActionListener(new ActionListener() {
@ -167,7 +170,7 @@ public class panelAsientos extends JPanel {
public void actionPerformed(ActionEvent e) {
int precioTotal = 0;
Connection con = conexion.getInstance();
for (Component component : getComponents()) {
for (Component component : panelCentral.getComponents()) {
if (component instanceof BotonConImagen) {
BotonConImagen boton = (BotonConImagen) component;
if (boton.isAmarillo()) {
@ -177,11 +180,11 @@ public class panelAsientos extends JPanel {
Connection connection = conexion.getInstance();
PreparedStatement statement = connection.prepareStatement("UPDATE "+nombreTabla+" SET estado = ? WHERE id = ?");
statement.setString(1, "ocupado");
statement.setInt(2, boton.getId());
statement.setString(2, boton.getId());
statement.executeUpdate();
statement.close();
System.out.println("Comprando el asiento seleccionado con el numero " + boton.getId());
System.out.println("Comprando el asiento seleccionado con el número " + boton.getId());
boton.Ocupado();
@ -195,6 +198,20 @@ public class panelAsientos extends JPanel {
precioLabel.setText("Precio total: $" + precioTotal);
}
});
add(boton2);
panelCentral.add(boton2);
// Agregar panelCentral al centro de panelAsientos
add(panelCentral, BorderLayout.CENTER);
// Crear panelSeleccionA y establecer su color
JPanel panelSeleccionA = new JPanel();
panelSeleccionA.setBackground(Color.RED);
// Agregar panelSeleccionA al este de panelAsientos
add(panelSeleccionA, BorderLayout.EAST);
}
}