mezontleTeam/out/production/Boletos Teatro/Boletos interfaz/TeatroGUI.java

115 lines
3.7 KiB
Java
Raw Normal View History

2024-03-10 03:51:57 +00:00
/*
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<String, Integer> 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<String, Integer> 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();
}
}