This commit is contained in:
xFractu 2024-03-06 19:25:29 -06:00
parent ae4bd19dc4
commit 9ddc09fa97
1 changed files with 100 additions and 174 deletions

View File

@ -4,182 +4,50 @@
*/
package Vista;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Polygon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
*
* @author mario
*/
class Zonas extends JPanel {
private int[] xPoints0 = {5, 150, 350, 495, 415, 370, 130, 85}; // Coordenadas X de los puntos
private int[] yPoints0 = {50, 10, 10, 50, 260, 410, 410, 260};
private int[] xPoints = {30, 150, 350, 470, 450, 350, 150, 50}; // Coordenadas X de los puntos
private int[] yPoints = {70, 30, 30, 70, 120, 80, 80, 120}; // Coordenadas Y de los puntos
private int[] xPoints2 = {50, 150, 350, 450, 430, 350, 150, 70}; // Coordenadas X de los puntos
private int[] yPoints2 = {125, 85, 85, 125, 170, 130, 130, 170};
private int[] xPoints3 = {70, 150, 350, 430, 400, 350, 350, 150, 150, 100}; // Coordenadas X de los puntos
private int[] yPoints3 = {177, 137, 137, 177, 252, 232, 177, 177, 232, 252};
private int[] xPoints4 = {100, 180, 190, 310, 320, 400, 350, 300, 200, 150}; // Coordenadas X de los puntos
private int[] yPoints4 = {259, 228, 289, 289, 228, 259, 400, 384, 384, 400};
private int[] xPoints5 = {100, 400, 350, 150}; // Coordenadas X de los puntos
private int[] yPoints5 = {420, 420, 480, 480};
private Color fondo = new Color(246, 246, 246);
private Color silverColor = new Color(192, 192, 192); // Plata
private Color goldColor = new Color(255, 215, 0); // Oro
private Color platinumColor = new Color(229, 228, 226); // Platino
private Color diamondColor = new Color(224, 116, 186); // Diamante
private Color currentColor; // Color actual del polígono
public Zonas() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int mouseX = e.getX();
int mouseY = e.getY();
if (isPointInsidePolygon(mouseX, mouseY, xPoints, yPoints)) {
JOptionPane.showMessageDialog(null, "Zona Plata");
} else if (isPointInsidePolygon(mouseX, mouseY, xPoints2, yPoints2)) {
JOptionPane.showMessageDialog(null, "Zona Oro");
} else if (isPointInsidePolygon(mouseX, mouseY, xPoints3, yPoints3)) {
JOptionPane.showMessageDialog(null, "Zona Platino");
} else if (isPointInsidePolygon(mouseX, mouseY, xPoints4, yPoints4)) {
JOptionPane.showMessageDialog(null, "Zona Diamante");
}
}
@Override
public void mouseEntered(MouseEvent e) {
Object source = e.getSource();
if (source instanceof Component) {
Component component = (Component) source;
component.setForeground(component.getForeground().darker());
repaint();
}
}
@Override
public void mouseExited(MouseEvent e) {
Object source = e.getSource();
if (source instanceof Component) {
Component component = (Component) source;
component.setForeground(currentColor);
repaint();
}
}
});
}
private boolean isPointInsidePolygon(int x, int y, int[] xPoints, int[] yPoints) {
Polygon polygon = new Polygon(xPoints, yPoints, xPoints.length);
return polygon.contains(x, y);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Dibujar el cuarto polígono (Diamante)
g.setColor(fondo);
g.fillPolygon(xPoints0, yPoints0, xPoints0.length);
g.setColor(Color.black);
g.drawPolygon(xPoints0, yPoints0, xPoints0.length);
// Dibujar el primer polígono (Plata)
currentColor = silverColor;
g.setColor(currentColor);
g.fillPolygon(xPoints, yPoints, xPoints.length);
g.setColor(Color.black);
g.drawPolygon(xPoints, yPoints, xPoints.length);
// Dibujar el segundo polígono (Oro)
currentColor = goldColor;
g.setColor(currentColor);
g.fillPolygon(xPoints2, yPoints2, xPoints2.length);
g.setColor(Color.black);
g.drawPolygon(xPoints2, yPoints2, xPoints2.length);
// Dibujar el tercer polígono (Platino)
currentColor = platinumColor;
g.setColor(currentColor);
g.fillPolygon(xPoints3, yPoints3, xPoints3.length);
g.setColor(Color.black);
g.drawPolygon(xPoints3, yPoints3, xPoints3.length);
// Dibujar el cuarto polígono (Diamante)
currentColor = diamondColor;
g.setColor(currentColor);
g.fillPolygon(xPoints4, yPoints4, xPoints4.length);
g.setColor(Color.black);
g.drawPolygon(xPoints4, yPoints4, xPoints4.length);
// Dibujar el cuarto polígono (Diamante)
currentColor = silverColor;
g.setColor(currentColor);
g.fillPolygon(xPoints5, yPoints5, xPoints5.length);
g.setColor(Color.black);
g.drawPolygon(xPoints5, yPoints5, xPoints5.length);
}
}
public class VentanaConcierto extends JFrame {
private JPanel panelLienzoAccesorios,panelLienzoCara,panelLienzoRopaS, panelLienzoRopaI;
class VentanaConcierto extends JFrame {
private JPanel panelLienzoAccesorios, panelLienzoCara, panelLienzoRopaS, panelLienzoRopaI;
private Zonas zonasPanel;
private ZonaPlata zonaPlata;
private ZonaOro zonaOro;
private ZonaPlatino zonaPlatino;
private ZonaDiamante zonaDiamante;
private JPanel panelCentral; // Nuevo panel para contener zonasPanel y zonaPlata
public VentanaConcierto() {
configurarVentana();
}
private void configurarVentana() {
setTitle("AvatART");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(810, 650);
setSize(770, 650);
setLocationRelativeTo(null);
getContentPane().setBackground(new Color(200, 160, 255)); // Lila
JPanel panelLienzo = new JPanel();
panelLienzo.setLayout(new GridLayout(4, 1)); // 4 filas, 1 columna
panelLienzo.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// Configurar el panel de Zonas
zonasPanel = new Zonas();
zonaPlata = new ZonaPlata();
zonaOro = new ZonaOro();
zonaPlatino = new ZonaPlatino();
zonaDiamante = new ZonaDiamante();
zonaPlata.setPreferredSize(new Dimension(2000, zonaPlata.getPreferredSize().height));
zonaOro.setPreferredSize(new Dimension(2000, zonaOro.getPreferredSize().height));
zonaPlatino.setPreferredSize(new Dimension(1140, zonaPlatino.getPreferredSize().height));
zonaDiamante.setPreferredSize(new Dimension(960, zonaDiamante.getPreferredSize().height));
JPanel panelLienzoContenedor = new JPanel(new BorderLayout());
panelLienzoContenedor.add(panelLienzo, BorderLayout.CENTER);
panelLienzoContenedor.setBackground(new Color(200, 160, 255)); // Lila
panelLienzoContenedor.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // Añade un espacio alrededor
panelCentral = new JPanel(new BorderLayout()); // Panel central que contendrá zonasPanel y zonaPlata
panelCentral.add(zonasPanel, BorderLayout.CENTER); // Agregar zonasPanel inicialmente
JScrollPane scrollPane = new JScrollPane(panelCentral); // Usar JScrollPane con panelCentral
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
// Ajustar la velocidad del desplazamiento
scrollPane.getHorizontalScrollBar().setUnitIncrement(50); // Ajusta el desplazamiento horizontal más rápido
scrollPane.getVerticalScrollBar().setUnitIncrement(50); // Ajusta el desplazamiento vertical más rápido
add(scrollPane, BorderLayout.CENTER); // Agregar JScrollPane en lugar de zonasPanel directamente
JPanel panelComboBox = new JPanel();
panelComboBox.setLayout(new GridLayout(8, 1, 0, 20)); // Espacio vertical entre componentes
@ -195,13 +63,20 @@ public class VentanaConcierto extends JFrame {
JLabel label4 = new JLabel("Elige tu ropa inferior");
label4.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
panelLienzoContenedor.add(new Zonas());
panelComboBox.add(label1);
panelComboBox.add(label2);
panelComboBox.add(label3);
panelComboBox.add(label4);
// Crear un botón para volver al estado inicial
JButton btnVolver = new JButton("Volver");
btnVolver.addActionListener(e -> {
cambiarPanelCentral(zonasPanel); // Volver al estado inicial cuando se hace clic en el botón
});
panelComboBox.add(btnVolver); // Agregar el botón al panelComboBox
// Panel para el título "AvatArt"
JPanel panelTitulo = new JPanel();
@ -211,18 +86,69 @@ public class VentanaConcierto extends JFrame {
panelTitulo.setBackground(new Color(200, 160, 255));
add(panelTitulo, BorderLayout.NORTH);
add(panelComboBox, BorderLayout.WEST);
add(panelLienzoContenedor, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String[] args) {
VentanaConcierto vista = new VentanaConcierto();
// Agregar Mouse Listeners
agregarMouseListeners();
}
}
private void agregarMouseListeners() {
zonasPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int mouseX = e.getX();
int mouseY = e.getY();
if (zonasPanel.isPointInsidePolygon(mouseX, mouseY, zonasPanel.getXPoints(), zonasPanel.getYPoints())) {
JOptionPane.showMessageDialog(null, "Zona Plata");
cambiarPanelCentral(zonaPlata); // Cambiar a zonaPlata cuando se hace clic en la zona
} else if (zonasPanel.isPointInsidePolygon(mouseX, mouseY, zonasPanel.getXPoints2(), zonasPanel.getYPoints2())) {
JOptionPane.showMessageDialog(null, "Zona Oro");
cambiarPanelCentral(zonaOro); // Cambiar a zonaOro cuando se hace clic en la zona
} else if (zonasPanel.isPointInsidePolygon(mouseX, mouseY, zonasPanel.getXPoints3(), zonasPanel.getYPoints3())) {
JOptionPane.showMessageDialog(null, "Zona Platino");
cambiarPanelCentral(zonaPlatino); // Cambiar a zonaPlatino cuando se hace clic en la zona
} else if (zonasPanel.isPointInsidePolygon(mouseX, mouseY, zonasPanel.getXPoints4(), zonasPanel.getYPoints4())) {
JOptionPane.showMessageDialog(null, "Zona Diamante");
cambiarPanelCentral(zonaDiamante); // Cambiar a zonaDiamante cuando se hace clic en la zona
}
}
@Override
public void mouseEntered(MouseEvent e) {
Object source = e.getSource();
if (source instanceof Component) {
Component component = (Component) source;
component.setForeground(component.getForeground().darker());
zonasPanel.repaint();
}
}
@Override
public void mouseExited(MouseEvent e) {
Object source = e.getSource();
if (source instanceof Component) {
Component component = (Component) source;
component.setForeground(zonasPanel.getCurrentColor());
zonasPanel.repaint();
}
}
});
}
// Método para cambiar el contenido del panel central
private void cambiarPanelCentral(Component nuevoContenido) {
panelCentral.removeAll(); // Limpiar el panel central
panelCentral.add(nuevoContenido, BorderLayout.CENTER); // Agregar el nuevo contenido
panelCentral.revalidate(); // Revalidar el panel para reflejar los cambios
panelCentral.repaint(); // Repintar el panel
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
VentanaConcierto vista = new VentanaConcierto();
});
}
}