From 70eaa213e38b06b59678218e8dee077763939b8e Mon Sep 17 00:00:00 2001 From: OmarVX Date: Sat, 9 Mar 2024 21:51:57 -0600 Subject: [PATCH] Interfaz Boletos --- .../Boletos interfaz/TeatroGUI.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 out/production/Boletos Teatro/Boletos interfaz/TeatroGUI.java diff --git a/out/production/Boletos Teatro/Boletos interfaz/TeatroGUI.java b/out/production/Boletos Teatro/Boletos interfaz/TeatroGUI.java new file mode 100644 index 0000000..d90a6c5 --- /dev/null +++ b/out/production/Boletos Teatro/Boletos interfaz/TeatroGUI.java @@ -0,0 +1,115 @@ +/* +Interfaz de compra de boletos aún por trabajar +El botón CONTINUAR llevaría a la interfaz de pago con tarjeta :) +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +public class TeatroGUI extends JFrame { + private JLabel titleLabel; + private JLabel priceLabel; + private JPanel ticketPanel; + private Map selectedTickets; + private JTextArea ticketListTextArea; + private JButton continuarButton; + + + private static final double VIP_ZONE = 100.0; + private static final double PREFERENCIAL_ZONE = 80.0; + private static final double STANDAR_ZONE = 60.0; + + public TeatroGUI() { + setTitle("Compra de Boletos Ticketmania"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(500, 700); + setLayout(new FlowLayout(FlowLayout.CENTER)); + + + titleLabel = new JLabel("Seleccione el tipo de boleto para las zonas:"); + add(titleLabel); + + priceLabel = new JLabel("Precios: VIP $" + VIP_ZONE + " | Preferencial $" + PREFERENCIAL_ZONE + " | Estándar $" + STANDAR_ZONE); + add(priceLabel); + + selectedTickets = new HashMap<>(); + + ticketPanel = new JPanel(new GridLayout(3, 2)); + addTicketOption("VIP "); + addTicketOption("Preferencial "); + addTicketOption("Estándar "); + add(ticketPanel); + continuarButton = new JButton("Continuar"); + + ticketListTextArea = new JTextArea(30, 30); + ticketListTextArea.setEditable(false); + add(ticketListTextArea); + add(continuarButton); + + setVisible(true); + } + + private void addTicketOption(String ticketType) { + JLabel label = new JLabel(ticketType); + ticketPanel.add(label); + + JButton plusButton = new JButton("+"); + plusButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + selectedTickets.put(ticketType, selectedTickets.getOrDefault(ticketType, 0) + 1); + updateTicketList(); + } + }); + ticketPanel.add(plusButton); + + JButton minusButton = new JButton("-"); + minusButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int currentCount = selectedTickets.getOrDefault(ticketType, 0); + if (currentCount > 0) { + selectedTickets.put(ticketType, currentCount - 1); + updateTicketList(); + } + } + }); + + + ticketPanel.add(minusButton); + } + + private void updateTicketList() { + StringBuilder sb = new StringBuilder(); + double totalPrice = 0.0; + for (Map.Entry entry : selectedTickets.entrySet()) { + String ticketType = entry.getKey(); + int quantity = entry.getValue(); + double price = 0.0; + switch (ticketType) { + case "VIP ": + price = VIP_ZONE; + break; + case "Preferencial ": + price = PREFERENCIAL_ZONE; + break; + case "Estándar ": + price = STANDAR_ZONE; + break; + } + totalPrice += price * quantity; + sb.append(ticketType).append(": ").append(quantity).append(" boletos\n"); + } + sb.append("Total: $").append(totalPrice).append("\n"); + //JTextArea ticketListTextArea = (JTextArea) getContentPane().getComponent(4); + ticketListTextArea.setText(sb.toString()); + } + + public static void main(String[] args) { + new TeatroGUI(); + } +} \ No newline at end of file