Generación de asientos con info de la base de datos

This commit is contained in:
victor.monge 2025-03-08 21:16:54 -06:00
parent 7f3c76ea18
commit fe48c1944f
11 changed files with 444 additions and 145 deletions

View File

@ -3,6 +3,8 @@ package controller;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
@ -15,27 +17,44 @@ import model.ModeloSQL;
import view.Menu;
import view.MenuSala;
public class MenuController extends WindowAdapter implements ActionListener {
public class MenuController extends WindowAdapter implements ActionListener, ItemListener {
private Menu menu;
private MenuSala menuSala;
private ModeloSQL modeloSQL;
private String seleccionEventoComboBox;
private ArrayList<Evento> arrayListEventos;
public MenuController(Menu menu){
this.menu = menu;
this.modeloSQL = new ModeloSQL();
arrayListEventos = new ArrayList<>();
obtenerEventosDefaultComboBoxMoldel();
}
@Override
public void actionPerformed(ActionEvent e){
Object o = e.getSource();
// Si se presiona el boton de visualizar
if(o.equals(menu.jButtonVisualizar)){
System.out.println("controller.MenuController.actionPerformed(): jButtonVisualizar");
MenuSala menuSala = new MenuSala();
menu.jPanelMenuSala.removeAll(); // Limpiar panel
menu.jPanelMenuSala.add(menuSala, BorderLayout.CENTER); // Agrega el nuevo JPanel
menu.jPanelMenuSala.revalidate(); // Reorganiza los componentes
menu. jPanelMenuSala.repaint(); // Redibuja la interfaz
// Si se ha seleccionado un evento del comboBox
if(seleccionEventoComboBox != null && seleccionEventoComboBox != "Seleccione un evento"){
System.out.println("controller.MenuController.actionPerformed(): visualizar evento de " + seleccionEventoComboBox);
menuSala = new MenuSala(obtenerIdEventoSeleccionado(seleccionEventoComboBox), seleccionEventoComboBox);
menu.jPanelMenuSala.removeAll(); // Limpiar panel
menu.jPanelMenuSala.add(menuSala, BorderLayout.CENTER); // Agrega el nuevo JPanel
menu.jPanelMenuSala.revalidate(); // Reorganiza los componentes
menu. jPanelMenuSala.repaint(); // Redibuja la interfaz
} else {
menu.mensaje("Debe seleccionar un evento.");
}
}
}
public void itemStateChanged(ItemEvent e) {
// Obtener evento musical seleccionado del ComboBox
if (e.getStateChange() == ItemEvent.SELECTED) {
seleccionEventoComboBox = (String) menu.jComboBoxEventos.getSelectedItem();
System.out.println("controller.MenuController.itemStateChanged: seleccionó " + seleccionEventoComboBox);
}
}
@ -48,13 +67,26 @@ public class MenuController extends WindowAdapter implements ActionListener {
// Obtener ResultSet de ModeloSQL y añádir eventos al ComboBoxModel del ComboBox de eventos
public void obtenerEventosDefaultComboBoxMoldel(){
ResultSet rs = modeloSQL.obtenerEventos();
menu.defaultComboBoxModel.addElement("Seleccione un evento");
try {
while ( rs.next() ){
arrayListEventos.add(new Evento(rs.getInt("idEvento"), rs.getString("nombre"), rs.getDate("fecha")));
menu.defaultComboBoxModel.addElement(rs.getString("nombre"));
System.out.println("MenuController.obtenerEventosDefaultComboBoxMoldel(): + " + rs.getString("nombre"));
}
} catch (SQLException ex) {
System.out.println("MenuController.obtenerEventosDefaultComboBoxMoldel(): error " + ex);;
System.out.println("MenuController.obtenerEventosDefaultComboBoxMoldel(): error " + ex);
}
}
public int obtenerIdEventoSeleccionado(String nombreEvento){
int idEvento = 0;
for(Evento evento: arrayListEventos){
if(evento.getNombre().equals(nombreEvento)){
idEvento = evento.getIdEvento();
System.out.println("MenuController.obtenerIdEventoSeleccionado: " + nombreEvento + " id: " + idEvento );
}
}
return idEvento;
}
}

View File

@ -0,0 +1,175 @@
package controller;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JToggleButton;
import javax.swing.SwingUtilities;
import model.Asiento;
import view.MenuSala;
import model.ModeloSQL;
public class MenuSalaController implements ActionListener, ItemListener{
private int idEvento;
private MenuSala menuSala;
private ModeloSQL modeloSQL = new ModeloSQL();
private ArrayList<JToggleButton> arrayListAsientosSeleccionados;
//private int filas = 6;
private int columnas = 7;
private int largoBoton = 140;
private int anchoBoton = 60;
boolean clickAsientosHabilitado = false;// Variable bandera para permitir o no la selección de asientos
public MenuSalaController(MenuSala menuSala) {
this.menuSala = menuSala;
this.modeloSQL = new ModeloSQL();
this.idEvento = menuSala.getIdEvento();
obtenerAsientos(idEvento);// Obtener información del evento seleccionado desde la BD y añadir botones
arrayListAsientosSeleccionados = new ArrayList<>();
}
public void obtenerAsientos(int idEvento){
arrayListAsientosSeleccionados = null;
arrayListAsientosSeleccionados = new ArrayList<>();
int ejeX = 20;
int ejeY = 20;
ResultSet rs = modeloSQL.obtenerAsientosDisponibles(idEvento);
int numeroAsiento = 0;
try {
while ( rs.next() ){
int idAsiento = rs.getInt("idAsiento");
String fila = rs.getString("fila");
int numero = rs.getInt("numero");
String estado = rs.getString("estado");
Asiento asiento = new Asiento(idEvento, fila, numero);// Crear objeto asiento
JToggleButton botonAsiento = new JToggleButton(fila + ""+ numero + " ("+estado+")");// Crear botón
botonAsiento.setBounds(ejeX, ejeY, largoBoton, anchoBoton);// Establecer posición del botón
// Guadar información dentro del botón
botonAsiento.putClientProperty("asiento", asiento);
botonAsiento.putClientProperty("idAsiento", idAsiento);
botonAsiento.putClientProperty("estado", estado);
// Si el el asiento está vendido pintarlo de color rojo
if(estado.equals("vendido")){
//botonAsiento.setEnabled(false);
botonAsiento.setBackground(Color.RED);
botonAsiento.setForeground(Color.WHITE);
} else {// Si el asiento no está vendido pintarlo de color verde
botonAsiento.setBackground(Color.GREEN);
}
botonAsiento.addItemListener(this);
menuSala.jPanelBotones.add(botonAsiento);// Añadir botón al JPanel de MenuSala
ejeX += 160;// Actualizar posición vertical del siguiente botón
numeroAsiento++;
// Si da igual a 0, significa que el siguiente botón debe ir en la siguiente fila
if (numeroAsiento % columnas == 0) {
ejeY += 70;// Ajustar posición horizontal para la siguiente fila
ejeX = 20;// Ajustar posición vertical ya que es una nueva fila
}
}
} catch (SQLException ex) {
System.out.println("[X] controller.MenuSalaController.obtenerAsientos(): error " + ex);
}
}
@Override
public void actionPerformed(ActionEvent e){
Object o = e.getSource();
// Si se presiono el boton para seleccionar asientos para una venta
if(o.equals(menuSala.jButtonSeleccionarAsientosVenta)){
if (!clickAsientosHabilitado){// Si la selección de asientos está bloqueada
clickAsientosHabilitado = true;// Permitir la selección de asientos
menuSala.jButtonRealizarVenta.setEnabled(true);
menuSala.jPanelBotones.setBackground(Color.decode("#d7f1ce"));
menuSala.jButtonSeleccionarAsientosVenta.setBackground(Color.YELLOW);
} else {
menuSala.jPanelBotones.removeAll();
menuSala.revalidate();
menuSala.repaint();
obtenerAsientos(idEvento);
clickAsientosHabilitado = false;
menuSala.jButtonRealizarVenta.setEnabled(false);
menuSala.jPanelBotones.setBackground(Color.decode("#F6F6F6"));
menuSala.jButtonSeleccionarAsientosVenta.setBackground(Color.WHITE);
}
}
// Si se presiono el botón realizar venta
if(o.equals(menuSala.jButtonRealizarVenta)){
// Verificar que se seleccionó por lo menos un asiento
if (!arrayListAsientosSeleccionados.isEmpty()) {
} else {
menuSala.mensaje("No ha seleccionado ningún asiento.");
}
}
}
@Override
public void itemStateChanged(ItemEvent e){
Object componente = e.getSource();
if (componente instanceof JToggleButton) {// Si el evento es un botón de asiento
JToggleButton botonAsiento = (JToggleButton) componente;// Obtener botón
String estado = (String) botonAsiento.getClientProperty("estado");// Obtener estado del asiento
// Si no está habilitada la modificación de asientos (o si el botón está vendo), revertir el cambio de estado
if (!clickAsientosHabilitado || estado.equals("vendido")) {
botonAsiento.removeItemListener(this);// Remover temporalmente el listener para evitar ciclos infinitos
botonAsiento.setSelected(!botonAsiento.isSelected());// Revertir el cambio de estado
botonAsiento.addItemListener(this);// Volver a agregar el listener
return;
}
Asiento asiento = (Asiento) botonAsiento.getClientProperty("asiento");// Obtener el objeto asiento que estaba dentro del botón
int idAsiento = (int) botonAsiento.getClientProperty("idAsiento");
// Si el botón se ha seleccionado
if (e.getStateChange() == ItemEvent.SELECTED) {
arrayListAsientosSeleccionados.add(botonAsiento);
System.out.println("controller.MenuSalaController.itemStateChanged(): " + asiento.getFila() + "" + asiento.getNumero() + " añadido a arrayListAsientosSeleccionados");
System.out.println("controller.MenuSalaController.itemStateChanged(): " + asiento.getFila() + asiento.getNumero() + " seleccionado.");
botonAsiento.setBackground(Color.YELLOW);
botonAsiento.setForeground(Color.WHITE);
} else if (e.getStateChange() == ItemEvent.DESELECTED) {// Si el botón se ha deseleccionado
if(arrayListAsientosSeleccionados.contains(botonAsiento)){
arrayListAsientosSeleccionados.remove(botonAsiento);
System.out.println("controller.MenuSalaController.itemStateChanged(): " + asiento.getFila() + "" + asiento.getNumero() + " eliminado de arrayListAsientosSeleccionados");
}
System.out.println("controller.MenuSalaController.itemStateChanged(): " + asiento.getFila() + asiento.getNumero() + " deseleccionado.");
botonAsiento.setBackground(Color.GREEN);
botonAsiento.setForeground(Color.BLACK);
}
}
}
public void realizarVenta(ArrayList<JToggleButton> arrayBotones){
ArrayList<Asiento> arrayAsientos = new ArrayList<>();
for(JToggleButton boton: arrayBotones){
Asiento asiento = (Asiento) boton.getClientProperty("asiento");
arrayAsientos.add(asiento);
}
}
}

View File

@ -1,14 +1,16 @@
package model;
public class Asiento {
private String idEvento;
private int idAsiento;
private String fila;
private int numero;
public void setIdEvento(String idEvento) {
this.idEvento = idEvento;
}
public Asiento(int idAsiento, String fila, int numero) {
this.idAsiento = idAsiento;
this.fila = fila;
this.numero = numero;
}
public void setFila(String fila) {
this.fila = fila;
}
@ -17,10 +19,6 @@ public class Asiento {
this.numero = numero;
}
public String getIdEvento() {
return idEvento;
}
public String getFila() {
return fila;
}

View File

@ -8,17 +8,13 @@ public class Boleto {
private int idAsiento;
private double precio;
private String estado;
private LocalDateTime fechaVenta;
private Integer idVenta;
public Boleto(int idBoleto, int idEvento, int idAsiento, double precio, String estado, LocalDateTime fechaVenta, Integer idVenta) {
this.idBoleto = idBoleto;
public Boleto(int idEvento, int idAsiento, double precio) {
this.idEvento = idEvento;
this.idAsiento = idAsiento;
this.precio = precio;
this.estado = estado;
this.fechaVenta = fechaVenta;
this.idVenta = idVenta;
this.estado = "vendido";
}
public void setIdBoleto(int idBoleto) {
@ -41,10 +37,6 @@ public class Boleto {
this.estado = estado;
}
public void setFechaVenta(LocalDateTime fechaVenta) {
this.fechaVenta = fechaVenta;
}
public void setIdVenta(Integer idVenta) {
this.idVenta = idVenta;
}
@ -69,13 +61,7 @@ public class Boleto {
return estado;
}
public LocalDateTime getFechaVenta() {
return fechaVenta;
}
public Integer getIdVenta() {
return idVenta;
}
// Método para cambiar estado venderBoleto() que establezca estado, fechaVenta e idVenta.
}

View File

@ -1,11 +1,17 @@
package model;
import java.time.LocalDate;
import java.sql.Date;
public class Evento {
private int idEvento;
private String nombre;
private LocalDate fecha;
private Date fecha;
public Evento(int idEvento, String nombre, Date fecha){
this.idEvento = idEvento;
this.nombre = nombre;
this.fecha = fecha;
}
public void setIdEvento(int idEvento) {
this.idEvento = idEvento;
@ -15,7 +21,7 @@ public class Evento {
this.nombre = nombre;
}
public void setFecha(LocalDate fecha) {
public void setFecha(Date fecha) {
this.fecha = fecha;
}
@ -27,7 +33,7 @@ public class Evento {
return nombre;
}
public LocalDate getFecha() {
public Date getFecha() {
return fecha;
}

View File

@ -14,9 +14,9 @@ public class ModeloSQL {
// Eventos
public ResultSet obtenerEventos(){
ResultSet rs = null;
String consulta = "SELECT * FROM eventos";
try {
Statement st = con.createStatement();
String consulta = "SELECT * FROM eventos";
rs = st.executeQuery(consulta);
System.out.println("ModeloSQL.obtenerEventos(): eventos obtenidos.");
} catch (SQLException e) {
@ -25,7 +25,55 @@ public class ModeloSQL {
return rs;
}
// Asientos
public ResultSet obtenerAsientosDisponibles(int idEvento){
ResultSet rs = null;
String consulta = "SELECT a.idAsiento, a.fila, a.numero, IFNULL(b.estado, 'disponible') AS estado " +
"FROM asientos a " +
"LEFT JOIN boletos b ON a.idAsiento = b.idAsiento AND b.idEvento = "+idEvento+"";
try {
Statement st = con.createStatement();
rs = st.executeQuery(consulta);
System.out.println("ModeloSQL.obtenerAsientosDisponibles: asientos obtenidos.");
} catch (SQLException e) {
}
return rs;
}
// Venta
public void registrarVenta(int idEvento, int totalBoletos, Double totalMonto){
String sql = "INSERT INTO ventas (idEvento, fechaVenta, totalBoletos, totalMonto) VALUES (?, NOW(), ?, ?)";
PreparedStatement pst = null;
try {
pst = con.prepareStatement(sql);
pst.setInt(1, idEvento);
pst.setInt(2, totalBoletos);
pst.setDouble(3, totalMonto);
pst.executeUpdate();
pst.close();
System.out.println("model.ModeloSQL.crearVenta(): venta registrada.");
} catch (SQLException ex) {
System.out.println("[X] model.ModeloSQL.crearVenta(): " + ex);
}
}
// Boleto
public void registrarBoleto(int idEvento, int idAsiento, double precio, int idVenta){
String sql = "INSERT INTO boletos (idEvento, idAsiento, precio, idVenta) VALUES (?, ?, ?, ?)";
PreparedStatement pst = null;
try {
pst = con.prepareStatement(sql);
pst.setInt(1, idEvento);
pst.setInt(2, idAsiento);
pst.setDouble(3, precio);
pst.setInt(4, idVenta);
pst.executeUpdate();
pst.close();
System.out.println("model.ModeloSQL.registrarBoleto(): boleto registrado.");
} catch (SQLException ex) {
System.out.println("[X] model.ModeloSQL.registrarBoleto(): " + ex);
}
}
public ResultSet obtenerBoletosPorEvento(int idEvento){
ResultSet rs = null;

View File

@ -1,14 +1,17 @@
package model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JToggleButton;
public class Venta {
private int idVenta;
private int idEvento;
private LocalDateTime fechaVenta;
private String vendedor;
private List<Boleto> boletos;
private int totalBoletos;
private int totalMonto;
private ArrayList<JToggleButton> asientosVenta;
public void setIdVenta(int idVenta) {
this.idVenta = idVenta;
@ -22,14 +25,18 @@ public class Venta {
this.fechaVenta = fechaVenta;
}
public void setBoletos(List<Boleto> boletos) {
this.boletos = boletos;
public void setTotalBoletos(int totalBoletos) {
this.totalBoletos = totalBoletos;
}
public void setVendedor(String vendedor) {
this.vendedor = vendedor;
public void setTotalMonto(int totalMonto) {
this.totalMonto = totalMonto;
}
public void setAsientosVenta(ArrayList<JToggleButton> asientosVenta) {
this.asientosVenta = asientosVenta;
}
public int getIdVenta() {
return idVenta;
}
@ -42,14 +49,16 @@ public class Venta {
return fechaVenta;
}
public String getVendedor() {
return vendedor;
public int getTotalBoletos() {
return totalBoletos;
}
public List<Boleto> getBoletos() {
return boletos;
public int getTotalMonto() {
return totalMonto;
}
public ArrayList<JToggleButton> getAsientosVenta() {
return asientosVenta;
}
// métodos para agregar boletos, calcular total, etc.
}

View File

@ -10,6 +10,10 @@
<Property name="location" type="java.awt.Point" editor="org.netbeans.beaninfo.editors.PointEditor">
<Point value="[0, 0]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[1180, 650]"/>
</Property>
<Property name="resizable" type="boolean" value="false"/>
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 0]"/>
</Property>
@ -35,31 +39,28 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanelMenuSala" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComboBoxEventos" min="-2" pref="170" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonVisualizar" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="316" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="jPanelMenuSala" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="349" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComboBoxEventos" min="-2" pref="170" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonVisualizar" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jComboBoxEventos" alignment="3" max="32767" attributes="0"/>
<Component id="jButtonVisualizar" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabel1" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jComboBoxEventos" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonVisualizar" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanelMenuSala" max="32767" attributes="0"/>
@ -71,9 +72,6 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Gill Sans MT" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Seleccione un evento:"/>
</Properties>
</Component>
@ -97,11 +95,6 @@
</AuxValues>
</Component>
<Container class="javax.swing.JPanel" name="jPanelMenuSala">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="fd" green="fa" red="f8" type="rgb"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
@ -109,7 +102,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<EmptySpace min="0" pref="1168" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">

View File

@ -3,6 +3,7 @@ package view;
import java.awt.BorderLayout;
import controller.MenuController;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
public class Menu extends javax.swing.JFrame {
@ -17,9 +18,14 @@ public class Menu extends javax.swing.JFrame {
MenuController menuController = new MenuController(this);
this.jButtonVisualizar.addActionListener(menuController);
this.jComboBoxEventos.addItemListener(menuController);
addWindowListener(menuController);
}
public void mensaje(String mensaje){
JOptionPane.showMessageDialog(this, mensaje);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
@ -33,22 +39,21 @@ public class Menu extends javax.swing.JFrame {
setTitle("Aplicación de venta de boletos");
setBackground(new java.awt.Color(255, 255, 255));
setLocation(new java.awt.Point(0, 0));
setPreferredSize(new java.awt.Dimension(1180, 650));
setResizable(false);
setSize(new java.awt.Dimension(0, 0));
jLabel1.setFont(new java.awt.Font("Gill Sans MT", 0, 14)); // NOI18N
jLabel1.setText("Seleccione un evento:");
jComboBoxEventos.setModel(defaultComboBoxModel);
jButtonVisualizar.setText("Visualizar");
jPanelMenuSala.setBackground(new java.awt.Color(248, 250, 253));
javax.swing.GroupLayout jPanelMenuSalaLayout = new javax.swing.GroupLayout(jPanelMenuSala);
jPanelMenuSala.setLayout(jPanelMenuSalaLayout);
jPanelMenuSalaLayout.setHorizontalGroup(
jPanelMenuSalaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
.addGap(0, 1168, Short.MAX_VALUE)
);
jPanelMenuSalaLayout.setVerticalGroup(
jPanelMenuSalaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -61,25 +66,24 @@ public class Menu extends javax.swing.JFrame {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelMenuSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBoxEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonVisualizar)
.addGap(0, 316, Short.MAX_VALUE)))
.addComponent(jPanelMenuSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(349, 349, 349)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBoxEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonVisualizar)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBoxEventos)
.addComponent(jButtonVisualizar))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBoxEventos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonVisualizar)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanelMenuSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@ -88,7 +92,8 @@ public class Menu extends javax.swing.JFrame {
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JButton jButtonVisualizar;
public javax.swing.JComboBox<String> jComboBoxEventos;

View File

@ -39,11 +39,9 @@
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanelBotones">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
@ -60,9 +58,6 @@
</Container>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="fd" green="fa" red="f8" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
@ -71,19 +66,27 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="585" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jButtonSeleccionarAsientosVenta" alignment="0" max="32767" attributes="0"/>
<Component id="jButtonRealizarVenta" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="444" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="20" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="64" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonSeleccionarAsientosVenta" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonRealizarVenta" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="12" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -91,9 +94,28 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;Concierto: &quot; + nombre" type="code"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonSeleccionarAsientosVenta">
<Properties>
<Property name="text" type="java.lang.String" value="Seleccionar asientos para venta"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="jButtonRealizarVenta">
<Properties>
<Property name="text" type="java.lang.String" value="Realizar venta"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

@ -1,42 +1,50 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template
*/
package view;
import controller.MenuSalaController;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import model.Boleto;
/**
*
* @author vmonge
*/
public class MenuSala extends javax.swing.JPanel {
/**
* Creates new form MenuSala
*/
public MenuSala() {
private int idEvento;
private String nombre;
public MenuSala(int idEvento, String nombre) {
this.idEvento = idEvento;
this.nombre = nombre;
initComponents();
asientos();
//asientos();
MenuSalaController menuSalaController = new MenuSalaController(this);
jButtonSeleccionarAsientosVenta.addActionListener(menuSalaController);
jButtonRealizarVenta.addActionListener(menuSalaController);
}
private int filas = 5;
private int columnas = 5;
/*
private int filas = 6;
private int columnas = 7;
private int largoBoton = 140;
private int anchoBoton = 60;
private int ejeX = 20;
private int ejeY = 20;
public JToggleButton jtBotones[][];
int numeroAsientos = 0;
private ArrayList<Boleto> boletosVendidos = new ArrayList<>();
int contadorNumeroAsientos = 0;
*/
/*
public void asientos(){
jtBotones = new JToggleButton[filas][columnas];
for(int i = 0; i < filas; i++){
for(int j = 0; j < columnas; j++){
jtBotones[i][j] = new JToggleButton();
numeroAsientos++;
contadorNumeroAsientos++;
jtBotones[i][j].setBounds(ejeX, ejeY, largoBoton, anchoBoton);
jtBotones[i][j].setText("Asiento: " + numeroAsientos);
jtBotones[i][j].setText("Asiento: " + contadorNumeroAsientos);
jPanelBotones.add(jtBotones[i][j]);
ejeX += 160;
@ -48,12 +56,16 @@ public class MenuSala extends javax.swing.JPanel {
ejeX = 20;
}
}
*/
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
public int getIdEvento() {
return idEvento;
}
public void mensaje(String mensaje){
JOptionPane.showMessageDialog(this, mensaje);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
@ -61,8 +73,8 @@ public class MenuSala extends javax.swing.JPanel {
jPanelBotones = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanelBotones.setBackground(new java.awt.Color(255, 255, 255));
jButtonSeleccionarAsientosVenta = new javax.swing.JButton();
jButtonRealizarVenta = new javax.swing.JButton();
javax.swing.GroupLayout jPanelBotonesLayout = new javax.swing.GroupLayout(jPanelBotones);
jPanelBotones.setLayout(jPanelBotonesLayout);
@ -75,26 +87,37 @@ public class MenuSala extends javax.swing.JPanel {
.addGap(0, 448, Short.MAX_VALUE)
);
jPanel2.setBackground(new java.awt.Color(248, 250, 253));
jPanel2.setForeground(new java.awt.Color(0, 0, 0));
jLabel1.setText("jLabel1");
jLabel1.setText("Concierto: " + nombre);
jButtonSeleccionarAsientosVenta.setText("Seleccionar asientos para venta");
jButtonRealizarVenta.setText("Realizar venta");
jButtonRealizarVenta.setEnabled(false);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLabel1)
.addContainerGap(585, Short.MAX_VALUE))
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1)
.addComponent(jButtonSeleccionarAsientosVenta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonRealizarVenta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(444, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(64, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonSeleccionarAsientosVenta)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonRealizarVenta)
.addContainerGap(12, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
@ -120,8 +143,10 @@ public class MenuSala extends javax.swing.JPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JButton jButtonRealizarVenta;
public javax.swing.JButton jButtonSeleccionarAsientosVenta;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanelBotones;
public javax.swing.JPanel jPanelBotones;
// End of variables declaration//GEN-END:variables
}