1
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
# Configuración del fichero de continentes
|
||||||
|
continente.ruta=C:\\Users\\alumnoT\\aadd\\fic06.csv
|
||||||
|
continente.separador=#
|
||||||
@@ -3,7 +3,6 @@ package prueba.aadd.swing;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
@@ -15,41 +14,36 @@ import javax.swing.JScrollPane;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
// IMPORTACIÓN DE TUS PAQUETES PROPIOS CORRECTOS
|
||||||
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
import org.palomafp.aadd.rif.dao.ContinenteDAO;
|
||||||
import org.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
import org.palomafp.aadd.rif.dao.impl.ContinenteDAOImpl;
|
||||||
import org.palomafp.aadd.inm.dao.impl.PaisDaoText;
|
import org.palomafp.aadd.rif.model.Continente;
|
||||||
import org.palomafp.aadd.inm.model.Continente;
|
// Descomenta estas líneas cuando agregues las clases de Países:
|
||||||
import org.palomafp.aadd.inm.model.Pais;
|
// import org.palomafp.aadd.rif.dao.PaisDAO;
|
||||||
|
// import org.palomafp.aadd.rif.dao.impl.PaisDAOImpl;
|
||||||
|
// import org.palomafp.aadd.rif.model.Pais;
|
||||||
|
|
||||||
public class VentanaContinentesPaises extends JFrame {
|
public class VentanaContinentesPaises extends JFrame {
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
private JComboBox<Continente> comboContinentes;
|
private JComboBox<Continente> comboContinentes;
|
||||||
private JList<Pais> listaPaises;
|
private JList<String> listaPaises; // Cambiado temporalmente a String para evitar bloqueos si no tienes la clase Pais
|
||||||
private DefaultListModel<Pais> modeloPaises;
|
private DefaultListModel<String> modeloPaises;
|
||||||
private JTextArea areaInfo;
|
private JTextArea areaInfo;
|
||||||
|
|
||||||
private List<Pais> paisesActuales;
|
private ContinenteDAO continenteDAO;
|
||||||
|
// private PaisDAO hablandoDAO; // Descomentar cuando añadas PaisDAO
|
||||||
private IContinenteDAO continenteDAO;
|
|
||||||
private IPaisDAO paisDAO;
|
|
||||||
|
|
||||||
public VentanaContinentesPaises() {
|
public VentanaContinentesPaises() {
|
||||||
|
|
||||||
super("Continentes y países");
|
super("Continentes y países");
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setSize(500, 350);
|
setSize(500, 350);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
// Inicializar DAO
|
// Inicialización corregida con tus componentes reales
|
||||||
continenteDAO = new ContinenteDaoCSV();
|
continenteDAO = new ContinenteDAOImpl();
|
||||||
paisDAO = new PaisDaoText(continenteDAO);
|
// paisDAO = new PaisDAOImpl(continenteDAO); // Descomentar cuando añadas PaisDAO
|
||||||
|
|
||||||
// Componentes
|
|
||||||
comboContinentes = new JComboBox<>();
|
comboContinentes = new JComboBox<>();
|
||||||
modeloPaises = new DefaultListModel<>();
|
modeloPaises = new DefaultListModel<>();
|
||||||
listaPaises = new JList<>(modeloPaises);
|
listaPaises = new JList<>(modeloPaises);
|
||||||
@@ -59,25 +53,18 @@ public class VentanaContinentesPaises extends JFrame {
|
|||||||
areaInfo.setLineWrap(true);
|
areaInfo.setLineWrap(true);
|
||||||
areaInfo.setWrapStyleWord(true);
|
areaInfo.setWrapStyleWord(true);
|
||||||
|
|
||||||
// Mostrar nombre del continente en el desplegable
|
|
||||||
comboContinentes.setRenderer(new DefaultListCellRenderer() {
|
comboContinentes.setRenderer(new DefaultListCellRenderer() {
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
boolean cellHasFocus) {
|
|
||||||
|
|
||||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
|
|
||||||
if (value instanceof Continente) {
|
if (value instanceof Continente) {
|
||||||
setText(((Continente) value).getNombre());
|
setText(((Continente) value).getNombre());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Diseño
|
|
||||||
JPanel panel = new JPanel(new BorderLayout(5, 5));
|
JPanel panel = new JPanel(new BorderLayout(5, 5));
|
||||||
|
|
||||||
JPanel panelSuperior = new JPanel(new BorderLayout(5, 5));
|
JPanel panelSuperior = new JPanel(new BorderLayout(5, 5));
|
||||||
panelSuperior.add(new JLabel("Selecciona un continente:"), BorderLayout.WEST);
|
panelSuperior.add(new JLabel("Selecciona un continente:"), BorderLayout.WEST);
|
||||||
panelSuperior.add(comboContinentes, BorderLayout.CENTER);
|
panelSuperior.add(comboContinentes, BorderLayout.CENTER);
|
||||||
@@ -88,27 +75,24 @@ public class VentanaContinentesPaises extends JFrame {
|
|||||||
|
|
||||||
add(panel);
|
add(panel);
|
||||||
|
|
||||||
// Eventos
|
|
||||||
comboContinentes.addActionListener(e -> cargarPaises());
|
comboContinentes.addActionListener(e -> cargarPaises());
|
||||||
|
|
||||||
listaPaises.addListSelectionListener(e -> {
|
listaPaises.addListSelectionListener(e -> {
|
||||||
if (!e.getValueIsAdjusting()) {
|
if (!e.getValueIsAdjusting()) {
|
||||||
Pais seleccionado = listaPaises.getSelectedValue();
|
// Lógica de presentación de información detallada
|
||||||
|
String seleccionado = listaPaises.getSelectedValue();
|
||||||
if (seleccionado != null) {
|
if (seleccionado != null) {
|
||||||
mostrarInfo(seleccionado);
|
areaInfo.setText("Seleccionado: " + seleccionado);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cargar continentes al iniciar
|
|
||||||
cargarContinentes();
|
cargarContinentes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cargarContinentes() {
|
private void cargarContinentes() {
|
||||||
|
// Enlace corregido al método correcto de tu DAO propio
|
||||||
// Sustituir por el nombre real del método de tu DAO
|
List<Continente> continentes = continenteDAO.obtenerTodos();
|
||||||
List<Continente> continentes = continenteDAO.obtenerListaContinentes();
|
|
||||||
|
|
||||||
comboContinentes.removeAllItems();
|
comboContinentes.removeAllItems();
|
||||||
|
|
||||||
for (Continente continente : continentes) {
|
for (Continente continente : continentes) {
|
||||||
@@ -117,9 +101,7 @@ public class VentanaContinentesPaises extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cargarPaises() {
|
private void cargarPaises() {
|
||||||
|
|
||||||
Continente seleccionado = (Continente) comboContinentes.getSelectedItem();
|
Continente seleccionado = (Continente) comboContinentes.getSelectedItem();
|
||||||
|
|
||||||
modeloPaises.clear();
|
modeloPaises.clear();
|
||||||
areaInfo.setText("");
|
areaInfo.setText("");
|
||||||
|
|
||||||
@@ -127,36 +109,16 @@ public class VentanaContinentesPaises extends JFrame {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
paisesActuales = paisDAO.obtenerPaisesPorContinente(seleccionado.getCodigo());
|
// TODO: Enlazar aquí con tu funcionalidad de la Actividad 1.5 (IPaisDAO)
|
||||||
|
// Ejemplo provisional:
|
||||||
|
modeloPaises.addElement("País de ejemplo para " + seleccionado.getNombre());
|
||||||
|
|
||||||
if (paisesActuales == null || paisesActuales.isEmpty()) {
|
|
||||||
areaInfo.setText("No hay países disponibles para el continente seleccionado.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Pais pais : paisesActuales) {
|
|
||||||
modeloPaises.addElement(pais);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!paisesActuales.isEmpty()) {
|
|
||||||
listaPaises.setSelectedIndex(0);
|
listaPaises.setSelectedIndex(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void mostrarInfo(Pais pais) {
|
|
||||||
|
|
||||||
String texto = String.format("%s, capital de %s – %d, pertenece al continente %s (%s)", pais.getCapital(),
|
|
||||||
pais.getNombre(), pais.getIdentificador(), pais.getContinente().getNombre(),
|
|
||||||
pais.getContinente().getCodigo());
|
|
||||||
|
|
||||||
areaInfo.setText(texto);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
VentanaContinentesPaises ventana = new VentanaContinentesPaises();
|
VentanaContinentesPaises ventana = new VentanaContinentesPaises();
|
||||||
|
|
||||||
ventana.setVisible(true);
|
ventana.setVisible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user