mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
Compare commits
16 Commits
d8c4fa5e4b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4200da990 | ||
|
|
3ec83f87d6 | ||
|
|
f66e4a5dc0 | ||
|
|
8d3b26bf60 | ||
|
|
3e859f9db9 | ||
|
|
5b3b41dba0 | ||
|
|
263bd4220b | ||
|
|
dc2cbeefbe | ||
|
|
b6b59798dc | ||
|
|
f0c090da0d | ||
|
|
abf5adcfe9 | ||
|
|
8e18fb286b | ||
|
|
fbcc8026ed | ||
|
|
9ec8ab1912 | ||
|
|
7dbbed7984 | ||
|
|
738c42f160 |
File diff suppressed because one or more lines are too long
@@ -6,6 +6,8 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.modelo.Fabricante;
|
||||
|
||||
@@ -54,6 +56,33 @@ public class ControladorFabricante {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<Fabricante> findAllFabricante() {
|
||||
List<Fabricante> lista = new ArrayList<Fabricante>();
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs =
|
||||
s.executeQuery("select * from fabricante");
|
||||
|
||||
while (rs.next()) {
|
||||
Fabricante f = new Fabricante();
|
||||
f.setId(rs.getInt("id"));
|
||||
f.setNombre(rs.getString("nombre"));
|
||||
f.setCif(rs.getString("cif"));
|
||||
lista.add(f);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int modificaFabricante(Fabricante f) {
|
||||
@@ -95,7 +124,11 @@ public class ControladorFabricante {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param f
|
||||
* @return
|
||||
*/
|
||||
public static int insertaFabricante(Fabricante f) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
@@ -115,6 +148,28 @@ public class ControladorFabricante {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param f
|
||||
* @return
|
||||
*/
|
||||
public static int eliminaFabricante(int idFabricante) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
String sql = "delete from fabricante where id = ?";
|
||||
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, idFabricante);
|
||||
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -203,6 +203,11 @@ public class VentanaGestionFabricante extends JFrame {
|
||||
panel_1.add(btnNewButton_5);
|
||||
|
||||
JButton btnNewButton_6 = new JButton("Eliminar");
|
||||
btnNewButton_6.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
eliminar();
|
||||
}
|
||||
});
|
||||
panel_1.add(btnNewButton_6);
|
||||
|
||||
|
||||
@@ -277,6 +282,49 @@ public class VentanaGestionFabricante extends JFrame {
|
||||
this.jtfCif.setText("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void eliminar() {
|
||||
String [] opciones ={"Sí","No"};
|
||||
int eleccion = JOptionPane.showOptionDialog(null,"¿Desea eliminar el registro?",
|
||||
"Confirmación",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, opciones, "No");
|
||||
if (eleccion == JOptionPane.YES_OPTION) {
|
||||
// Realmente elimino
|
||||
int idFabricante = Integer.parseInt(this.jtfId.getText());
|
||||
|
||||
if (ControladorFabricante.eliminaFabricante(idFabricante) > 0) {
|
||||
// Navego al anterior, si existe
|
||||
Fabricante anterior =
|
||||
ControladorFabricante.getAnterior(idFabricante);
|
||||
if (anterior != null) { // Existe un anterior
|
||||
mostrarFabricanteEnPantalla(anterior);
|
||||
}
|
||||
else { // No existe anterior
|
||||
Fabricante siguiente =
|
||||
ControladorFabricante.getSiguiente(idFabricante);
|
||||
if (siguiente != null) { // Existe un siguiente
|
||||
mostrarFabricanteEnPantalla(siguiente);
|
||||
}
|
||||
else { // No existe siguiente ni anterior, no queda na
|
||||
nuevo();
|
||||
}
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "Registro eliminado");
|
||||
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Error en la eliminación");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JTextField;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class JPanelDatosPersonales extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField jtfId;
|
||||
private JTextField jtfNombre;
|
||||
private JTextField jtfAppelido1;
|
||||
private JLabel lblNewLabel_3;
|
||||
private JTextField textField;
|
||||
private Runnable runNavegarPrimerRegistro;
|
||||
private JToolBar toolBar;
|
||||
private JButton btnNewButton;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public JPanelDatosPersonales() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
toolBar = new JToolBar();
|
||||
GridBagConstraints gbc_toolBar = new GridBagConstraints();
|
||||
gbc_toolBar.gridwidth = 2;
|
||||
gbc_toolBar.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_toolBar.gridx = 0;
|
||||
gbc_toolBar.gridy = 0;
|
||||
add(toolBar, gbc_toolBar);
|
||||
|
||||
btnNewButton = new JButton("");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
runNavegarPrimerRegistro.run();
|
||||
}
|
||||
});
|
||||
btnNewButton.setIcon(new ImageIcon(JPanelDatosPersonales.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnNewButton);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Id:");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 1;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
jtfId = new JTextField();
|
||||
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
||||
gbc_jtfId.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfId.gridx = 1;
|
||||
gbc_jtfId.gridy = 1;
|
||||
add(jtfId, gbc_jtfId);
|
||||
jtfId.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Nombre:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 2;
|
||||
add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jtfNombre = new JTextField();
|
||||
GridBagConstraints gbc_jtfNombre = new GridBagConstraints();
|
||||
gbc_jtfNombre.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfNombre.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfNombre.gridx = 1;
|
||||
gbc_jtfNombre.gridy = 2;
|
||||
add(jtfNombre, gbc_jtfNombre);
|
||||
jtfNombre.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Apellido 1:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 3;
|
||||
add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfAppelido1 = new JTextField();
|
||||
GridBagConstraints gbc_jtfAppelido1 = new GridBagConstraints();
|
||||
gbc_jtfAppelido1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfAppelido1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfAppelido1.gridx = 1;
|
||||
gbc_jtfAppelido1.gridy = 3;
|
||||
add(jtfAppelido1, gbc_jtfAppelido1);
|
||||
jtfAppelido1.setColumns(10);
|
||||
|
||||
lblNewLabel_3 = new JLabel("Apellido 2:");
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 4;
|
||||
add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
textField = new JTextField();
|
||||
GridBagConstraints gbc_textField = new GridBagConstraints();
|
||||
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField.gridx = 1;
|
||||
gbc_textField.gridy = 4;
|
||||
add(textField, gbc_textField);
|
||||
textField.setColumns(10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.jtfId.setText("" + id);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return Integer.parseInt(this.jtfId.getText());
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.jtfNombre.setText(nombre);
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return this.jtfNombre.getText();
|
||||
}
|
||||
|
||||
public void setRunnableNavegarPrimerRegistro(Runnable runnable) {
|
||||
this.runNavegarPrimerRegistro = runnable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JToolBar;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.evaluacionCentroEducativo.Estudiante;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class JPanelEstudiante extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanelDatosPersonales panelDatos = new JPanelDatosPersonales();
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public JPanelEstudiante() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
GridBagConstraints gbc_toolBar = new GridBagConstraints();
|
||||
gbc_toolBar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_toolBar.gridx = 0;
|
||||
gbc_toolBar.gridy = 0;
|
||||
add(toolBar, gbc_toolBar);
|
||||
|
||||
JButton btnNewButton = new JButton("");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Estudiante e = ControladorEstudiante.findFirst();
|
||||
// panelDatos.setId(e.getId());
|
||||
// panelDatos.setNombre(e.getNombre());
|
||||
}
|
||||
});
|
||||
btnNewButton.setIcon(new ImageIcon(JPanelEstudiante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnNewButton);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de estudiantes");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 1;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
GridBagConstraints gbc_PanelDatosPersonales = new GridBagConstraints();
|
||||
gbc_PanelDatosPersonales.gridx = 0;
|
||||
gbc_PanelDatosPersonales.gridy = 2;
|
||||
add(panelDatos, gbc_PanelDatosPersonales);
|
||||
|
||||
|
||||
panelDatos.setRunnableNavegarPrimerRegistro(new Runnable() {
|
||||
public void run() {
|
||||
// Estudiante e = ControladorEstudiante.findFirst();
|
||||
// panelDatos.setId(e.getId());
|
||||
// panelDatos.setNombre(e.getNombre());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// private void cargarEstudianteEnPantalla(Estudiante e) {
|
||||
// this.panelDatos.setId(e.getId());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class JPanelProfesor extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public JPanelProfesor() {
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de Profesores");
|
||||
add(lblNewLabel, BorderLayout.NORTH);
|
||||
add(new JPanelDatosPersonales(), BorderLayout.CENTER);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JToolBar;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class PanelGestionCurso extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelGestionCurso() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
GridBagConstraints gbc_toolBar = new GridBagConstraints();
|
||||
gbc_toolBar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_toolBar.gridx = 0;
|
||||
gbc_toolBar.gridy = 0;
|
||||
add(toolBar, gbc_toolBar);
|
||||
|
||||
JButton btnNewButton = new JButton("");
|
||||
btnNewButton.setIcon(new ImageIcon(PanelGestionCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnNewButton);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("");
|
||||
btnNewButton_1.setIcon(new ImageIcon(PanelGestionCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
||||
toolBar.add(btnNewButton_1);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión Cursos");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 1;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class VentanaPrincipal extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
VentanaPrincipal frame = new VentanaPrincipal();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public VentanaPrincipal() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
setJMenuBar(menuBar);
|
||||
|
||||
JMenu mnNewMenu = new JMenu("New menu");
|
||||
menuBar.add(mnNewMenu);
|
||||
|
||||
JMenuItem mntmNewMenuItem = new JMenuItem("New menu item");
|
||||
mnNewMenu.add(mntmNewMenuItem);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
contentPane.add(toolBar, BorderLayout.NORTH);
|
||||
|
||||
JButton btnNewButton = new JButton("");
|
||||
btnNewButton.setIcon(new ImageIcon(VentanaPrincipal.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/guardar.png")));
|
||||
toolBar.add(btnNewButton);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("");
|
||||
btnNewButton_1.setIcon(new ImageIcon(VentanaPrincipal.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/eliminar.png")));
|
||||
toolBar.add(btnNewButton_1);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
contentPane.add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
tabbedPane.addTab("New tab", null, new PanelGestionCurso(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ public class Menu extends JMenuBar {
|
||||
// Menú Archivo de la aplicación
|
||||
JMenu menuArchivo = new JMenu("Archivo");
|
||||
|
||||
menuArchivo.add(crearNuevoMenuItem("Abrir", "ruedadentada.png", KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())));
|
||||
menuArchivo.add(crearNuevoMenuItem("Abrir", "ruedadentada.png",
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())));
|
||||
|
||||
JMenu menuExportar = new JMenu("Exportar");
|
||||
menuExportar.add(crearNuevoMenuItem("Como Word", "ruedadentada.png", KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())));
|
||||
|
||||
@@ -173,7 +173,8 @@ public class PanelJFileChooserFicheroImagen extends JPanel {
|
||||
Connection conexion = (Connection) DriverManager.getConnection ("jdbc:mysql://localhost/centroeducativo?serverTimezone=UTC","java", "Abcdefgh.1");
|
||||
|
||||
PreparedStatement ps = (PreparedStatement) conexion.
|
||||
prepareStatement("UPDATE centroeducativo.estudiante set imagen=? where id=?");
|
||||
prepareStatement("UPDATE centroeducativo.estudiante "
|
||||
+ "set imagen=? where id=?");
|
||||
|
||||
ps.setBytes(1, imagenEnArrayDeBytes);
|
||||
ps.setInt(2, 1);
|
||||
|
||||
@@ -4,8 +4,8 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.ProvinciaControlador;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorProvincia;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
@@ -24,11 +24,11 @@ public class PanelJList extends JPanel {
|
||||
|
||||
// Elemento JList a utilizar en el ejemplo
|
||||
private JList jlistProvincias;
|
||||
// Modelo del elemento JList, necesario para que podamos c<EFBFBD>modamente agregar y eliminar elementos
|
||||
// Modelo del elemento JList, necesario para que podamos cómodamente agregar y eliminar elementos
|
||||
private DefaultListModel<Provincia> listModelProvincias = null;
|
||||
// Lista de todas las provincias de la BBDD, para incluir en el elemento JList
|
||||
private List<Provincia> provincias = ProvinciaControlador.getControlador().findAllProvincias();
|
||||
// <EFBFBD>ndice de la <EFBFBD>ltima provincia agregada, para saber cu<EFBFBD>l debe ser la siguiente provincia a agregar
|
||||
private List<Provincia> provincias = ControladorProvincia.findAll();
|
||||
// Ìndice de la última provincia agregada, para saber cuál debe ser la siguiente provincia a agregar
|
||||
private int indiceProximaProvinciaParaAgregar = 0;
|
||||
|
||||
/**
|
||||
@@ -50,8 +50,8 @@ public class PanelJList extends JPanel {
|
||||
gbc_lblEjemploDeUso.gridy = 0;
|
||||
add(lblEjemploDeUso, gbc_lblEjemploDeUso);
|
||||
|
||||
// La JList debe ir dentro de un ScrollPane, y se construye con el modelo de JList sobre el que despu<EFBFBD>s
|
||||
// se agregar<EFBFBD>n o eliminar<EFBFBD>n provincias.
|
||||
// La JList debe ir dentro de un ScrollPane, y se construye con el modelo de JList sobre el que después
|
||||
// se agregarán o eliminarán provincias.
|
||||
jlistProvincias = new JList(this.getDefaultListModel());
|
||||
// Tipos de selecci<63>n disponibles en JList
|
||||
//this.jlistProvincias.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
@@ -96,7 +96,7 @@ public class PanelJList extends JPanel {
|
||||
|
||||
|
||||
/**
|
||||
* M<EFBFBD>todo que construye el modelo de JList, a utilizar para agregar y eliminar provincias
|
||||
* Método que construye el modelo de JList, a utilizar para agregar y eliminar provincias
|
||||
*/
|
||||
private DefaultListModel getDefaultListModel () {
|
||||
this.listModelProvincias = new DefaultListModel<Provincia>();
|
||||
@@ -108,16 +108,16 @@ public class PanelJList extends JPanel {
|
||||
*/
|
||||
private void agregarProvincia () {
|
||||
this.listModelProvincias.addElement(this.provincias.get(this.indiceProximaProvinciaParaAgregar));
|
||||
// Aumento el <EFBFBD>ndice de la pr<EFBFBD>xima provincia a agregar
|
||||
// Aumento el índice de la próxima provincia a agregar
|
||||
this.indiceProximaProvinciaParaAgregar++;
|
||||
// Si sobrepasa el l<EFBFBD>mite de las provincias posibles, reiniciamos a valor 0 (cero) el <EFBFBD>ndice de la pr<EFBFBD>xima provincia a agregar
|
||||
// Si sobrepasa el límite de las provincias posibles, reiniciamos a valor 0 (cero) el índice de la próxima provincia a agregar
|
||||
if (this.indiceProximaProvinciaParaAgregar == this.provincias.size()) {
|
||||
this.indiceProximaProvinciaParaAgregar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Para eliminar todas las provincias seleccionadas, deber<EFBFBD>amos comenzar desde la <EFBFBD>ltima e ir haciendo el barrido hasta la primera.
|
||||
* Para eliminar todas las provincias seleccionadas, deberíamos comenzar desde la última e ir haciendo el barrido hasta la primera.
|
||||
*/
|
||||
private void eliminarProvinciasSeleccionadas () {
|
||||
for (int i = this.jlistProvincias.getSelectedIndices().length - 1; i >= 0; i--) {
|
||||
@@ -125,3 +125,13 @@ public class PanelJList extends JPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class ConnectionManager {
|
||||
|
||||
private static Connection conn = null;
|
||||
|
||||
|
||||
public static Connection getConnection() throws Exception {
|
||||
if (conn == null) {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
conn =
|
||||
(Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://localhost:3306/poblacionprovincia?serverTimezone=UTC",
|
||||
"root", "1234");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Persona;
|
||||
;
|
||||
|
||||
|
||||
public class ControladorPersona {
|
||||
|
||||
|
||||
public static List<Persona> findAll() {
|
||||
List<Persona> l = new ArrayList<Persona>();
|
||||
|
||||
try {
|
||||
ResultSet rs = ConnectionManager.getConnection().createStatement()
|
||||
.executeQuery("Select * from persona");
|
||||
while (rs.next()) {
|
||||
Persona p = new Persona();
|
||||
p.setId(rs.getInt("id"));
|
||||
p.setNombre(rs.getString("nombre"));
|
||||
p.setApellido1(rs.getString("apellido1"));
|
||||
p.setApellido2(rs.getString("apellido2"));
|
||||
p.setFechaNacimiento(rs.getDate("fechaNacimiento"));
|
||||
p.setEdad(rs.getInt("edad"));
|
||||
p.setActivo(rs.getBoolean("activo"));
|
||||
p.setIdProvincia(rs.getInt("idProvincia"));
|
||||
p.setProvincia(ControladorProvincia.findById(p.getIdProvincia()));
|
||||
l.add(p);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||
|
||||
|
||||
public class ControladorProvincia {
|
||||
|
||||
|
||||
public static List<Provincia> findAll() {
|
||||
List<Provincia> l = new ArrayList<Provincia>();
|
||||
|
||||
try {
|
||||
ResultSet rs = ConnectionManager.getConnection().createStatement()
|
||||
.executeQuery("Select * from provincia");
|
||||
while (rs.next()) {
|
||||
Provincia p = new Provincia();
|
||||
p.setId(rs.getInt("id"));
|
||||
p.setDescripcion(rs.getString("descripcion"));
|
||||
l.add(p);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Provincia findById(int id) {
|
||||
Provincia p = null;
|
||||
|
||||
try {
|
||||
ResultSet rs = ConnectionManager.getConnection().createStatement()
|
||||
.executeQuery("Select * from provincia where id = " + id);
|
||||
if (rs.next()) {
|
||||
p = new Provincia();
|
||||
p.setId(rs.getInt("id"));
|
||||
p.setDescripcion(rs.getString("descripcion"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Persona {
|
||||
private int id;
|
||||
private String nombre;
|
||||
private String apellido1;
|
||||
private String apellido2;
|
||||
private Date fechaNacimiento;
|
||||
private int edad;
|
||||
private boolean activo;
|
||||
private int idProvincia;
|
||||
private Provincia provincia;
|
||||
|
||||
public Persona() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Persona(int id, String nombre, String apellido1, String apellido2, Date fechaNacimiento, int edad,
|
||||
boolean activo, int idProvincia) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.nombre = nombre;
|
||||
this.apellido1 = apellido1;
|
||||
this.apellido2 = apellido2;
|
||||
this.fechaNacimiento = fechaNacimiento;
|
||||
this.edad = edad;
|
||||
this.activo = activo;
|
||||
this.idProvincia = idProvincia;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellido1() {
|
||||
return apellido1;
|
||||
}
|
||||
|
||||
public void setApellido1(String apellido1) {
|
||||
this.apellido1 = apellido1;
|
||||
}
|
||||
|
||||
public String getApellido2() {
|
||||
return apellido2;
|
||||
}
|
||||
|
||||
public void setApellido2(String apellido2) {
|
||||
this.apellido2 = apellido2;
|
||||
}
|
||||
|
||||
public Date getFechaNacimiento() {
|
||||
return fechaNacimiento;
|
||||
}
|
||||
|
||||
public void setFechaNacimiento(Date fechaNacimiento) {
|
||||
this.fechaNacimiento = fechaNacimiento;
|
||||
}
|
||||
|
||||
public int getEdad() {
|
||||
return edad;
|
||||
}
|
||||
|
||||
public void setEdad(int edad) {
|
||||
this.edad = edad;
|
||||
}
|
||||
|
||||
public boolean isActivo() {
|
||||
return activo;
|
||||
}
|
||||
|
||||
public void setActivo(boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
|
||||
public int getIdProvincia() {
|
||||
return idProvincia;
|
||||
}
|
||||
|
||||
public void setIdProvincia(int idProvincia) {
|
||||
this.idProvincia = idProvincia;
|
||||
}
|
||||
|
||||
public Provincia getProvincia() {
|
||||
return provincia;
|
||||
}
|
||||
|
||||
public void setProvincia(Provincia provincia) {
|
||||
this.provincia = provincia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Persona [id=" + id + ", nombre=" + nombre + ", apellido1=" + apellido1 + ", apellido2=" + apellido2
|
||||
+ ", fechaNacimiento=" + fechaNacimiento + ", edad=" + edad + ", activo=" + activo + ", idProvincia="
|
||||
+ idProvincia + ", provincia=" + provincia + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model;
|
||||
|
||||
public class Provincia {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
|
||||
public Provincia() {
|
||||
}
|
||||
|
||||
public Provincia(int id, String descripcion) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,8 +2,9 @@ package tutorialJava.capitulo9_AWT_SWING.v06_EjemplosJTable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Persona;
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.PersonaControlador;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorPersona;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Persona;
|
||||
|
||||
|
||||
public class DatosDeTabla {
|
||||
|
||||
@@ -12,7 +13,7 @@ public class DatosDeTabla {
|
||||
* @return
|
||||
*/
|
||||
public static String[] getTitulosColumnas() {
|
||||
return new String[] {"Id", "Nombre", "1<EFBFBD> apellido", "2<EFBFBD> apellido", "Fecha Nac.", "Edad", "Activo", "Provincia"};
|
||||
return new String[] {"Id", "Nombre", "1º apellido", "2º apellido", "Fecha Nac.", "Edad", "Activo", "Provincia"};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,7 @@ public class DatosDeTabla {
|
||||
*/
|
||||
public static Object[][] getDatosDeTabla() {
|
||||
// Obtengo todas las personas
|
||||
List<Persona> personas = PersonaControlador.getControlador().findAllPersonas();
|
||||
List<Persona> personas = ControladorPersona.findAll();
|
||||
// Preparo una estructura para pasar al constructor de la JTable
|
||||
Object[][] datos = new Object[personas.size()][8];
|
||||
// Cargo los datos de la lista de personas en la matriz de los datos
|
||||
@@ -29,11 +30,11 @@ public class DatosDeTabla {
|
||||
Persona persona = personas.get(i);
|
||||
datos[i][0] = persona.getId();
|
||||
datos[i][1] = persona.getNombre();
|
||||
datos[i][2] = persona.getPrimerApellido();
|
||||
datos[i][3] = persona.getSegundoApellido();
|
||||
datos[i][2] = persona.getApellido1();
|
||||
datos[i][3] = persona.getApellido2();
|
||||
datos[i][4] = persona.getFechaNacimiento();
|
||||
datos[i][5] = persona.getEdad();
|
||||
datos[i][6] = persona.getActivo();
|
||||
datos[i][6] = persona.isActivo();
|
||||
datos[i][7] = persona.getProvincia();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,17 +62,27 @@ public class v02_TablaConDefaultTableModel extends JPanel {
|
||||
*/
|
||||
private DefaultTableModel getDefaultTableModelNoEditable () {
|
||||
DefaultTableModel dtm = new DefaultTableModel(datosEnTabla, titulosEnTabla) {
|
||||
|
||||
/**
|
||||
* La sobreescritura de este m<>todo nos permite controlar qu<71> celdas queremos que sean editables
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
if (column != 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (column == 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * La sobreescritura de este m<>todo nos permite controlar qu<71> celdas queremos que sean editables
|
||||
// */
|
||||
// @Override
|
||||
// public boolean isCellEditable(int row, int column) {
|
||||
// if (column != 1) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
};
|
||||
return dtm;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.ProvinciaControlador;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorProvincia;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||
|
||||
|
||||
public class MiProvinciaTableCellEditor extends DefaultCellEditor {
|
||||
|
||||
@@ -37,7 +38,7 @@ public class MiProvinciaTableCellEditor extends DefaultCellEditor {
|
||||
jcbProvincias.removeAllItems();
|
||||
|
||||
// Inicializo los elementos del combobox a todas las provincias disponibles y selecciono la correcta
|
||||
List<Provincia> provincias = ProvinciaControlador.getControlador().findAllProvincias();
|
||||
List<Provincia> provincias = ControladorProvincia.findAll();
|
||||
for (Provincia provincia : provincias) {
|
||||
jcbProvincias.addItem(provincia);
|
||||
if (value != null && value instanceof Provincia) {
|
||||
|
||||
@@ -11,7 +11,8 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
||||
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||
|
||||
|
||||
public class TablaEnScrollPane extends JPanel {
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package tutorialJava.examenes.examen20250321.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class ConnectionManager {
|
||||
|
||||
private static Connection conn = null;
|
||||
|
||||
|
||||
public static Connection getConnection() throws Exception {
|
||||
if (conn == null) {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
conn =
|
||||
(Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://localhost:3306/alquileres?serverTimezone=UTC",
|
||||
"root", "1234");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package tutorialJava.examenes.examen20250321.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250321.modelo.Inquilino;
|
||||
|
||||
|
||||
public class ControladorInquilino {
|
||||
|
||||
|
||||
public static Inquilino
|
||||
findByIdVivienda(int idVivienda) {
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
|
||||
String sql = "select * from inquilino where "
|
||||
+ "idVivienda = ?";
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, idVivienda);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
Inquilino i = new Inquilino();
|
||||
i.setId(rs.getInt("id"));
|
||||
i.setDni(rs.getString("dni"));
|
||||
i.setNombreCompleto(rs.getString("nombreCompleto"));
|
||||
i.setFechaInicioAlquiler(rs.getDate("fechaInicioAlquiler"));
|
||||
i.setFechaFinAlquiler(rs.getDate("fechaFinAlquiler"));
|
||||
i.setIdVivienda(rs.getInt("idVivienda"));
|
||||
i.setIdTipoMorosidad(rs.getInt("idTipoMorosidad"));
|
||||
i.setCuotaMensual(rs.getFloat("cuotaMensual"));
|
||||
return i;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static int guardaInquilino (Inquilino i) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
String sql = "Update inquilino set dni = ?, "
|
||||
+ "nombreCompleto = ?, fechaInicioAlquiler = ?, "
|
||||
+ "fechaFinAlquiler = ?, cuotaMensual = ?, "
|
||||
+ "idVivienda = ?, idTipoMorosidad = ? "
|
||||
+ "where id = ?";
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ps.setString(1, i.getDni());
|
||||
ps.setString(2, i.getNombreCompleto());
|
||||
if (i.getFechaInicioAlquiler() != null) {
|
||||
ps.setDate(3, new java.sql.Date(i.getFechaInicioAlquiler().getTime()));
|
||||
}
|
||||
else {
|
||||
ps.setDate(3, null);
|
||||
}
|
||||
if (i.getFechaFinAlquiler() != null) {
|
||||
ps.setDate(4, new java.sql.Date(i.getFechaFinAlquiler().getTime()));
|
||||
}
|
||||
else {
|
||||
ps.setDate(4, null);
|
||||
}
|
||||
ps.setFloat(5, i.getCuotaMensual());
|
||||
ps.setInt(6, i.getIdVivienda());
|
||||
ps.setInt(7, i.getIdTipoMorosidad());
|
||||
ps.setInt(8, i.getId());
|
||||
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package tutorialJava.examenes.examen20250321.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250321.modelo.Localidad;
|
||||
|
||||
public class ControladorLocalidad {
|
||||
|
||||
|
||||
public static List<Localidad> findAll() {
|
||||
List<Localidad> lista = new ArrayList<Localidad>();
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs =
|
||||
s.executeQuery("select * from localidad");
|
||||
|
||||
while (rs.next()) {
|
||||
Localidad l = new Localidad();
|
||||
l.setId(rs.getInt("id"));
|
||||
l.setDescripcion(rs.getString("descripcion"));
|
||||
lista.add(l);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package tutorialJava.examenes.examen20250321.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250321.modelo.TipoMorosidad;
|
||||
|
||||
|
||||
public class ControladorTipoMorosidad {
|
||||
|
||||
|
||||
public static List<TipoMorosidad> findAll() {
|
||||
List<TipoMorosidad> lista = new ArrayList<TipoMorosidad>();
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs =
|
||||
s.executeQuery("select * from tipo_morosidad");
|
||||
|
||||
while (rs.next()) {
|
||||
TipoMorosidad l = new TipoMorosidad();
|
||||
l.setId(rs.getInt("id"));
|
||||
l.setDescripcion(rs.getString("descripcion"));
|
||||
lista.add(l);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package tutorialJava.examenes.examen20250321.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250321.modelo.Vivienda;
|
||||
|
||||
|
||||
public class ControladorVivienda {
|
||||
|
||||
|
||||
public static List<Vivienda>
|
||||
findAllByLocalidadAndFilterDescription(int idLocalidad,
|
||||
String filterDescription) {
|
||||
|
||||
List<Vivienda> lista = new ArrayList<Vivienda>();
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
|
||||
String sql = "select * from vivienda where "
|
||||
+ "idLocalidad = ? and descripcion like ?";
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, idLocalidad);
|
||||
ps.setString(2, "%" + filterDescription + "%");
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Vivienda v = new Vivienda();
|
||||
v.setId(rs.getInt("id"));
|
||||
v.setDescripcion(rs.getString("descripcion"));
|
||||
v.setIdLocalidad(rs.getInt("idLocalidad"));
|
||||
lista.add(v);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package tutorialJava.examenes.examen20250321.modelo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Inquilino {
|
||||
private int id;
|
||||
private String dni;
|
||||
private String nombreCompleto;
|
||||
private Date fechaInicioAlquiler;
|
||||
private Date fechaFinAlquiler;
|
||||
private float cuotaMensual;
|
||||
private int idVivienda;
|
||||
private int idTipoMorosidad;
|
||||
|
||||
public Inquilino() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDni() {
|
||||
return dni;
|
||||
}
|
||||
|
||||
public void setDni(String dni) {
|
||||
this.dni = dni;
|
||||
}
|
||||
|
||||
public String getNombreCompleto() {
|
||||
return nombreCompleto;
|
||||
}
|
||||
|
||||
public void setNombreCompleto(String nombreCompleto) {
|
||||
this.nombreCompleto = nombreCompleto;
|
||||
}
|
||||
|
||||
public Date getFechaInicioAlquiler() {
|
||||
return fechaInicioAlquiler;
|
||||
}
|
||||
|
||||
public void setFechaInicioAlquiler(Date fechaInicioAlquiler) {
|
||||
this.fechaInicioAlquiler = fechaInicioAlquiler;
|
||||
}
|
||||
|
||||
public Date getFechaFinAlquiler() {
|
||||
return fechaFinAlquiler;
|
||||
}
|
||||
|
||||
public void setFechaFinAlquiler(Date fechaFinAlquiler) {
|
||||
this.fechaFinAlquiler = fechaFinAlquiler;
|
||||
}
|
||||
|
||||
public float getCuotaMensual() {
|
||||
return cuotaMensual;
|
||||
}
|
||||
|
||||
public void setCuotaMensual(float cuotaMensual) {
|
||||
this.cuotaMensual = cuotaMensual;
|
||||
}
|
||||
|
||||
public int getIdVivienda() {
|
||||
return idVivienda;
|
||||
}
|
||||
|
||||
public void setIdVivienda(int idVivienda) {
|
||||
this.idVivienda = idVivienda;
|
||||
}
|
||||
|
||||
public int getIdTipoMorosidad() {
|
||||
return idTipoMorosidad;
|
||||
}
|
||||
|
||||
public void setIdTipoMorosidad(int idTipoMorosidad) {
|
||||
this.idTipoMorosidad = idTipoMorosidad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Inquilino [id=" + id + ", dni=" + dni + ", nombreCompleto=" + nombreCompleto + ", fechaInicioAlquiler="
|
||||
+ fechaInicioAlquiler + ", fechaFinAlquiler=" + fechaFinAlquiler + ", cuotaMensual=" + cuotaMensual
|
||||
+ ", idVivienda=" + idVivienda + ", idTipoMorosidad=" + idTipoMorosidad + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package tutorialJava.examenes.examen20250321.modelo;
|
||||
|
||||
public class Localidad {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
|
||||
public Localidad() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Localidad(int id, String descripcion) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package tutorialJava.examenes.examen20250321.modelo;
|
||||
|
||||
public class TipoMorosidad {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
|
||||
public TipoMorosidad() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TipoMorosidad(int id, String descripcion) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package tutorialJava.examenes.examen20250321.modelo;
|
||||
|
||||
public class Vivienda {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
private int idLocalidad;
|
||||
|
||||
public Vivienda() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Vivienda(int id, String descripcion, int idLocalidad) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.descripcion = descripcion;
|
||||
this.idLocalidad = idLocalidad;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getIdLocalidad() {
|
||||
return idLocalidad;
|
||||
}
|
||||
|
||||
public void setIdLocalidad(int idLocalidad) {
|
||||
this.idLocalidad = idLocalidad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
package tutorialJava.examenes.examen20250321.vista;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import tutorialJava.examenes.examen20250321.controlador.ControladorInquilino;
|
||||
import tutorialJava.examenes.examen20250321.controlador.ControladorLocalidad;
|
||||
import tutorialJava.examenes.examen20250321.controlador.ControladorTipoMorosidad;
|
||||
import tutorialJava.examenes.examen20250321.controlador.ControladorVivienda;
|
||||
import tutorialJava.examenes.examen20250321.modelo.Inquilino;
|
||||
import tutorialJava.examenes.examen20250321.modelo.Localidad;
|
||||
import tutorialJava.examenes.examen20250321.modelo.TipoMorosidad;
|
||||
import tutorialJava.examenes.examen20250321.modelo.Vivienda;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class GestionAlquileres extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
private JTextField jtfId;
|
||||
private JTextField jtfDni;
|
||||
private JTextField jtfNombreInquilino;
|
||||
private JTextField jtfFechaInicio;
|
||||
private JTextField jtfFechaFin;
|
||||
private JTextField jtfCuotaMensual;
|
||||
private JTextField jtfFiltroVivienda;
|
||||
private JComboBox<Localidad> jcbLocalidad;
|
||||
private JComboBox<TipoMorosidad> jcbTipoMorosidad;
|
||||
private JComboBox<Vivienda> jcbVivienda;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
private JLabel jlblCuotaConIva;
|
||||
private JCheckBox chkActivo;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
GestionAlquileres frame = new GestionAlquileres();
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public GestionAlquileres() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de alquileres");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 3;
|
||||
gbc_lblNewLabel.insets = new Insets(15, 0, 5, 0);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
contentPane.add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Localidad:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jcbLocalidad = new JComboBox();
|
||||
GridBagConstraints gbc_jcbLocalidad = new GridBagConstraints();
|
||||
gbc_jcbLocalidad.gridwidth = 2;
|
||||
gbc_jcbLocalidad.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbLocalidad.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbLocalidad.gridx = 1;
|
||||
gbc_jcbLocalidad.gridy = 1;
|
||||
contentPane.add(jcbLocalidad, gbc_jcbLocalidad);
|
||||
|
||||
JLabel lblNewLabel_12 = new JLabel("Filtro de vivienda");
|
||||
GridBagConstraints gbc_lblNewLabel_12 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_12.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_12.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_12.gridx = 0;
|
||||
gbc_lblNewLabel_12.gridy = 2;
|
||||
contentPane.add(lblNewLabel_12, gbc_lblNewLabel_12);
|
||||
|
||||
jtfFiltroVivienda = new JTextField();
|
||||
GridBagConstraints gbc_jtfFiltroVivienda = new GridBagConstraints();
|
||||
gbc_jtfFiltroVivienda.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jtfFiltroVivienda.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFiltroVivienda.gridx = 1;
|
||||
gbc_jtfFiltroVivienda.gridy = 2;
|
||||
contentPane.add(jtfFiltroVivienda, gbc_jtfFiltroVivienda);
|
||||
jtfFiltroVivienda.setColumns(10);
|
||||
|
||||
JButton btnFiltroVivienda = new JButton("Filtrar viviendas");
|
||||
btnFiltroVivienda.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
filtrarViviendas();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnFiltroVivienda = new GridBagConstraints();
|
||||
gbc_btnFiltroVivienda.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnFiltroVivienda.gridx = 2;
|
||||
gbc_btnFiltroVivienda.gridy = 2;
|
||||
contentPane.add(btnFiltroVivienda, gbc_btnFiltroVivienda);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Vivienda:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 3;
|
||||
contentPane.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jcbVivienda = new JComboBox();
|
||||
jcbVivienda.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarInquilino();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_jcbVivienda = new GridBagConstraints();
|
||||
gbc_jcbVivienda.gridwidth = 2;
|
||||
gbc_jcbVivienda.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbVivienda.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbVivienda.gridx = 1;
|
||||
gbc_jcbVivienda.gridy = 3;
|
||||
contentPane.add(jcbVivienda, gbc_jcbVivienda);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("Datos del inquilino");
|
||||
lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.gridwidth = 3;
|
||||
gbc_lblNewLabel_3.insets = new Insets(15, 0, 5, 0);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 4;
|
||||
contentPane.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("Id:");
|
||||
GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_4.gridx = 0;
|
||||
gbc_lblNewLabel_4.gridy = 5;
|
||||
contentPane.add(lblNewLabel_4, gbc_lblNewLabel_4);
|
||||
|
||||
jtfId = new JTextField();
|
||||
jtfId.setEnabled(false);
|
||||
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
||||
gbc_jtfId.gridwidth = 2;
|
||||
gbc_jtfId.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfId.gridx = 1;
|
||||
gbc_jtfId.gridy = 5;
|
||||
contentPane.add(jtfId, gbc_jtfId);
|
||||
jtfId.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_5 = new JLabel("DNI:");
|
||||
GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_5.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_5.gridx = 0;
|
||||
gbc_lblNewLabel_5.gridy = 6;
|
||||
contentPane.add(lblNewLabel_5, gbc_lblNewLabel_5);
|
||||
|
||||
jtfDni = new JTextField();
|
||||
GridBagConstraints gbc_jtfDni = new GridBagConstraints();
|
||||
gbc_jtfDni.gridwidth = 2;
|
||||
gbc_jtfDni.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfDni.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfDni.gridx = 1;
|
||||
gbc_jtfDni.gridy = 6;
|
||||
contentPane.add(jtfDni, gbc_jtfDni);
|
||||
jtfDni.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_6 = new JLabel("Nombre completo:");
|
||||
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_6.gridx = 0;
|
||||
gbc_lblNewLabel_6.gridy = 7;
|
||||
contentPane.add(lblNewLabel_6, gbc_lblNewLabel_6);
|
||||
|
||||
jtfNombreInquilino = new JTextField();
|
||||
GridBagConstraints gbc_jtfNombreInquilino = new GridBagConstraints();
|
||||
gbc_jtfNombreInquilino.gridwidth = 2;
|
||||
gbc_jtfNombreInquilino.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfNombreInquilino.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfNombreInquilino.gridx = 1;
|
||||
gbc_jtfNombreInquilino.gridy = 7;
|
||||
contentPane.add(jtfNombreInquilino, gbc_jtfNombreInquilino);
|
||||
jtfNombreInquilino.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_7 = new JLabel("Fecha inicio:");
|
||||
GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_7.gridx = 0;
|
||||
gbc_lblNewLabel_7.gridy = 8;
|
||||
contentPane.add(lblNewLabel_7, gbc_lblNewLabel_7);
|
||||
|
||||
jtfFechaInicio = new JTextField();
|
||||
GridBagConstraints gbc_jtfFechaInicio = new GridBagConstraints();
|
||||
gbc_jtfFechaInicio.gridwidth = 2;
|
||||
gbc_jtfFechaInicio.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFechaInicio.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFechaInicio.gridx = 1;
|
||||
gbc_jtfFechaInicio.gridy = 8;
|
||||
contentPane.add(jtfFechaInicio, gbc_jtfFechaInicio);
|
||||
jtfFechaInicio.setColumns(10);
|
||||
|
||||
chkActivo = new JCheckBox("Alquiler en activo");
|
||||
chkActivo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
checkAlquierActivo();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_chkActivo = new GridBagConstraints();
|
||||
gbc_chkActivo.gridwidth = 3;
|
||||
gbc_chkActivo.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_chkActivo.gridx = 0;
|
||||
gbc_chkActivo.gridy = 9;
|
||||
contentPane.add(chkActivo, gbc_chkActivo);
|
||||
|
||||
JLabel lblNewLabel_8 = new JLabel("Fecha de fin:");
|
||||
GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_8.fill = GridBagConstraints.VERTICAL;
|
||||
gbc_lblNewLabel_8.gridx = 0;
|
||||
gbc_lblNewLabel_8.gridy = 10;
|
||||
contentPane.add(lblNewLabel_8, gbc_lblNewLabel_8);
|
||||
|
||||
jtfFechaFin = new JTextField();
|
||||
GridBagConstraints gbc_jtfFechaFin = new GridBagConstraints();
|
||||
gbc_jtfFechaFin.gridwidth = 2;
|
||||
gbc_jtfFechaFin.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFechaFin.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFechaFin.gridx = 1;
|
||||
gbc_jtfFechaFin.gridy = 10;
|
||||
contentPane.add(jtfFechaFin, gbc_jtfFechaFin);
|
||||
jtfFechaFin.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_13 = new JLabel("Tipo de morosidad:");
|
||||
GridBagConstraints gbc_lblNewLabel_13 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_13.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_13.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_13.gridx = 0;
|
||||
gbc_lblNewLabel_13.gridy = 11;
|
||||
contentPane.add(lblNewLabel_13, gbc_lblNewLabel_13);
|
||||
|
||||
jcbTipoMorosidad = new JComboBox();
|
||||
GridBagConstraints gbc_jcbTipoMorosidad = new GridBagConstraints();
|
||||
gbc_jcbTipoMorosidad.gridwidth = 2;
|
||||
gbc_jcbTipoMorosidad.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jcbTipoMorosidad.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbTipoMorosidad.gridx = 1;
|
||||
gbc_jcbTipoMorosidad.gridy = 11;
|
||||
contentPane.add(jcbTipoMorosidad, gbc_jcbTipoMorosidad);
|
||||
|
||||
JLabel lblNewLabel_9 = new JLabel("Cuota mensual (€):");
|
||||
GridBagConstraints gbc_lblNewLabel_9 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_9.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_9.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_9.gridx = 0;
|
||||
gbc_lblNewLabel_9.gridy = 12;
|
||||
contentPane.add(lblNewLabel_9, gbc_lblNewLabel_9);
|
||||
|
||||
jtfCuotaMensual = new JTextField();
|
||||
GridBagConstraints gbc_jtfCuotaMensual = new GridBagConstraints();
|
||||
gbc_jtfCuotaMensual.gridwidth = 2;
|
||||
gbc_jtfCuotaMensual.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfCuotaMensual.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfCuotaMensual.gridx = 1;
|
||||
gbc_jtfCuotaMensual.gridy = 12;
|
||||
contentPane.add(jtfCuotaMensual, gbc_jtfCuotaMensual);
|
||||
jtfCuotaMensual.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_10 = new JLabel("Total mensual (IVA incluido) €:");
|
||||
GridBagConstraints gbc_lblNewLabel_10 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_10.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_10.gridx = 0;
|
||||
gbc_lblNewLabel_10.gridy = 13;
|
||||
contentPane.add(lblNewLabel_10, gbc_lblNewLabel_10);
|
||||
|
||||
jlblCuotaConIva = new JLabel("??? €");
|
||||
GridBagConstraints gbc_jlblCuotaConIva = new GridBagConstraints();
|
||||
gbc_jlblCuotaConIva.gridwidth = 2;
|
||||
gbc_jlblCuotaConIva.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jlblCuotaConIva.gridx = 1;
|
||||
gbc_jlblCuotaConIva.gridy = 13;
|
||||
contentPane.add(jlblCuotaConIva, gbc_jlblCuotaConIva);
|
||||
|
||||
JButton btnGuardar = new JButton("Guardar cambios");
|
||||
btnGuardar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
guardarInquilino();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
|
||||
gbc_btnGuardar.gridwidth = 3;
|
||||
gbc_btnGuardar.gridx = 0;
|
||||
gbc_btnGuardar.gridy = 14;
|
||||
contentPane.add(btnGuardar, gbc_btnGuardar);
|
||||
|
||||
// Carga de todas las localidades y tipos de morosidad
|
||||
cargarLocalidades();
|
||||
cargarTiposMorosidad();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarLocalidades() {
|
||||
for(Localidad l : ControladorLocalidad.findAll()) {
|
||||
jcbLocalidad.addItem(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarTiposMorosidad() {
|
||||
for(TipoMorosidad l : ControladorTipoMorosidad.findAll()) {
|
||||
jcbTipoMorosidad.addItem(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void filtrarViviendas() {
|
||||
Localidad localidadSeleccionada =
|
||||
(Localidad) this.jcbLocalidad.getSelectedItem();
|
||||
int idLocalidadSeleccionada = localidadSeleccionada.getId();
|
||||
String filtroVivienda = this.jtfFiltroVivienda.getText();
|
||||
|
||||
List<Vivienda> viviendas = ControladorVivienda
|
||||
.findAllByLocalidadAndFilterDescription(
|
||||
idLocalidadSeleccionada, filtroVivienda);
|
||||
|
||||
this.jcbVivienda.removeAllItems();
|
||||
for (Vivienda v : viviendas) {
|
||||
this.jcbVivienda.addItem(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarInquilino() {
|
||||
if (jcbVivienda.getItemCount() > 0) {
|
||||
Vivienda viviendaSeleccionada =
|
||||
(Vivienda) jcbVivienda.getSelectedItem();
|
||||
int idVivienda = viviendaSeleccionada.getId();
|
||||
|
||||
Inquilino i = ControladorInquilino
|
||||
.findByIdVivienda(idVivienda);
|
||||
|
||||
if (i != null) {
|
||||
this.jtfId.setText("" + i.getId());
|
||||
this.jtfDni.setText(i.getDni());
|
||||
this.jtfNombreInquilino.setText(i.getNombreCompleto());
|
||||
if (i.getFechaInicioAlquiler() != null) {
|
||||
this.jtfFechaInicio.setText(
|
||||
sdf.format(i.getFechaInicioAlquiler()));
|
||||
}
|
||||
else {
|
||||
this.jtfFechaInicio.setText("");
|
||||
}
|
||||
if (i.getFechaFinAlquiler() != null) {
|
||||
this.jtfFechaFin.setText(
|
||||
sdf.format(i.getFechaFinAlquiler()));
|
||||
}
|
||||
else {
|
||||
this.jtfFechaFin.setText("");
|
||||
}
|
||||
// Tipo de morosidad
|
||||
for(int j = 0; j < this.jcbTipoMorosidad.getItemCount(); j++) {
|
||||
if (this.jcbTipoMorosidad.getItemAt(j).getId() ==
|
||||
i.getIdTipoMorosidad()) {
|
||||
this.jcbTipoMorosidad.setSelectedIndex(j);
|
||||
}
|
||||
}
|
||||
// Cuota mensual
|
||||
this.jtfCuotaMensual.setText("" + i.getCuotaMensual());
|
||||
this.jlblCuotaConIva.setText("" + (i.getCuotaMensual() * 1.21));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void checkAlquierActivo() {
|
||||
if (chkActivo.isSelected()) {
|
||||
this.jtfFechaFin.setEnabled(false);
|
||||
this.jtfFechaFin.setText("");
|
||||
}
|
||||
else {
|
||||
this.jtfFechaFin.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void guardarInquilino() {
|
||||
Inquilino i = new Inquilino();
|
||||
i.setId(Integer.parseInt(this.jtfId.getText()));
|
||||
i.setDni(this.jtfDni.getText());
|
||||
if (this.jtfNombreInquilino.getText().trim().equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Introduzca un nombre para el inquilino");
|
||||
return;
|
||||
}
|
||||
i.setNombreCompleto(this.jtfNombreInquilino.getText());
|
||||
Date fechaInicio = getFechaFromString(this.jtfFechaInicio.getText());
|
||||
if (!jtfFechaInicio.getText().trim().equals("") &&
|
||||
fechaInicio == null) {
|
||||
JOptionPane.showMessageDialog(null, "Fecha de inicio no válida, use formato dd/MM/yyyy");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
i.setFechaInicioAlquiler(fechaInicio);
|
||||
}
|
||||
Date fechaFin = getFechaFromString(this.jtfFechaFin.getText());
|
||||
if (!jtfFechaFin.getText().trim().equals("") &&
|
||||
fechaFin == null) {
|
||||
JOptionPane.showMessageDialog(null, "Fecha de fin no válida, use formato dd/MM/yyyy");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
i.setFechaFinAlquiler(fechaFin);
|
||||
}
|
||||
TipoMorosidad morosidadSeleccionada =
|
||||
(TipoMorosidad) this.jcbTipoMorosidad.getSelectedItem();
|
||||
i.setIdTipoMorosidad(morosidadSeleccionada.getId());
|
||||
Vivienda viviendaSeleccionada =
|
||||
(Vivienda) this.jcbVivienda.getSelectedItem();
|
||||
i.setIdVivienda(viviendaSeleccionada.getId());
|
||||
i.setCuotaMensual(Float.parseFloat(this.jtfCuotaMensual.getText()));
|
||||
|
||||
if (ControladorInquilino.guardaInquilino(i) > 0) {
|
||||
JOptionPane.showMessageDialog(null, "Inquilino almacenado");
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Algo ha fallado");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Date getFechaFromString(String strDate) {
|
||||
try {
|
||||
return sdf.parse(strDate);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
246
src/tutorialJava/examenes/examen20250404/GestionBiblioteca.java
Normal file
246
src/tutorialJava/examenes/examen20250404/GestionBiblioteca.java
Normal file
@@ -0,0 +1,246 @@
|
||||
package tutorialJava.examenes.examen20250404;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
|
||||
public class GestionBiblioteca extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
private JTextField jtfFiltroTituloLibro;
|
||||
private JTextField jtfFiltroAutorLibro;
|
||||
private JTextField textField;
|
||||
private JTextField textField_1;
|
||||
private JTextField textField_2;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
GestionBiblioteca frame = new GestionBiblioteca();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public GestionBiblioteca() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de préstamos de biblioteca");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 2;
|
||||
gbc_lblNewLabel.insets = new Insets(10, 0, 10, 0);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
contentPane.add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Categoría literaria:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
JComboBox jcbCategoria = new JComboBox();
|
||||
jcbCategoria.setModel(new DefaultComboBoxModel(new String[] {"Novela"}));
|
||||
GridBagConstraints gbc_jcbCategoria = new GridBagConstraints();
|
||||
gbc_jcbCategoria.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbCategoria.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbCategoria.gridx = 1;
|
||||
gbc_jcbCategoria.gridy = 1;
|
||||
contentPane.add(jcbCategoria, gbc_jcbCategoria);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Filtro de título de libro:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 2;
|
||||
contentPane.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfFiltroTituloLibro = new JTextField();
|
||||
jtfFiltroTituloLibro.setText("Cien");
|
||||
GridBagConstraints gbc_jtfFiltroTituloLibro = new GridBagConstraints();
|
||||
gbc_jtfFiltroTituloLibro.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFiltroTituloLibro.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFiltroTituloLibro.gridx = 1;
|
||||
gbc_jtfFiltroTituloLibro.gridy = 2;
|
||||
contentPane.add(jtfFiltroTituloLibro, gbc_jtfFiltroTituloLibro);
|
||||
jtfFiltroTituloLibro.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("Filtro de autor de libro:");
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 3;
|
||||
contentPane.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
jtfFiltroAutorLibro = new JTextField();
|
||||
jtfFiltroAutorLibro.setText("García");
|
||||
GridBagConstraints gbc_jtfFiltroAutorLibro = new GridBagConstraints();
|
||||
gbc_jtfFiltroAutorLibro.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFiltroAutorLibro.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFiltroAutorLibro.gridx = 1;
|
||||
gbc_jtfFiltroAutorLibro.gridy = 3;
|
||||
contentPane.add(jtfFiltroAutorLibro, gbc_jtfFiltroAutorLibro);
|
||||
jtfFiltroAutorLibro.setColumns(10);
|
||||
|
||||
JButton btnFiltrarLibros = new JButton("Filtrar libros");
|
||||
GridBagConstraints gbc_btnFiltrarLibros = new GridBagConstraints();
|
||||
gbc_btnFiltrarLibros.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnFiltrarLibros.gridx = 1;
|
||||
gbc_btnFiltrarLibros.gridy = 4;
|
||||
contentPane.add(btnFiltrarLibros, gbc_btnFiltrarLibros);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("Libros filtrados:");
|
||||
GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_4.gridx = 0;
|
||||
gbc_lblNewLabel_4.gridy = 5;
|
||||
contentPane.add(lblNewLabel_4, gbc_lblNewLabel_4);
|
||||
|
||||
JComboBox jcbLibrosFiltrados = new JComboBox();
|
||||
jcbLibrosFiltrados.setModel(new DefaultComboBoxModel(new String[] {"Cien años de soledad - Gabriel García Márquez"}));
|
||||
GridBagConstraints gbc_jcbLibrosFiltrados = new GridBagConstraints();
|
||||
gbc_jcbLibrosFiltrados.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbLibrosFiltrados.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbLibrosFiltrados.gridx = 1;
|
||||
gbc_jcbLibrosFiltrados.gridy = 5;
|
||||
contentPane.add(jcbLibrosFiltrados, gbc_jcbLibrosFiltrados);
|
||||
|
||||
JLabel lblNewLabel_5 = new JLabel("Datos del préstamo del libro");
|
||||
lblNewLabel_5.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_5.gridwidth = 2;
|
||||
gbc_lblNewLabel_5.insets = new Insets(10, 0, 10, 0);
|
||||
gbc_lblNewLabel_5.gridx = 0;
|
||||
gbc_lblNewLabel_5.gridy = 6;
|
||||
contentPane.add(lblNewLabel_5, gbc_lblNewLabel_5);
|
||||
|
||||
JLabel lblNewLabel_6 = new JLabel("Id préstamo:");
|
||||
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_6.gridx = 0;
|
||||
gbc_lblNewLabel_6.gridy = 7;
|
||||
contentPane.add(lblNewLabel_6, gbc_lblNewLabel_6);
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setEnabled(false);
|
||||
textField.setText("1");
|
||||
GridBagConstraints gbc_textField = new GridBagConstraints();
|
||||
gbc_textField.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField.gridx = 1;
|
||||
gbc_textField.gridy = 7;
|
||||
contentPane.add(textField, gbc_textField);
|
||||
textField.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_7 = new JLabel("Usuario:");
|
||||
GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_7.gridx = 0;
|
||||
gbc_lblNewLabel_7.gridy = 8;
|
||||
contentPane.add(lblNewLabel_7, gbc_lblNewLabel_7);
|
||||
|
||||
JComboBox jcbUsuario = new JComboBox();
|
||||
jcbUsuario.setModel(new DefaultComboBoxModel(new String[] {"Ana López - 12345678A"}));
|
||||
GridBagConstraints gbc_jcbUsuario = new GridBagConstraints();
|
||||
gbc_jcbUsuario.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbUsuario.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbUsuario.gridx = 1;
|
||||
gbc_jcbUsuario.gridy = 8;
|
||||
contentPane.add(jcbUsuario, gbc_jcbUsuario);
|
||||
|
||||
JLabel lblNewLabel_8 = new JLabel("Fecha del préstamo:");
|
||||
GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_8.gridx = 0;
|
||||
gbc_lblNewLabel_8.gridy = 9;
|
||||
contentPane.add(lblNewLabel_8, gbc_lblNewLabel_8);
|
||||
|
||||
textField_1 = new JTextField();
|
||||
textField_1.setText("2025-03-01");
|
||||
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
|
||||
gbc_textField_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_1.gridx = 1;
|
||||
gbc_textField_1.gridy = 9;
|
||||
contentPane.add(textField_1, gbc_textField_1);
|
||||
textField_1.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_9 = new JLabel("Fecha de devolución:");
|
||||
GridBagConstraints gbc_lblNewLabel_9 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_9.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_9.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_9.gridx = 0;
|
||||
gbc_lblNewLabel_9.gridy = 10;
|
||||
contentPane.add(lblNewLabel_9, gbc_lblNewLabel_9);
|
||||
|
||||
textField_2 = new JTextField();
|
||||
textField_2.setText("2025-03-15");
|
||||
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
|
||||
gbc_textField_2.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_textField_2.gridx = 1;
|
||||
gbc_textField_2.gridy = 10;
|
||||
contentPane.add(textField_2, gbc_textField_2);
|
||||
textField_2.setColumns(10);
|
||||
|
||||
JCheckBox chckbxNewCheckBox = new JCheckBox("Préstamo activo");
|
||||
GridBagConstraints gbc_chckbxNewCheckBox = new GridBagConstraints();
|
||||
gbc_chckbxNewCheckBox.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_chckbxNewCheckBox.anchor = GridBagConstraints.WEST;
|
||||
gbc_chckbxNewCheckBox.gridx = 1;
|
||||
gbc_chckbxNewCheckBox.gridy = 11;
|
||||
contentPane.add(chckbxNewCheckBox, gbc_chckbxNewCheckBox);
|
||||
|
||||
JButton btnGuardar = new JButton("Guardar cambios del préstamo");
|
||||
GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
|
||||
gbc_btnGuardar.gridwidth = 2;
|
||||
gbc_btnGuardar.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_btnGuardar.gridx = 0;
|
||||
gbc_btnGuardar.gridy = 12;
|
||||
contentPane.add(btnGuardar, gbc_btnGuardar);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package tutorialJava.examenes.examen20250509.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class ConnectionManager {
|
||||
|
||||
private static Connection conn = null;
|
||||
|
||||
|
||||
public static Connection getConnection() throws Exception {
|
||||
if (conn == null) {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
conn =
|
||||
(Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://localhost:3306/conciertos_grupos_salas?serverTimezone=Europe/Madrid",
|
||||
"root", "1234");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
package tutorialJava.examenes.examen20250509.controlador;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
|
||||
public class ControladorConcierto {
|
||||
|
||||
public static Concierto getPrimero () {
|
||||
Concierto c = getConciertoDesdeSql("select * from concierto "
|
||||
+ "order by id asc limit 1");
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Concierto getSiguiente (int idActual) {
|
||||
Concierto c = getConciertoDesdeSql("select * from concierto "
|
||||
+ "where id > " + idActual + " order by id asc limit 1");
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Concierto getUltimo () {
|
||||
Concierto c = getConciertoDesdeSql("select * from concierto "
|
||||
+ "order by id desc limit 1");
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Concierto getAnterior (int idActual) {
|
||||
Concierto c = getConciertoDesdeSql("select * from concierto "
|
||||
+ "where id < " + idActual + " order by id desc limit 1");
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
public static Concierto getConciertoDesdeSql (String sql) {
|
||||
Concierto c = null;
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
if (rs.next()) {
|
||||
c = new Concierto();
|
||||
c.setId(rs.getInt("id"));
|
||||
c.setFecha(rs.getDate("fecha"));
|
||||
c.setPrecio(rs.getFloat("precio"));
|
||||
c.setFestival(rs.getBoolean("es_festival"));
|
||||
c.setIdGrupo(rs.getInt("grupo_id"));
|
||||
c.setIdSala(rs.getInt("sala_id"));
|
||||
return c;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
public static int guardar (Concierto c) {
|
||||
if (c.getId() > 0) {
|
||||
return modificar(c);
|
||||
}
|
||||
else if (c.getId() == 0){ // Inserción del dato
|
||||
return insertar(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public static int modificar(Concierto c) {
|
||||
int registroAfectados = 0;
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"update concierto set fecha= ? "
|
||||
+ ", precio= ?, es_festival = ?, "
|
||||
+ "sala_id = ?, grupo_id = ? "
|
||||
+ "where id = ?");
|
||||
long millisFecha = c.getFecha().getTime();
|
||||
ps.setDate(1, new java.sql.Date(millisFecha));
|
||||
ps.setFloat(2, c.getPrecio());
|
||||
ps.setBoolean(3, c.isFestival());
|
||||
ps.setInt(4, c.getIdSala());
|
||||
ps.setInt(5, c.getIdGrupo());
|
||||
ps.setInt(6, c.getId());
|
||||
registroAfectados = ps.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return registroAfectados;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
public static int insertar(Concierto c) {
|
||||
int registroAfectados = 0;
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"insert into concierto "
|
||||
+ "(id, fecha, precio, es_festival, sala_id,"
|
||||
+ "grupo_id) values (?, ?, ?, ?, ?, ?)");
|
||||
long millisFecha = c.getFecha().getTime();
|
||||
ps.setInt(1, c.getId());
|
||||
ps.setDate(2, new java.sql.Date(millisFecha));
|
||||
ps.setFloat(3, c.getPrecio());
|
||||
ps.setBoolean(4, c.isFestival());
|
||||
ps.setInt(5, c.getIdSala());
|
||||
ps.setInt(6, c.getIdGrupo());
|
||||
registroAfectados = ps.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return registroAfectados;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
public static int eliminar(int idConcierto) {
|
||||
int registroAfectados = 0;
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"delete from concierto where id = ?");
|
||||
ps.setInt(1, idConcierto);
|
||||
registroAfectados = ps.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return registroAfectados;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idSala
|
||||
* @return
|
||||
*/
|
||||
public static List<String> findConciertosPorSalaYNombreGrupo (
|
||||
int idSala, String nombreGrupo) {
|
||||
|
||||
List<String> lista = new ArrayList<String>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"SELECT c.*, s.nombre as nombre_sala, g.nombre as nombre_grupo "
|
||||
+ "FROM concierto c "
|
||||
+ "inner join sala s on c.sala_id = s.id "
|
||||
+ "inner join grupo g on c.grupo_id = g.id "
|
||||
+ "where c.sala_id = ? "
|
||||
+ "and g.nombre like ?");
|
||||
ps.setInt(1, idSala);
|
||||
ps.setString(2, "%" + nombreGrupo + "%");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String fecha = sdf.format(rs.getDate("fecha"));
|
||||
String s = fecha + " - "
|
||||
+ rs.getString("nombre_grupo") + " - "
|
||||
+ rs.getString("nombre_sala");
|
||||
lista.add(s);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Object[][] getTotalesFestivalesPorCiudad() {
|
||||
List<Object[]> list = new ArrayList<Object[]>();
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs = s.executeQuery("select sala.ciudad as ciudad, "
|
||||
+ "count(concierto.id) as festivales "
|
||||
+ "from concierto inner join sala "
|
||||
+ "on (concierto.sala_id = sala.id) "
|
||||
+ "where concierto.es_festival = 1 "
|
||||
+ "group by sala.ciudad;");
|
||||
while (rs.next()) {
|
||||
Object fila[] = new Object[2];
|
||||
fila[0] = rs.getString("ciudad");
|
||||
fila[1] = rs.getString("festivales");
|
||||
list.add(fila);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
// Convierto la lista en una matriz
|
||||
Object m[][] = new Object[list.size()][2];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
m[i][0] = list.get(i)[0];
|
||||
m[i][1] = list.get(i)[1];
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static float getPrecioMedioConciertos() {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs =
|
||||
s.executeQuery("select avg(precio) from concierto");
|
||||
|
||||
if (rs.next()) {
|
||||
return rs.getFloat(1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getGrupoConMasConciertos() {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs =
|
||||
s.executeQuery("select count(concierto.id) as total, "
|
||||
+ "grupo.nombre "
|
||||
+ "from concierto inner join grupo "
|
||||
+ "on concierto.grupo_id = grupo.id "
|
||||
+ "group by grupo.nombre "
|
||||
+ "order by total desc limit 1");
|
||||
|
||||
if (rs.next()) {
|
||||
return rs.getString(2);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return "Error al obtener el grup con más conciertos";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package tutorialJava.examenes.examen20250509.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.modelo.Grupo;
|
||||
|
||||
public class ControladorGrupo {
|
||||
|
||||
public static List<Grupo> findAll() {
|
||||
List<Grupo> lista = new ArrayList<Grupo>();
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs = s.executeQuery("select * from grupo");
|
||||
|
||||
while (rs.next()) {
|
||||
Grupo g = new Grupo();
|
||||
g.setId(rs.getInt("id"));
|
||||
g.setNombre(rs.getString("nombre"));
|
||||
g.setEstilo(rs.getString("estilo"));
|
||||
lista.add(g);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package tutorialJava.examenes.examen20250509.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.modelo.Sala;
|
||||
|
||||
|
||||
|
||||
public class ControladorSala {
|
||||
|
||||
public static List<Sala> findAll() {
|
||||
List<Sala> lista = new ArrayList<Sala>();
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
Statement s = conn.createStatement();
|
||||
ResultSet rs = s.executeQuery("select * from sala");
|
||||
|
||||
while (rs.next()) {
|
||||
Sala sala = new Sala();
|
||||
sala.setId(rs.getInt("id"));
|
||||
sala.setNombre(rs.getString("nombre"));
|
||||
sala.setCiudad(rs.getString("ciudad"));
|
||||
sala.setAforo(rs.getInt("aforo"));
|
||||
lista.add(sala);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package tutorialJava.examenes.examen20250509.modelo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Concierto {
|
||||
private int id;
|
||||
private Date fecha;
|
||||
private float precio;
|
||||
private boolean festival;
|
||||
private int idSala;
|
||||
private int idGrupo;
|
||||
|
||||
public Concierto() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getFecha() {
|
||||
return fecha;
|
||||
}
|
||||
|
||||
public void setFecha(Date fecha) {
|
||||
this.fecha = fecha;
|
||||
}
|
||||
|
||||
public float getPrecio() {
|
||||
return precio;
|
||||
}
|
||||
|
||||
public void setPrecio(float precio) {
|
||||
this.precio = precio;
|
||||
}
|
||||
|
||||
public boolean isFestival() {
|
||||
return festival;
|
||||
}
|
||||
|
||||
public void setFestival(boolean festival) {
|
||||
this.festival = festival;
|
||||
}
|
||||
|
||||
public int getIdSala() {
|
||||
return idSala;
|
||||
}
|
||||
|
||||
public void setIdSala(int idSala) {
|
||||
this.idSala = idSala;
|
||||
}
|
||||
|
||||
public int getIdGrupo() {
|
||||
return idGrupo;
|
||||
}
|
||||
|
||||
public void setIdGrupo(int idGrupo) {
|
||||
this.idGrupo = idGrupo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Concierto [id=" + id + ", fecha=" + fecha + ", precio=" + precio + ", esFestival=" + festival
|
||||
+ ", idSala=" + idSala + ", idGrupo=" + idGrupo + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
src/tutorialJava/examenes/examen20250509/modelo/Grupo.java
Normal file
42
src/tutorialJava/examenes/examen20250509/modelo/Grupo.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package tutorialJava.examenes.examen20250509.modelo;
|
||||
|
||||
public class Grupo {
|
||||
private int id;
|
||||
private String nombre;
|
||||
private String estilo;
|
||||
|
||||
public Grupo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getEstilo() {
|
||||
return estilo;
|
||||
}
|
||||
|
||||
public void setEstilo(String estilo) {
|
||||
this.estilo = estilo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
src/tutorialJava/examenes/examen20250509/modelo/Sala.java
Normal file
51
src/tutorialJava/examenes/examen20250509/modelo/Sala.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package tutorialJava.examenes.examen20250509.modelo;
|
||||
|
||||
public class Sala {
|
||||
private int id;
|
||||
private String nombre;
|
||||
private String ciudad;
|
||||
private int aforo;
|
||||
|
||||
public Sala() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getCiudad() {
|
||||
return ciudad;
|
||||
}
|
||||
|
||||
public void setCiudad(String ciudad) {
|
||||
this.ciudad = ciudad;
|
||||
}
|
||||
|
||||
public int getAforo() {
|
||||
return aforo;
|
||||
}
|
||||
|
||||
public void setAforo(int aforo) {
|
||||
this.aforo = aforo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class PanelEstadisticas extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTable jTableDatos;
|
||||
private JLabel lblPrecioMedio;
|
||||
JLabel lblGrupoConMasConciertos;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelEstadisticas() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Estadísticas");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 15));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 2;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
jTableDatos = new JTable(getMatrizDeDatos(), getTitulosMatriz());
|
||||
scrollPane.setViewportView(jTableDatos);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("Calcular precio medio");
|
||||
btnNewButton_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
lblPrecioMedio.setText("" +
|
||||
ControladorConcierto.getPrecioMedioConciertos());
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
|
||||
gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_btnNewButton_1.gridx = 0;
|
||||
gbc_btnNewButton_1.gridy = 2;
|
||||
add(btnNewButton_1, gbc_btnNewButton_1);
|
||||
|
||||
lblPrecioMedio = new JLabel("New label");
|
||||
GridBagConstraints gbc_lblPrecioMedio = new GridBagConstraints();
|
||||
gbc_lblPrecioMedio.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblPrecioMedio.gridx = 1;
|
||||
gbc_lblPrecioMedio.gridy = 2;
|
||||
add(lblPrecioMedio, gbc_lblPrecioMedio);
|
||||
|
||||
JButton btnNewButton = new JButton("Grupo con más conciertos");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
lblGrupoConMasConciertos.setText(
|
||||
ControladorConcierto.getGrupoConMasConciertos());
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||||
gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_btnNewButton.gridx = 0;
|
||||
gbc_btnNewButton.gridy = 3;
|
||||
add(btnNewButton, gbc_btnNewButton);
|
||||
|
||||
lblGrupoConMasConciertos = new JLabel("New label");
|
||||
GridBagConstraints gbc_lblGrupoConMasConciertos = new GridBagConstraints();
|
||||
gbc_lblGrupoConMasConciertos.gridx = 1;
|
||||
gbc_lblGrupoConMasConciertos.gridy = 3;
|
||||
add(lblGrupoConMasConciertos, gbc_lblGrupoConMasConciertos);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Object[][] getMatrizDeDatos() {
|
||||
// String matriz[][] = new String[2][2];
|
||||
// matriz[0][0] = "Rafa";
|
||||
// matriz[0][1] = "Ismael";
|
||||
// matriz[1][0] = "Rubén";
|
||||
// matriz[1][1] = "Mª Jesús";
|
||||
return ControladorConcierto.getTotalesFestivalesPorCiudad();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String[] getTitulosMatriz() {
|
||||
return new String[] {"Ciudad", "Número de festivales"};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Insets;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorSala;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Sala;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JList;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class PanelFiltradoConciertos extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField jtfNombreGrupo;
|
||||
private JTextField jtfAgregar;
|
||||
JComboBox<Sala> jcbSalas;
|
||||
DefaultListModel<String> dlmConciertos =
|
||||
new DefaultListModel<String>();
|
||||
JList jlistConciertos;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelFiltradoConciertos() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Filtrado de conciertos");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 3;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Sala del concierto");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jcbSalas = new JComboBox<Sala>();
|
||||
GridBagConstraints gbc_jcbSalas = new GridBagConstraints();
|
||||
gbc_jcbSalas.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jcbSalas.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbSalas.gridx = 1;
|
||||
gbc_jcbSalas.gridy = 1;
|
||||
add(jcbSalas, gbc_jcbSalas);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Nombre del grupo:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 2;
|
||||
add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfNombreGrupo = new JTextField();
|
||||
GridBagConstraints gbc_jtfNombreGrupo = new GridBagConstraints();
|
||||
gbc_jtfNombreGrupo.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jtfNombreGrupo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfNombreGrupo.gridx = 1;
|
||||
gbc_jtfNombreGrupo.gridy = 2;
|
||||
add(jtfNombreGrupo, gbc_jtfNombreGrupo);
|
||||
jtfNombreGrupo.setColumns(10);
|
||||
|
||||
JButton btnBuscar = new JButton("Buscar");
|
||||
btnBuscar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
filtrar();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnBuscar = new GridBagConstraints();
|
||||
gbc_btnBuscar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnBuscar.gridx = 2;
|
||||
gbc_btnBuscar.gridy = 2;
|
||||
add(btnBuscar, gbc_btnBuscar);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridheight = 3;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 1;
|
||||
gbc_scrollPane.gridy = 3;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
jlistConciertos = new JList(dlmConciertos);
|
||||
scrollPane.setViewportView(jlistConciertos);
|
||||
|
||||
JButton btnEliminar = new JButton("Eliminar");
|
||||
btnEliminar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
eliminarSeleccionados();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnEliminar = new GridBagConstraints();
|
||||
gbc_btnEliminar.anchor = GridBagConstraints.SOUTH;
|
||||
gbc_btnEliminar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnEliminar.gridx = 2;
|
||||
gbc_btnEliminar.gridy = 3;
|
||||
add(btnEliminar, gbc_btnEliminar);
|
||||
|
||||
jtfAgregar = new JTextField();
|
||||
GridBagConstraints gbc_jtfAgregar = new GridBagConstraints();
|
||||
gbc_jtfAgregar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfAgregar.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfAgregar.gridx = 2;
|
||||
gbc_jtfAgregar.gridy = 4;
|
||||
add(jtfAgregar, gbc_jtfAgregar);
|
||||
jtfAgregar.setColumns(10);
|
||||
|
||||
JButton btnAgregar = new JButton("Agregar");
|
||||
btnAgregar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (jtfAgregar.getText().length() > 0) {
|
||||
dlmConciertos.addElement(jtfAgregar.getText());
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnAgregar = new GridBagConstraints();
|
||||
gbc_btnAgregar.gridx = 2;
|
||||
gbc_btnAgregar.gridy = 5;
|
||||
add(btnAgregar, gbc_btnAgregar);
|
||||
|
||||
|
||||
cargaTodasLasSalas();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargaTodasLasSalas() {
|
||||
List<Sala> salas = ControladorSala.findAll();
|
||||
for (Sala s : salas) {
|
||||
jcbSalas.addItem(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void filtrar() {
|
||||
Sala salaSeleccionada = (Sala) jcbSalas.getSelectedItem();
|
||||
List<String> conciertosFiltrados =
|
||||
ControladorConcierto.findConciertosPorSalaYNombreGrupo(
|
||||
salaSeleccionada.getId(),
|
||||
jtfNombreGrupo.getText());
|
||||
dlmConciertos.removeAllElements();
|
||||
dlmConciertos.addAll(conciertosFiltrados);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void eliminarSeleccionados() {
|
||||
int selectedIndices[] = this.jlistConciertos.getSelectedIndices();
|
||||
for (int i = selectedIndices.length - 1; i >= 0; i--) {
|
||||
System.out.println("Selected index: " + selectedIndices[i]);
|
||||
dlmConciertos.removeElementAt(selectedIndices[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,413 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.awt.event.ActionEvent;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Grupo;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Sala;
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorGrupo;
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorSala;
|
||||
|
||||
public class PanelGestionConciertos extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField jtfId;
|
||||
private JTextField jtfFecha;
|
||||
private JTextField jtfPrecio;
|
||||
JComboBox jcbGrupo;
|
||||
JComboBox jcbSala;
|
||||
JCheckBox checkEsFestival;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
JLabel lblErrorEnPrecio;
|
||||
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelGestionConciertos() {
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
add(toolBar, BorderLayout.NORTH);
|
||||
|
||||
JButton btnPrimero = new JButton("");
|
||||
btnPrimero.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Concierto c = ControladorConcierto.getPrimero();
|
||||
mostrarConciertoEnPantalla(c);
|
||||
}
|
||||
});
|
||||
btnPrimero.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnPrimero);
|
||||
|
||||
JButton btnAnterior = new JButton("");
|
||||
btnAnterior.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int idActual = Integer.parseInt(jtfId.getText());
|
||||
mostrarConciertoEnPantalla(
|
||||
ControladorConcierto.getAnterior(idActual));
|
||||
}
|
||||
});
|
||||
btnAnterior.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
||||
toolBar.add(btnAnterior);
|
||||
|
||||
JButton btnSiguiente = new JButton("");
|
||||
btnSiguiente.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int idActual = Integer.parseInt(jtfId.getText());
|
||||
mostrarConciertoEnPantalla(
|
||||
ControladorConcierto.getSiguiente(idActual));
|
||||
}
|
||||
});
|
||||
btnSiguiente.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/next.png")));
|
||||
toolBar.add(btnSiguiente);
|
||||
|
||||
JButton btnUltimo = new JButton("");
|
||||
btnUltimo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mostrarConciertoEnPantalla(ControladorConcierto.getUltimo());
|
||||
}
|
||||
});
|
||||
btnUltimo.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotoend.png")));
|
||||
toolBar.add(btnUltimo);
|
||||
|
||||
JButton btnNuevo = new JButton("");
|
||||
btnNuevo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
nuevo();
|
||||
}
|
||||
});
|
||||
btnNuevo.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/nuevo.png")));
|
||||
toolBar.add(btnNuevo);
|
||||
|
||||
JButton btnGuardar = new JButton("");
|
||||
btnGuardar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
guardar();
|
||||
}
|
||||
});
|
||||
btnGuardar.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/guardar.png")));
|
||||
toolBar.add(btnGuardar);
|
||||
|
||||
JButton btnEliminar = new JButton("");
|
||||
btnEliminar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
eliminar();
|
||||
}
|
||||
});
|
||||
btnEliminar.setIcon(new ImageIcon(PanelGestionConciertos.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/eliminar.png")));
|
||||
toolBar.add(btnEliminar);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
add(panel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Id:");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
jtfId = new JTextField();
|
||||
jtfId.setEnabled(false);
|
||||
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
||||
gbc_jtfId.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfId.gridx = 1;
|
||||
gbc_jtfId.gridy = 0;
|
||||
panel.add(jtfId, gbc_jtfId);
|
||||
jtfId.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Fecha:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
panel.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jtfFecha = new JTextField();
|
||||
GridBagConstraints gbc_jtfFecha = new GridBagConstraints();
|
||||
gbc_jtfFecha.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFecha.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFecha.gridx = 1;
|
||||
gbc_jtfFecha.gridy = 1;
|
||||
panel.add(jtfFecha, gbc_jtfFecha);
|
||||
jtfFecha.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Precio");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 2;
|
||||
panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfPrecio = new JTextField();
|
||||
GridBagConstraints gbc_jtfPrecio = new GridBagConstraints();
|
||||
gbc_jtfPrecio.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfPrecio.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfPrecio.gridx = 1;
|
||||
gbc_jtfPrecio.gridy = 2;
|
||||
panel.add(jtfPrecio, gbc_jtfPrecio);
|
||||
jtfPrecio.setColumns(10);
|
||||
|
||||
lblErrorEnPrecio = new JLabel("");
|
||||
GridBagConstraints gbc_lblErrorEnPrecio = new GridBagConstraints();
|
||||
gbc_lblErrorEnPrecio.anchor = GridBagConstraints.WEST;
|
||||
gbc_lblErrorEnPrecio.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblErrorEnPrecio.gridx = 1;
|
||||
gbc_lblErrorEnPrecio.gridy = 3;
|
||||
panel.add(lblErrorEnPrecio, gbc_lblErrorEnPrecio);
|
||||
|
||||
checkEsFestival = new JCheckBox("New check box");
|
||||
GridBagConstraints gbc_checkEsFestival = new GridBagConstraints();
|
||||
gbc_checkEsFestival.anchor = GridBagConstraints.WEST;
|
||||
gbc_checkEsFestival.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_checkEsFestival.gridx = 1;
|
||||
gbc_checkEsFestival.gridy = 4;
|
||||
panel.add(checkEsFestival, gbc_checkEsFestival);
|
||||
checkEsFestival.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
compruebaFestival();
|
||||
}
|
||||
});
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("Grupo:");
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 5;
|
||||
panel.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
jcbGrupo = new JComboBox();
|
||||
GridBagConstraints gbc_jcbGrupo = new GridBagConstraints();
|
||||
gbc_jcbGrupo.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbGrupo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbGrupo.gridx = 1;
|
||||
gbc_jcbGrupo.gridy = 5;
|
||||
panel.add(jcbGrupo, gbc_jcbGrupo);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("Sala:");
|
||||
GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_4.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblNewLabel_4.gridx = 0;
|
||||
gbc_lblNewLabel_4.gridy = 6;
|
||||
panel.add(lblNewLabel_4, gbc_lblNewLabel_4);
|
||||
|
||||
jcbSala = new JComboBox();
|
||||
GridBagConstraints gbc_jcbSala = new GridBagConstraints();
|
||||
gbc_jcbSala.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbSala.gridx = 1;
|
||||
gbc_jcbSala.gridy = 6;
|
||||
panel.add(jcbSala, gbc_jcbSala);
|
||||
|
||||
cargaTodosLosGrupos();
|
||||
cargaTodasLasSalas();
|
||||
|
||||
mostrarConciertoEnPantalla(ControladorConcierto.getPrimero());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void compruebaFestival () {
|
||||
if (checkEsFestival.isSelected()) {
|
||||
checkEsFestival.setText("Es festival");
|
||||
}
|
||||
else {
|
||||
checkEsFestival.setText("No es festival");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargaTodosLosGrupos() {
|
||||
List<Grupo> grupos = ControladorGrupo.findAll();
|
||||
for (Grupo g : grupos) {
|
||||
jcbGrupo.addItem(g);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargaTodasLasSalas() {
|
||||
List<Sala> salas = ControladorSala.findAll();
|
||||
for (Sala s : salas) {
|
||||
jcbSala.addItem(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
private void mostrarConciertoEnPantalla(Concierto c) {
|
||||
if (c != null) {
|
||||
jtfId.setText("" + c.getId());
|
||||
jtfFecha.setText(sdf.format(c.getFecha()));
|
||||
jtfPrecio.setText("" + c.getPrecio());
|
||||
|
||||
checkEsFestival.setSelected(c.isFestival());
|
||||
// if (c.isFestival()) {
|
||||
// checkEsFestival.setSelected(true);
|
||||
// }
|
||||
// else {
|
||||
// checkEsFestival.setSelected(false);
|
||||
// }
|
||||
compruebaFestival();
|
||||
|
||||
for (int i = 0; i < jcbGrupo.getItemCount(); i++) {
|
||||
Grupo grupoEnJCombo = (Grupo) jcbGrupo.getItemAt(i);
|
||||
if (grupoEnJCombo.getId() == c.getIdGrupo()) {
|
||||
jcbGrupo.setSelectedIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < jcbSala.getItemCount(); i++) {
|
||||
Sala salaEnJCombo = (Sala) jcbSala.getItemAt(i);
|
||||
if (salaEnJCombo.getId() == c.getIdSala()) {
|
||||
jcbSala.setSelectedIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void guardar() {
|
||||
Concierto c = new Concierto();
|
||||
c.setId(Integer.parseInt(jtfId.getText()));
|
||||
try {
|
||||
c.setFecha(sdf.parse(jtfFecha.getText()));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null, "El formato de la"
|
||||
+ " fecha debe ser dd/MM/yyyy");
|
||||
return;
|
||||
}
|
||||
|
||||
float precioConcierto = Float.parseFloat(jtfPrecio.getText());
|
||||
if (precioConcierto < 0 || precioConcierto >= 1000) {
|
||||
lblErrorEnPrecio.setText("Precio debe estar entre 0 y 999.99");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
lblErrorEnPrecio.setText("");
|
||||
}
|
||||
c.setPrecio(precioConcierto);
|
||||
|
||||
c.setFestival(checkEsFestival.isSelected());
|
||||
|
||||
Grupo g = (Grupo) jcbGrupo.getSelectedItem();
|
||||
c.setIdGrupo(g.getId());
|
||||
|
||||
Sala s = (Sala) jcbSala.getSelectedItem();
|
||||
c.setIdSala(s.getId());
|
||||
|
||||
int registrosAfectados = ControladorConcierto.guardar(c);
|
||||
if (registrosAfectados == 0) {
|
||||
JOptionPane.showMessageDialog(null, "Error al guardar");
|
||||
}
|
||||
else if (registrosAfectados == 1) {
|
||||
if (c.getId() == 0) { // Se trata de una inserción
|
||||
mostrarConciertoEnPantalla(ControladorConcierto.getUltimo());
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Guardado correctamente");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void nuevo() {
|
||||
jtfId.setText("0");
|
||||
jtfFecha.setText(sdf.format(new Date()));
|
||||
jtfPrecio.setText("0");
|
||||
checkEsFestival.setSelected(false);
|
||||
jcbGrupo.setSelectedIndex(0);
|
||||
jcbSala.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void eliminar() {
|
||||
String [] opciones ={"Sí","No"};
|
||||
int eleccion = JOptionPane.showOptionDialog(null,
|
||||
"¿Desea eliminar el concierto?","Eliminar concierto",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, opciones, "Sí");
|
||||
if (eleccion != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int idConcierto = Integer.parseInt(jtfId.getText());
|
||||
int registrosAfectados = ControladorConcierto.eliminar(idConcierto);
|
||||
if (registrosAfectados == 0) {
|
||||
JOptionPane.showMessageDialog(null, "Error al eliminar");
|
||||
}
|
||||
else if (registrosAfectados == 1) {
|
||||
JOptionPane.showMessageDialog(null, "Eliminado correctamente");
|
||||
|
||||
Concierto conciertoAnterior =
|
||||
ControladorConcierto.getAnterior(idConcierto);
|
||||
// Si elimino correctamente, intento mostrar el anterior
|
||||
if (conciertoAnterior != null) {
|
||||
mostrarConciertoEnPantalla(conciertoAnterior);
|
||||
}
|
||||
else { // No existe un anterior, intento mostrar el siguiente
|
||||
Concierto conciertoSiguiente =
|
||||
ControladorConcierto.getSiguiente(idConcierto);
|
||||
if (conciertoSiguiente != null) {
|
||||
mostrarConciertoEnPantalla(conciertoSiguiente);
|
||||
}
|
||||
else { // No tiene concierto anterior ni siguiente
|
||||
nuevo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import tutorialJava.examenes.examen20250616.controlador.ControladorEquipo;
|
||||
import tutorialJava.examenes.examen20250616.controlador.ControladorSocio;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Equipo;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Socio;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class PanelSociosPorEquipo extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTable table;
|
||||
private JRadioButton radioOrdenarNombre;
|
||||
JRadioButton radioOrdenarApellido1;
|
||||
JRadioButton radioOrdenarApellido2;
|
||||
JRadioButton radioOrdenarFechaNacimiento;
|
||||
JComboBox jcbEquipo;
|
||||
JScrollPane scrollPane;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelSociosPorEquipo() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de socios por equipo");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 2;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Equipo:");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 10, 5, 5);
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jcbEquipo = new JComboBox();
|
||||
jcbEquipo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarSociosEnTabla();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_jcbEquipo = new GridBagConstraints();
|
||||
gbc_jcbEquipo.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jcbEquipo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbEquipo.gridx = 1;
|
||||
gbc_jcbEquipo.gridy = 1;
|
||||
add(jcbEquipo, gbc_jcbEquipo);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.gridwidth = 2;
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 2;
|
||||
add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
// gbl_panel.columnWidths = new int[]{0, 0, 0};
|
||||
// gbl_panel.rowHeights = new int[]{0, 0, 0};
|
||||
// gbl_panel.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
// gbl_panel.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
radioOrdenarNombre = new JRadioButton("Ordenar por Nombre");
|
||||
radioOrdenarNombre.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarSociosEnTabla();
|
||||
}
|
||||
});
|
||||
radioOrdenarNombre.setSelected(true);
|
||||
GridBagConstraints gbc_radioOrdenarNombre = new GridBagConstraints();
|
||||
gbc_radioOrdenarNombre.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_radioOrdenarNombre.gridx = 0;
|
||||
gbc_radioOrdenarNombre.gridy = 0;
|
||||
panel.add(radioOrdenarNombre, gbc_radioOrdenarNombre);
|
||||
|
||||
radioOrdenarApellido1 = new JRadioButton("Ordenar por primer apellido");
|
||||
radioOrdenarApellido1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarSociosEnTabla();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_radioOrdenarApellido1 = new GridBagConstraints();
|
||||
gbc_radioOrdenarApellido1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_radioOrdenarApellido1.gridx = 1;
|
||||
gbc_radioOrdenarApellido1.gridy = 0;
|
||||
panel.add(radioOrdenarApellido1, gbc_radioOrdenarApellido1);
|
||||
|
||||
radioOrdenarApellido2 = new JRadioButton("Ordenar por segundo apellido");
|
||||
radioOrdenarApellido2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarSociosEnTabla();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_radioOrdenarApellido2 = new GridBagConstraints();
|
||||
gbc_radioOrdenarApellido2.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_radioOrdenarApellido2.gridx = 0;
|
||||
gbc_radioOrdenarApellido2.gridy = 1;
|
||||
panel.add(radioOrdenarApellido2, gbc_radioOrdenarApellido2);
|
||||
|
||||
radioOrdenarFechaNacimiento = new JRadioButton("Ordenar por fecha de nacimiento");
|
||||
radioOrdenarFechaNacimiento.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cargarSociosEnTabla();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_radioOrdenarFechaNacimiento = new GridBagConstraints();
|
||||
gbc_radioOrdenarFechaNacimiento.gridx = 1;
|
||||
gbc_radioOrdenarFechaNacimiento.gridy = 1;
|
||||
panel.add(radioOrdenarFechaNacimiento, gbc_radioOrdenarFechaNacimiento);
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 3;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
table = new JTable();
|
||||
scrollPane.setViewportView(table);
|
||||
|
||||
ButtonGroup groupOrdenacion = new ButtonGroup();
|
||||
groupOrdenacion.add(radioOrdenarNombre);
|
||||
groupOrdenacion.add(radioOrdenarApellido1);
|
||||
groupOrdenacion.add(radioOrdenarApellido2);
|
||||
groupOrdenacion.add(radioOrdenarFechaNacimiento);
|
||||
|
||||
cargarEquipos();
|
||||
cargarSociosEnTabla();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarEquipos() {
|
||||
List<Equipo> lista = ControladorEquipo.findAll();
|
||||
for (Equipo e : lista) {
|
||||
jcbEquipo.addItem(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarSociosEnTabla() {
|
||||
// Localizo el id del equipo seleccionado en el JCombo
|
||||
Equipo equipoSeleccionado = (Equipo) jcbEquipo.getSelectedItem();
|
||||
|
||||
// Localizo el campo de ordenación
|
||||
String campoOrdenacion = "";
|
||||
if (radioOrdenarNombre.isSelected()) {
|
||||
campoOrdenacion = "nombre";
|
||||
}
|
||||
else if (radioOrdenarApellido1.isSelected()) {
|
||||
campoOrdenacion = "apellido1";
|
||||
}
|
||||
else if (radioOrdenarApellido2.isSelected()) {
|
||||
campoOrdenacion = "apellido2";
|
||||
}
|
||||
else {
|
||||
campoOrdenacion = "fechaNacimiento";
|
||||
}
|
||||
|
||||
// Obtengo los socios del equipo, ordenados correctamente
|
||||
List<Socio> listaSocios = ControladorSocio.findAllByEquipoAndOrder(
|
||||
equipoSeleccionado.getId(),
|
||||
campoOrdenacion);
|
||||
|
||||
// Convierto los datos de la lista en una matriz de datos
|
||||
Object matrizSocios[][] = new Object[listaSocios.size()][4];
|
||||
for (int i = 0; i < listaSocios.size(); i++) {
|
||||
matrizSocios[i][0] = listaSocios.get(i).getNombre();
|
||||
matrizSocios[i][1] = listaSocios.get(i).getApellido1();
|
||||
matrizSocios[i][2] = listaSocios.get(i).getApellido2();
|
||||
matrizSocios[i][3] =
|
||||
sdf.format(listaSocios.get(i).getFechaNacimiento());
|
||||
}
|
||||
|
||||
// Creo un array con los títulos de las columnas
|
||||
String titulos[] = new String[] {"Nombre", "Primer apellido",
|
||||
"Segundo apellido", "Fecha nacimiento"};
|
||||
|
||||
// Creo un nuevo JTable con los datos
|
||||
table = new JTable(matrizSocios, titulos);
|
||||
table.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
JOptionPane.showMessageDialog(null, "Se ha hecho clic sobre "
|
||||
+ " el socio/a " +
|
||||
listaSocios.get(table.getSelectedRow()).getNombre() +
|
||||
" con id " +
|
||||
listaSocios.get(table.getSelectedRow()).getId());
|
||||
}
|
||||
});
|
||||
|
||||
// Muestro tabla en pantalla
|
||||
scrollPane.setViewportView(table);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Font;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
public class VentanaPrincipal extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
VentanaPrincipal frame = new VentanaPrincipal();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public VentanaPrincipal() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de conciertos");
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
contentPane.add(lblNewLabel, BorderLayout.NORTH);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
contentPane.add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
PanelGestionConciertos panel1 = new PanelGestionConciertos();
|
||||
tabbedPane.addTab("Gestión de conciertos", null, panel1, null);
|
||||
|
||||
PanelFiltradoConciertos panel2 = new PanelFiltradoConciertos();
|
||||
tabbedPane.addTab("Filtrado de conciertos", null, panel2, null);
|
||||
|
||||
PanelEstadisticas panel3 = new PanelEstadisticas();
|
||||
tabbedPane.addTab("Estadísticas", null, panel3, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package tutorialJava.examenes.examen20250616.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class ConnectionManager {
|
||||
|
||||
private static Connection conn = null;
|
||||
|
||||
|
||||
public static Connection getConnection() throws Exception {
|
||||
if (conn == null) {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
conn =
|
||||
(Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://localhost:3306/voleibol?serverTimezone=Europe/Madrid",
|
||||
"root", "1234");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package tutorialJava.examenes.examen20250616.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250616.modelo.Equipo;
|
||||
|
||||
public class ControladorEquipo {
|
||||
|
||||
public static List<Equipo> findAll () {
|
||||
List<Equipo> list = new ArrayList<Equipo>();
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"select * from equipo");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
Equipo e = new Equipo();
|
||||
e.setId(rs.getInt("id"));
|
||||
e.setDescripcion(rs.getString("descripcion"));
|
||||
list.add(e);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
package tutorialJava.examenes.examen20250616.controlador;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250616.modelo.Equipo;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Socio;
|
||||
|
||||
public class ControladorSocio {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<Socio> findAllByEquipoAndOrder (int idEquipo,
|
||||
String campoOrdenacion) {
|
||||
|
||||
List<Socio> list = new ArrayList<Socio>();
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"select * from socio where idEquipo = ? "
|
||||
+ "order by " + campoOrdenacion);
|
||||
ps.setInt(1, idEquipo);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
list.add(getSocioFromResultSet(rs));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static Socio getPrimero() {
|
||||
return getSocioFromSql("select * from socio order by id limit 1");
|
||||
}
|
||||
|
||||
public static Socio getUltimo() {
|
||||
return getSocioFromSql("select * from socio order by id desc limit 1");
|
||||
}
|
||||
|
||||
public static Socio getSiguiente(int idActual) {
|
||||
return getSocioFromSql("select * from socio "
|
||||
+ "where id > " + idActual +
|
||||
" order by id limit 1");
|
||||
}
|
||||
|
||||
public static Socio getAnterior(int idActual) {
|
||||
return getSocioFromSql("select * from socio "
|
||||
+ "where id < " + idActual +
|
||||
" order by id desc limit 1");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Socio getSocioFromSql (String sql) {
|
||||
Socio s = null;
|
||||
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
s = getSocioFromResultSet(rs);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static Socio getSocioFromResultSet (ResultSet rs) throws Exception {
|
||||
Socio s = new Socio();
|
||||
s.setId(rs.getInt("id"));
|
||||
s.setNombre(rs.getString("nombre"));
|
||||
s.setApellido1(rs.getString("apellido1"));
|
||||
s.setApellido2(rs.getString("apellido2"));
|
||||
s.setFechaNacimiento(rs.getDate("fechaNacimiento"));
|
||||
s.setAntiguedadAnios(rs.getInt("antiguedadAnios"));
|
||||
s.setActivo(rs.getBoolean("activo"));
|
||||
s.setIdEquipo(rs.getInt("idEquipo"));
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static int guardar (Socio s) {
|
||||
if (s.getId() == 0) {
|
||||
return insertar(s);
|
||||
}
|
||||
else {
|
||||
return modificar(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int modificar (Socio s) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"update socio set nombre = ?, apellido1 = ?, "
|
||||
+ "apellido2 = ?, fechaNacimiento = ?, "
|
||||
+ "antiguedadAnios = ?, activo = ?, "
|
||||
+ "idEquipo = ? "
|
||||
+ "where id = ?");
|
||||
ps.setString(1, s.getNombre());
|
||||
ps.setString(2, s.getApellido1());
|
||||
ps.setString(3, s.getApellido2());
|
||||
ps.setDate(4, new java.sql.Date(s.getFechaNacimiento().getTime()));
|
||||
ps.setInt(5, s.getAntiguedadAnios());
|
||||
ps.setBoolean(6, s.isActivo());
|
||||
ps.setInt(7, s.getIdEquipo());
|
||||
ps.setInt(8, s.getId());
|
||||
return ps.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static int insertar (Socio s) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"insert into socio (id, nombre, apellido1, apellido2,"
|
||||
+ "fechaNacimiento, antiguedadAnios, activo, idEquipo)"
|
||||
+ " values (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
ps.setInt(1, nuevoId());
|
||||
ps.setString(2, s.getNombre());
|
||||
ps.setString(3, s.getApellido1());
|
||||
ps.setString(4, s.getApellido2());
|
||||
ps.setDate(5, new java.sql.Date(s.getFechaNacimiento().getTime()));
|
||||
ps.setInt(6, s.getAntiguedadAnios());
|
||||
ps.setBoolean(7, s.isActivo());
|
||||
ps.setInt(8, s.getIdEquipo());
|
||||
return ps.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static int nuevoId () {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"select max(id) from socio");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1) + 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int eliminar (int id) {
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"delete from socio where id = ?");
|
||||
ps.setInt(1, id);
|
||||
return ps.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
33
src/tutorialJava/examenes/examen20250616/modelo/Equipo.java
Normal file
33
src/tutorialJava/examenes/examen20250616/modelo/Equipo.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package tutorialJava.examenes.examen20250616.modelo;
|
||||
|
||||
public class Equipo {
|
||||
private int id;
|
||||
private String descripcion;
|
||||
|
||||
public Equipo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
92
src/tutorialJava/examenes/examen20250616/modelo/Socio.java
Normal file
92
src/tutorialJava/examenes/examen20250616/modelo/Socio.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package tutorialJava.examenes.examen20250616.modelo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Socio {
|
||||
private int id;
|
||||
private String nombre;
|
||||
private String apellido1;
|
||||
private String apellido2;
|
||||
private Date fechaNacimiento;
|
||||
private int antiguedadAnios;
|
||||
private boolean activo;
|
||||
private int idEquipo;
|
||||
|
||||
public Socio() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellido1() {
|
||||
return apellido1;
|
||||
}
|
||||
|
||||
public void setApellido1(String apellido1) {
|
||||
this.apellido1 = apellido1;
|
||||
}
|
||||
|
||||
public String getApellido2() {
|
||||
return apellido2;
|
||||
}
|
||||
|
||||
public void setApellido2(String apellido2) {
|
||||
this.apellido2 = apellido2;
|
||||
}
|
||||
|
||||
public Date getFechaNacimiento() {
|
||||
return fechaNacimiento;
|
||||
}
|
||||
|
||||
public void setFechaNacimiento(Date fechaNacimiento) {
|
||||
this.fechaNacimiento = fechaNacimiento;
|
||||
}
|
||||
|
||||
public int getAntiguedadAnios() {
|
||||
return antiguedadAnios;
|
||||
}
|
||||
|
||||
public void setAntiguedadAnios(int antiguedadAnios) {
|
||||
this.antiguedadAnios = antiguedadAnios;
|
||||
}
|
||||
|
||||
public boolean isActivo() {
|
||||
return activo;
|
||||
}
|
||||
|
||||
public void setActivo(boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
|
||||
public int getIdEquipo() {
|
||||
return idEquipo;
|
||||
}
|
||||
|
||||
public void setIdEquipo(int idEquipo) {
|
||||
this.idEquipo = idEquipo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Socio [id=" + id + ", nombre=" + nombre + ", apellido1=" + apellido1 + ", apellido2=" + apellido2
|
||||
+ ", fechaNacimiento=" + fechaNacimiento + ", antiguedadAnios=" + antiguedadAnios + ", activo=" + activo
|
||||
+ ", idEquipo=" + idEquipo + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,438 @@
|
||||
package tutorialJava.examenes.examen20250616.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JToolBar;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
import tutorialJava.examenes.examen20250616.controlador.ControladorEquipo;
|
||||
import tutorialJava.examenes.examen20250616.controlador.ControladorSocio;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Equipo;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Socio;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
|
||||
public class PanelCRUDSocio extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField jtfNombre;
|
||||
private JTextField jtfApellido1;
|
||||
private JTextField jtfApellido2;
|
||||
private JTextField jtfFechaNacimiento;
|
||||
private JTextField jtfId;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
JSlider sliderAntiguedad;
|
||||
JLabel lblAntiguedad;
|
||||
JComboBox<Equipo> jcbEquipo;
|
||||
JCheckBox chckActivo;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelCRUDSocio() {
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
add(toolBar, BorderLayout.NORTH);
|
||||
|
||||
JButton btnPrimero = new JButton("");
|
||||
btnPrimero.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mostrarSocioEnPantalla(ControladorSocio.getPrimero());
|
||||
}
|
||||
});
|
||||
btnPrimero.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnPrimero);
|
||||
|
||||
JButton btnAnterior = new JButton("");
|
||||
btnAnterior.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int idSocioActual = Integer.parseInt(jtfId.getText());
|
||||
mostrarSocioEnPantalla(
|
||||
ControladorSocio.getAnterior(idSocioActual));
|
||||
}
|
||||
});
|
||||
btnAnterior.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
||||
toolBar.add(btnAnterior);
|
||||
|
||||
JButton btnSiguiente = new JButton("");
|
||||
btnSiguiente.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int idSocioActual = Integer.parseInt(jtfId.getText());
|
||||
mostrarSocioEnPantalla(
|
||||
ControladorSocio.getSiguiente(idSocioActual));
|
||||
}
|
||||
});
|
||||
btnSiguiente.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/next.png")));
|
||||
toolBar.add(btnSiguiente);
|
||||
|
||||
JButton btnUltimo = new JButton("");
|
||||
btnUltimo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mostrarSocioEnPantalla(ControladorSocio.getUltimo());
|
||||
}
|
||||
});
|
||||
btnUltimo.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotoend.png")));
|
||||
toolBar.add(btnUltimo);
|
||||
|
||||
JButton btnNuevo = new JButton("");
|
||||
btnNuevo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
nuevo();
|
||||
}
|
||||
});
|
||||
btnNuevo.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/nuevo.png")));
|
||||
toolBar.add(btnNuevo);
|
||||
|
||||
JButton btnGuardar = new JButton("");
|
||||
btnGuardar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
guardar();
|
||||
}
|
||||
});
|
||||
btnGuardar.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/guardar.png")));
|
||||
toolBar.add(btnGuardar);
|
||||
|
||||
JButton btnEliminar = new JButton("");
|
||||
btnEliminar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
eliminar();
|
||||
}
|
||||
});
|
||||
btnEliminar.setIcon(new ImageIcon(PanelCRUDSocio.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/eliminar.png")));
|
||||
toolBar.add(btnEliminar);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
add(panel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de socios");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 3;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_8 = new JLabel("Id:");
|
||||
GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_8.gridx = 0;
|
||||
gbc_lblNewLabel_8.gridy = 1;
|
||||
panel.add(lblNewLabel_8, gbc_lblNewLabel_8);
|
||||
|
||||
jtfId = new JTextField();
|
||||
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
||||
gbc_jtfId.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfId.gridx = 1;
|
||||
gbc_jtfId.gridy = 1;
|
||||
panel.add(jtfId, gbc_jtfId);
|
||||
jtfId.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Nombre");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 2;
|
||||
panel.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jtfNombre = new JTextField();
|
||||
GridBagConstraints gbc_jtfNombre = new GridBagConstraints();
|
||||
gbc_jtfNombre.gridwidth = 2;
|
||||
gbc_jtfNombre.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfNombre.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfNombre.gridx = 1;
|
||||
gbc_jtfNombre.gridy = 2;
|
||||
panel.add(jtfNombre, gbc_jtfNombre);
|
||||
jtfNombre.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Primer apellido:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 3;
|
||||
panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfApellido1 = new JTextField();
|
||||
GridBagConstraints gbc_jtfApellido1 = new GridBagConstraints();
|
||||
gbc_jtfApellido1.gridwidth = 2;
|
||||
gbc_jtfApellido1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfApellido1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfApellido1.gridx = 1;
|
||||
gbc_jtfApellido1.gridy = 3;
|
||||
panel.add(jtfApellido1, gbc_jtfApellido1);
|
||||
jtfApellido1.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("Segundo apellido:");
|
||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_3.gridx = 0;
|
||||
gbc_lblNewLabel_3.gridy = 4;
|
||||
panel.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||
|
||||
jtfApellido2 = new JTextField();
|
||||
GridBagConstraints gbc_jtfApellido2 = new GridBagConstraints();
|
||||
gbc_jtfApellido2.gridwidth = 2;
|
||||
gbc_jtfApellido2.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfApellido2.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfApellido2.gridx = 1;
|
||||
gbc_jtfApellido2.gridy = 4;
|
||||
panel.add(jtfApellido2, gbc_jtfApellido2);
|
||||
jtfApellido2.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_4 = new JLabel("Fecha de nacimiento:");
|
||||
GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_4.gridx = 0;
|
||||
gbc_lblNewLabel_4.gridy = 5;
|
||||
panel.add(lblNewLabel_4, gbc_lblNewLabel_4);
|
||||
|
||||
jtfFechaNacimiento = new JTextField();
|
||||
GridBagConstraints gbc_jtfFechaNacimiento = new GridBagConstraints();
|
||||
gbc_jtfFechaNacimiento.gridwidth = 2;
|
||||
gbc_jtfFechaNacimiento.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfFechaNacimiento.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfFechaNacimiento.gridx = 1;
|
||||
gbc_jtfFechaNacimiento.gridy = 5;
|
||||
panel.add(jtfFechaNacimiento, gbc_jtfFechaNacimiento);
|
||||
jtfFechaNacimiento.setColumns(10);
|
||||
|
||||
JLabel lblNewLabel_5 = new JLabel("Antigüedad (años):");
|
||||
GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_5.gridx = 0;
|
||||
gbc_lblNewLabel_5.gridy = 6;
|
||||
panel.add(lblNewLabel_5, gbc_lblNewLabel_5);
|
||||
|
||||
sliderAntiguedad = new JSlider();
|
||||
sliderAntiguedad.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (lblAntiguedad != null) {
|
||||
lblAntiguedad.setText(
|
||||
sliderAntiguedad.getValue() + " años");
|
||||
}
|
||||
}
|
||||
});
|
||||
sliderAntiguedad.setMaximum(150);
|
||||
GridBagConstraints gbc_sliderAntiguedad = new GridBagConstraints();
|
||||
gbc_sliderAntiguedad.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_sliderAntiguedad.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_sliderAntiguedad.gridx = 1;
|
||||
gbc_sliderAntiguedad.gridy = 6;
|
||||
panel.add(sliderAntiguedad, gbc_sliderAntiguedad);
|
||||
|
||||
lblAntiguedad = new JLabel("New label");
|
||||
GridBagConstraints gbc_lblAntiguedad = new GridBagConstraints();
|
||||
gbc_lblAntiguedad.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblAntiguedad.gridx = 2;
|
||||
gbc_lblAntiguedad.gridy = 6;
|
||||
panel.add(lblAntiguedad, gbc_lblAntiguedad);
|
||||
|
||||
chckActivo = new JCheckBox("Socio en activo");
|
||||
GridBagConstraints gbc_chckActivo = new GridBagConstraints();
|
||||
gbc_chckActivo.anchor = GridBagConstraints.WEST;
|
||||
gbc_chckActivo.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_chckActivo.gridx = 1;
|
||||
gbc_chckActivo.gridy = 7;
|
||||
panel.add(chckActivo, gbc_chckActivo);
|
||||
|
||||
JLabel lblNewLabel_7 = new JLabel("Equipo:");
|
||||
GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_7.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblNewLabel_7.gridx = 0;
|
||||
gbc_lblNewLabel_7.gridy = 8;
|
||||
panel.add(lblNewLabel_7, gbc_lblNewLabel_7);
|
||||
|
||||
jcbEquipo = new JComboBox<Equipo>();
|
||||
GridBagConstraints gbc_jcbEquipo = new GridBagConstraints();
|
||||
gbc_jcbEquipo.gridwidth = 2;
|
||||
gbc_jcbEquipo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbEquipo.gridx = 1;
|
||||
gbc_jcbEquipo.gridy = 8;
|
||||
panel.add(jcbEquipo, gbc_jcbEquipo);
|
||||
|
||||
cargarEquipos();
|
||||
mostrarSocioEnPantalla(ControladorSocio.getPrimero());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargarEquipos(){
|
||||
List<Equipo> lista = ControladorEquipo.findAll();
|
||||
for (Equipo e : lista) {
|
||||
this.jcbEquipo.addItem(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void mostrarSocioEnPantalla(Socio s) {
|
||||
if (s != null) {
|
||||
this.jtfId.setText("" + s.getId());
|
||||
this.jtfNombre.setText(s.getNombre());
|
||||
this.jtfApellido1.setText(s.getApellido1());
|
||||
this.jtfApellido2.setText(s.getApellido2());
|
||||
this.jtfFechaNacimiento.setText(
|
||||
sdf.format(s.getFechaNacimiento()));
|
||||
this.sliderAntiguedad.setValue(s.getAntiguedadAnios());
|
||||
|
||||
this.chckActivo.setSelected(s.isActivo());
|
||||
|
||||
for (int i = 0; i < this.jcbEquipo.getItemCount(); i++) {
|
||||
if (this.jcbEquipo.getItemAt(i).getId() == s.getIdEquipo()) {
|
||||
this.jcbEquipo.setSelectedIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Socio getSocioFromDatosDePantalla() {
|
||||
Socio s = new Socio();
|
||||
s.setId(Integer.parseInt(jtfId.getText()));
|
||||
s.setNombre(jtfNombre.getText());
|
||||
s.setApellido1(jtfApellido1.getText());
|
||||
s.setApellido2(jtfApellido2.getText());
|
||||
|
||||
try {
|
||||
s.setFechaNacimiento(sdf.parse(jtfFechaNacimiento.getText()));
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, "El formato de la fecha debe ser dd/MM/yyyy");
|
||||
}
|
||||
|
||||
s.setAntiguedadAnios(this.sliderAntiguedad.getValue());
|
||||
s.setActivo(this.chckActivo.isSelected());
|
||||
|
||||
Equipo equipoSeleccionado = (Equipo) this.jcbEquipo.getSelectedItem();
|
||||
s.setIdEquipo(equipoSeleccionado.getId());
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void guardar() {
|
||||
Socio s = getSocioFromDatosDePantalla();
|
||||
int registrosAfectados = ControladorSocio.guardar(s);
|
||||
if (registrosAfectados == 1) {
|
||||
if (s.getId() == 0) { // Hemos insertado
|
||||
mostrarSocioEnPantalla(ControladorSocio.getUltimo());
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Guardado correctamente");
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Algo ha fallado");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void nuevo() {
|
||||
this.jtfId.setText("0");
|
||||
this.jtfNombre.setText("");
|
||||
this.jtfApellido1.setText("");
|
||||
this.jtfApellido2.setText("");
|
||||
this.jtfFechaNacimiento.setText(sdf.format(new Date()));
|
||||
this.sliderAntiguedad.setValue(0);
|
||||
this.chckActivo.setSelected(false);
|
||||
this.jcbEquipo.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void eliminar() {
|
||||
String [] opciones ={"Sí","No"};
|
||||
int eleccion = JOptionPane.showOptionDialog(null,
|
||||
"¿Desea eliminar el socio?","Eliminar socio",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, opciones, "Sí");
|
||||
if (eleccion != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int idSocio = Integer.parseInt(jtfId.getText());
|
||||
int registrosAfectados = ControladorSocio.eliminar(idSocio);
|
||||
if (registrosAfectados == 0) {
|
||||
JOptionPane.showMessageDialog(null, "Error al eliminar");
|
||||
}
|
||||
else if (registrosAfectados == 1) {
|
||||
JOptionPane.showMessageDialog(null, "Eliminado correctamente");
|
||||
|
||||
Socio anterior =
|
||||
ControladorSocio.getAnterior(idSocio);
|
||||
// Si elimino correctamente, intento mostrar el anterior
|
||||
if (anterior != null) {
|
||||
mostrarSocioEnPantalla(anterior);
|
||||
}
|
||||
else { // No existe un anterior, intento mostrar el siguiente
|
||||
Socio siguiente =
|
||||
ControladorSocio.getSiguiente(idSocio);
|
||||
if (siguiente != null) {
|
||||
mostrarSocioEnPantalla(siguiente);
|
||||
}
|
||||
else { // No tiene concierto anterior ni siguiente
|
||||
nuevo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
package tutorialJava.examenes.examen20250616.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import tutorialJava.examenes.examen20250616.controlador.ControladorEquipo;
|
||||
import tutorialJava.examenes.examen20250616.modelo.Equipo;
|
||||
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
public class PanelListaEquipos extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private DefaultListModel<Equipo> dlmEquipos = new DefaultListModel<Equipo>();
|
||||
private JList list;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelListaEquipos() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de equipos de voleibol");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
list = new JList(dlmEquipos);
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
scrollPane.setViewportView(list);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 1;
|
||||
gbc_panel.gridy = 1;
|
||||
add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
// gbl_panel.columnWidths = new int[]{0, 0};
|
||||
// gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
// gbl_panel.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
// gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JButton btnResetear = new JButton("Resetear");
|
||||
btnResetear.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetear();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnResetear = new GridBagConstraints();
|
||||
gbc_btnResetear.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnResetear.gridx = 0;
|
||||
gbc_btnResetear.gridy = 0;
|
||||
panel.add(btnResetear, gbc_btnResetear);
|
||||
|
||||
JButton btnArriba = new JButton("Arriba");
|
||||
btnArriba.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
equipoArriba();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnArriba = new GridBagConstraints();
|
||||
gbc_btnArriba.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnArriba.gridx = 0;
|
||||
gbc_btnArriba.gridy = 1;
|
||||
panel.add(btnArriba, gbc_btnArriba);
|
||||
|
||||
JButton btnAbajo = new JButton("Abajo");
|
||||
btnAbajo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
equipoAbajo();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnAbajo = new GridBagConstraints();
|
||||
gbc_btnAbajo.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnAbajo.gridx = 0;
|
||||
gbc_btnAbajo.gridy = 2;
|
||||
panel.add(btnAbajo, gbc_btnAbajo);
|
||||
|
||||
JButton btnEliminar = new JButton("Eliminar");
|
||||
btnEliminar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
eliminar();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnEliminar = new GridBagConstraints();
|
||||
gbc_btnEliminar.gridx = 0;
|
||||
gbc_btnEliminar.gridy = 3;
|
||||
panel.add(btnEliminar, gbc_btnEliminar);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void resetear() {
|
||||
List<Equipo> lista = ControladorEquipo.findAll();
|
||||
dlmEquipos.removeAllElements();
|
||||
for (Equipo e : lista) {
|
||||
dlmEquipos.addElement(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void eliminar() {
|
||||
int selectedIndices[] = this.list.getSelectedIndices();
|
||||
for (int i = selectedIndices.length - 1; i >= 0; i--) {
|
||||
dlmEquipos.removeElementAt(selectedIndices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void equipoArriba() {
|
||||
int selectedIndex = this.list.getSelectedIndex();
|
||||
if (selectedIndex > 0) {
|
||||
dlmEquipos.insertElementAt(
|
||||
dlmEquipos.elementAt(selectedIndex), selectedIndex - 1);
|
||||
dlmEquipos.removeElementAt(this.list.getSelectedIndex());
|
||||
list.setSelectedIndex(selectedIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void equipoAbajo() {
|
||||
int selectedIndex = this.list.getSelectedIndex();
|
||||
if (selectedIndex < dlmEquipos.getSize() - 1) {
|
||||
dlmEquipos.insertElementAt(
|
||||
dlmEquipos.elementAt(selectedIndex), selectedIndex + 2);
|
||||
dlmEquipos.removeElementAt(this.list.getSelectedIndex());
|
||||
list.setSelectedIndex(selectedIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package tutorialJava.examenes.examen20250616.vista;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.vista.PanelSociosPorEquipo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
public class VentanaPrincipal extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
VentanaPrincipal frame = new VentanaPrincipal();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public VentanaPrincipal() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 500);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
contentPane.add(lblNewLabel, BorderLayout.NORTH);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
contentPane.add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
PanelCRUDSocio panel_2 = new PanelCRUDSocio();
|
||||
tabbedPane.addTab("Gestión de socios", null, panel_2, null);
|
||||
|
||||
PanelListaEquipos panel = new PanelListaEquipos();
|
||||
tabbedPane.addTab("Gestión de equipos", null, panel, null);
|
||||
|
||||
PanelSociosPorEquipo panel_1 = new PanelSociosPorEquipo();
|
||||
tabbedPane.addTab("Socios por equipo", null, panel_1, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package tutorialJava.examenes.examen20250619.ej01_elementosComunesEnMatriz;
|
||||
|
||||
import tutorialJava.Utils;
|
||||
import tutorialJava.UtilsArrays;
|
||||
|
||||
public class Ej02_OrdenarArrayPorDivisores {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a[] = inicializaArray();
|
||||
UtilsArrays.imprimeArray(a);
|
||||
|
||||
ordenaArrayPorDivisores(a);
|
||||
|
||||
UtilsArrays.imprimeArray(a);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static int[] inicializaArray () {
|
||||
int a[] = new int[100];
|
||||
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = Utils.obtenerNumeroAzar(0, 100);
|
||||
}
|
||||
|
||||
return a;
|
||||
// return new int[] {11, 22, 20, 12, 8};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param n
|
||||
* @return
|
||||
*/
|
||||
private static int countDivisores(int n) {
|
||||
int contadorDivisores = 0;
|
||||
for (int i = 2; i < n; i++) {
|
||||
if (n % i == 0) {
|
||||
contadorDivisores++;
|
||||
}
|
||||
}
|
||||
return contadorDivisores;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a
|
||||
*/
|
||||
private static void ordenaArrayPorDivisores (int a[]) {
|
||||
boolean hayIntercambios;
|
||||
do {
|
||||
hayIntercambios = false;
|
||||
for (int i = 0; i < (a.length - 1); i++) {
|
||||
if (countDivisores(a[i]) > countDivisores(a[i + 1])) {
|
||||
int aux = a[i];
|
||||
a[i] = a[i + 1];
|
||||
a[i + 1] = aux;
|
||||
hayIntercambios = true;
|
||||
}
|
||||
}
|
||||
} while (hayIntercambios == true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package tutorialJava.examenes.examen20250619.ej01_elementosComunesEnMatriz;
|
||||
|
||||
public class Ej03_StringDeCamelCaseASnakeCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "estoEsUnEjemplo";
|
||||
System.out.println("Cadena modificada: " + camelCaseToSnakeCase(str));
|
||||
}
|
||||
|
||||
private static String camelCaseToSnakeCase (String str) {
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
String sb = "";
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// Compruebo si es una mayúscula
|
||||
if (str.charAt(i) >= 65 && str.charAt(i) <= 90) {
|
||||
// sb.append("_");
|
||||
sb += "_";
|
||||
char minuscula = (char) (str.charAt(i) + 32);
|
||||
// sb.append(minuscula);
|
||||
sb += minuscula;
|
||||
}
|
||||
else { // No es una mayúscula
|
||||
// sb.append(str.charAt(i));
|
||||
sb += str.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package tutorialJava.examenes.examen20250619.ej01_elementosComunesEnMatriz;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import tutorialJava.Utils;
|
||||
import tutorialJava.UtilsArrays;
|
||||
|
||||
public class ElementosMasFrecuentesEnMatriz {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
int m[][] = inicializaMatriz();
|
||||
UtilsArrays.imprimeMatriz(m);
|
||||
System.out.println();
|
||||
|
||||
HashMap<Integer, Integer> hm = creaHashMapDeRepeticiones(m);
|
||||
|
||||
int mRepeticiones[][] = getMatrizRepeticionesDesdeHashMap(hm);
|
||||
UtilsArrays.imprimeMatriz(mRepeticiones);
|
||||
System.out.println();
|
||||
|
||||
ordenarMatrizRepeticiones(mRepeticiones);
|
||||
UtilsArrays.imprimeMatriz(mRepeticiones);
|
||||
|
||||
// Sacamos en consola los x que más se repiten
|
||||
int podium = 3;
|
||||
for (int i = 0; i < podium; i++) {
|
||||
System.out.println("Número más repetido: " +
|
||||
mRepeticiones[i][0] + " con " +
|
||||
mRepeticiones[i][1] + " repeticiones");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static int[][] inicializaMatriz () {
|
||||
int filas = Utils.obtenerEnteroConDescripcion(
|
||||
"Introduzca filas de la matriz: ");
|
||||
int columnas = Utils.obtenerEnteroConDescripcion(
|
||||
"Introduzca columnas de la matriz: ");
|
||||
|
||||
int m[][] = new int[filas][columnas];
|
||||
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for (int j = 0; j < m[i].length; j++) {
|
||||
m[i][j] = Utils.obtenerNumeroAzar(0, 20);
|
||||
}
|
||||
}
|
||||
// int m[][] = new int[][] {{2, 3, 4, 4},
|
||||
// {2, 3, 5, 5},
|
||||
// {5, 4, 6, 7},
|
||||
// {6, 7, 4, 5}};
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param m
|
||||
* @return
|
||||
*/
|
||||
private static HashMap<Integer, Integer>
|
||||
creaHashMapDeRepeticiones(int m[][]) {
|
||||
|
||||
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
|
||||
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for (int j = 0; j < m[i].length; j++) {
|
||||
int valorAComprobar = m[i][j];
|
||||
|
||||
// Compruebo si el valorAComprobar ya existe, o no, como
|
||||
// key del hashmap
|
||||
if (hm.get(valorAComprobar) == null) {
|
||||
// En el HashMap no hay key que tenga el "valorAComprobar"
|
||||
hm.put(valorAComprobar, 1);
|
||||
}
|
||||
else {
|
||||
// Ya existe un key de "valorAComprobar" en el hm
|
||||
int repeticionesDeValorAComprobar = hm.get(valorAComprobar);
|
||||
hm.put(valorAComprobar, repeticionesDeValorAComprobar + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hm
|
||||
* @return
|
||||
*/
|
||||
private static int[][] getMatrizRepeticionesDesdeHashMap(
|
||||
HashMap<Integer, Integer> hm) {
|
||||
|
||||
int mRepeticiones[][] = new int[hm.values().size()][2];
|
||||
|
||||
Iterator<Integer> keys = hm.keySet().iterator();
|
||||
int i = 0;
|
||||
while (keys.hasNext()) {
|
||||
int singleKey = keys.next();
|
||||
mRepeticiones[i][0] = singleKey;
|
||||
mRepeticiones[i][1] = hm.get(singleKey);
|
||||
i++;
|
||||
}
|
||||
return mRepeticiones;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param m
|
||||
*/
|
||||
private static void ordenarMatrizRepeticiones (int m[][]) {
|
||||
boolean hayIntercambios;
|
||||
|
||||
do {
|
||||
hayIntercambios = false;
|
||||
for (int i = 0; i < (m.length - 1); i++) {
|
||||
if (m[i][1] < m[i + 1][1]) {
|
||||
int aux[] = m[i];
|
||||
m[i] = m[i + 1];
|
||||
m[i + 1] = aux;
|
||||
hayIntercambios = true;
|
||||
}
|
||||
}
|
||||
} while (hayIntercambios == true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user