153 lines
6.3 KiB
Java
153 lines
6.3 KiB
Java
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.*;
|
||
|
|
||
|
public class Ventana extends JFrame {
|
||
|
private JPanel panelLienzoAccesorios,panelLienzoCara,panelLienzoRopaS, panelLienzoRopaI;
|
||
|
private DibujoAvatar modelo;
|
||
|
|
||
|
public Ventana(DibujoAvatar modelo) {
|
||
|
this.modelo = modelo;
|
||
|
|
||
|
configurarVentana();
|
||
|
}
|
||
|
|
||
|
public Ventana() {
|
||
|
configurarVentana();
|
||
|
}
|
||
|
|
||
|
private void configurarVentana() {
|
||
|
setTitle("AvatART");
|
||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
setSize(1000, 800);
|
||
|
setLocationRelativeTo(null);
|
||
|
|
||
|
getContentPane().setBackground(new Color(200, 160, 255)); // Lila
|
||
|
|
||
|
panelLienzoAccesorios = new JPanel();
|
||
|
panelLienzoCara = new JPanel();
|
||
|
panelLienzoRopaS = new JPanel();
|
||
|
panelLienzoRopaI = new JPanel();
|
||
|
|
||
|
panelLienzoAccesorios.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||
|
panelLienzoCara.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||
|
panelLienzoRopaS.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||
|
panelLienzoRopaI.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||
|
|
||
|
JPanel panelLienzo = new JPanel();
|
||
|
panelLienzo.setLayout(new GridLayout(4, 1)); // 4 filas, 1 columna
|
||
|
panelLienzo.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||
|
|
||
|
panelLienzo.add(panelLienzoAccesorios);
|
||
|
panelLienzo.add(panelLienzoCara);
|
||
|
panelLienzo.add(panelLienzoRopaS);
|
||
|
panelLienzo.add(panelLienzoRopaI);
|
||
|
|
||
|
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
|
||
|
|
||
|
JPanel panelComboBox = new JPanel();
|
||
|
panelComboBox.setLayout(new GridLayout(8, 1, 0, 20)); // Espacio vertical entre componentes
|
||
|
panelComboBox.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||
|
panelComboBox.setBackground(new Color(200, 160, 255)); // Lila
|
||
|
|
||
|
JLabel label1 = new JLabel("Elige tus accesorios");
|
||
|
label1.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
|
||
|
JLabel label2 = new JLabel("Elige tu cabeza");
|
||
|
label2.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
|
||
|
JLabel label3 = new JLabel("Elige tu ropa superior");
|
||
|
label3.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
|
||
|
JLabel label4 = new JLabel("Elige tu ropa inferior");
|
||
|
label4.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
|
||
|
|
||
|
// Combo box 1
|
||
|
JComboBox<String> comboBox1 = new JComboBox<>(modelo.getOpciones("accesorios"));
|
||
|
comboBox1.setPreferredSize(new Dimension(200, comboBox1.getPreferredSize().height));
|
||
|
comboBox1.setFont(new Font("Aharoni", Font.BOLD, 15));
|
||
|
comboBox1.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
String selectedOption = (String) comboBox1.getSelectedItem();
|
||
|
dibujarPalabra(selectedOption, panelLienzoAccesorios,3);
|
||
|
}
|
||
|
});
|
||
|
panelComboBox.add(label1);
|
||
|
panelComboBox.add(comboBox1);
|
||
|
|
||
|
// Combo box 2
|
||
|
JComboBox<String> comboBox2 = new JComboBox<>(modelo.getOpciones("cabeza"));
|
||
|
comboBox2.setPreferredSize(new Dimension(200, comboBox2.getPreferredSize().height));
|
||
|
comboBox2.setFont(new Font("Aharoni", Font.BOLD, 15));
|
||
|
comboBox2.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
String selectedOption = (String) comboBox2.getSelectedItem();
|
||
|
dibujarPalabra(selectedOption, panelLienzoCara,3);
|
||
|
}
|
||
|
});
|
||
|
panelComboBox.add(label2);
|
||
|
panelComboBox.add(comboBox2);
|
||
|
|
||
|
// Combo box 3
|
||
|
JComboBox<String> comboBox3 = new JComboBox<>(modelo.getOpciones("ropaS"));
|
||
|
comboBox3.setPreferredSize(new Dimension(200, comboBox3.getPreferredSize().height));
|
||
|
comboBox3.setFont(new Font("Aharoni", Font.BOLD, 15));
|
||
|
comboBox3.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
String selectedOption = (String) comboBox3.getSelectedItem();
|
||
|
dibujarPalabra(selectedOption, panelLienzoRopaS,3);//tamaño de fuente
|
||
|
}
|
||
|
});
|
||
|
panelComboBox.add(label3);
|
||
|
panelComboBox.add(comboBox3);
|
||
|
|
||
|
// Combo box 4
|
||
|
JComboBox<String> comboBox4 = new JComboBox<>(modelo.getOpciones("ropaI"));
|
||
|
comboBox4.setPreferredSize(new Dimension(200, comboBox4.getPreferredSize().height));
|
||
|
comboBox4.setFont(new Font("Aharoni", Font.BOLD, 15));
|
||
|
comboBox4.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
String selectedOption = (String) comboBox4.getSelectedItem();
|
||
|
dibujarPalabra(selectedOption, panelLienzoRopaI,3);
|
||
|
}
|
||
|
});
|
||
|
panelComboBox.add(label4);
|
||
|
panelComboBox.add(comboBox4);
|
||
|
|
||
|
|
||
|
// Panel para el título "AvatArt"
|
||
|
JPanel panelTitulo = new JPanel();
|
||
|
JLabel labelTitulo = new JLabel("AvatART", SwingConstants.LEFT);
|
||
|
labelTitulo.setFont(new Font("Comic Sans MS", Font.BOLD, 50));
|
||
|
panelTitulo.add(labelTitulo);
|
||
|
panelTitulo.setBackground(new Color(200, 160, 255));
|
||
|
|
||
|
add(panelTitulo, BorderLayout.NORTH);
|
||
|
|
||
|
add(panelComboBox, BorderLayout.WEST);
|
||
|
add(panelLienzoContenedor, BorderLayout.CENTER);
|
||
|
|
||
|
setVisible(true);
|
||
|
}
|
||
|
|
||
|
public void dibujarPalabra(String palabra, JPanel panelLienzo, int fontSize) { // Agregar parámetro fontSize
|
||
|
String dibujo = modelo.getDibujo(palabra);
|
||
|
|
||
|
// Crear un JTextArea para mostrar el dibujo ASCII
|
||
|
JTextArea areaDibujo = new JTextArea(dibujo);
|
||
|
areaDibujo.setFont(new Font("Monospaced", Font.PLAIN, fontSize)); // Usar el tamaño de fuente proporcionado
|
||
|
areaDibujo.setEditable(false);
|
||
|
areaDibujo.setOpaque(false);
|
||
|
//areaDibujo.setBackground(Color.WHITE);
|
||
|
|
||
|
panelLienzo.removeAll();
|
||
|
panelLienzo.add(areaDibujo);
|
||
|
panelLienzo.revalidate();
|
||
|
panelLienzo.repaint();
|
||
|
}
|
||
|
}
|