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.Component;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JComboBox;
|
||||
@@ -15,41 +14,36 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
||||
import org.palomafp.aadd.inm.dao.impl.PaisDaoText;
|
||||
import org.palomafp.aadd.inm.model.Continente;
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
// IMPORTACIÓN DE TUS PAQUETES PROPIOS CORRECTOS
|
||||
import org.palomafp.aadd.rif.dao.ContinenteDAO;
|
||||
import org.palomafp.aadd.rif.dao.impl.ContinenteDAOImpl;
|
||||
import org.palomafp.aadd.rif.model.Continente;
|
||||
// Descomenta estas líneas cuando agregues las clases de Países:
|
||||
// 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 {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
private JComboBox<Continente> comboContinentes;
|
||||
private JList<Pais> listaPaises;
|
||||
private DefaultListModel<Pais> modeloPaises;
|
||||
private JList<String> listaPaises; // Cambiado temporalmente a String para evitar bloqueos si no tienes la clase Pais
|
||||
private DefaultListModel<String> modeloPaises;
|
||||
private JTextArea areaInfo;
|
||||
|
||||
private List<Pais> paisesActuales;
|
||||
|
||||
private IContinenteDAO continenteDAO;
|
||||
private IPaisDAO paisDAO;
|
||||
private ContinenteDAO continenteDAO;
|
||||
// private PaisDAO hablandoDAO; // Descomentar cuando añadas PaisDAO
|
||||
|
||||
public VentanaContinentesPaises() {
|
||||
|
||||
super("Continentes y países");
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(500, 350);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Inicializar DAO
|
||||
continenteDAO = new ContinenteDaoCSV();
|
||||
paisDAO = new PaisDaoText(continenteDAO);
|
||||
// Inicialización corregida con tus componentes reales
|
||||
continenteDAO = new ContinenteDAOImpl();
|
||||
// paisDAO = new PaisDAOImpl(continenteDAO); // Descomentar cuando añadas PaisDAO
|
||||
|
||||
// Componentes
|
||||
comboContinentes = new JComboBox<>();
|
||||
modeloPaises = new DefaultListModel<>();
|
||||
listaPaises = new JList<>(modeloPaises);
|
||||
@@ -59,25 +53,18 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
areaInfo.setLineWrap(true);
|
||||
areaInfo.setWrapStyleWord(true);
|
||||
|
||||
// Mostrar nombre del continente en el desplegable
|
||||
comboContinentes.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
|
||||
if (value instanceof Continente) {
|
||||
setText(((Continente) value).getNombre());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
// Diseño
|
||||
JPanel panel = 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(comboContinentes, BorderLayout.CENTER);
|
||||
@@ -88,27 +75,24 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
|
||||
add(panel);
|
||||
|
||||
// Eventos
|
||||
comboContinentes.addActionListener(e -> cargarPaises());
|
||||
|
||||
listaPaises.addListSelectionListener(e -> {
|
||||
if (!e.getValueIsAdjusting()) {
|
||||
Pais seleccionado = listaPaises.getSelectedValue();
|
||||
|
||||
// Lógica de presentación de información detallada
|
||||
String seleccionado = listaPaises.getSelectedValue();
|
||||
if (seleccionado != null) {
|
||||
mostrarInfo(seleccionado);
|
||||
areaInfo.setText("Seleccionado: " + seleccionado);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar continentes al iniciar
|
||||
cargarContinentes();
|
||||
}
|
||||
|
||||
private void cargarContinentes() {
|
||||
|
||||
// Sustituir por el nombre real del método de tu DAO
|
||||
List<Continente> continentes = continenteDAO.obtenerListaContinentes();
|
||||
|
||||
// Enlace corregido al método correcto de tu DAO propio
|
||||
List<Continente> continentes = continenteDAO.obtenerTodos();
|
||||
comboContinentes.removeAllItems();
|
||||
|
||||
for (Continente continente : continentes) {
|
||||
@@ -117,9 +101,7 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
}
|
||||
|
||||
private void cargarPaises() {
|
||||
|
||||
Continente seleccionado = (Continente) comboContinentes.getSelectedItem();
|
||||
|
||||
modeloPaises.clear();
|
||||
areaInfo.setText("");
|
||||
|
||||
@@ -127,36 +109,16 @@ public class VentanaContinentesPaises extends JFrame {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
VentanaContinentesPaises ventana = new VentanaContinentesPaises();
|
||||
|
||||
ventana.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user