diff --git a/src/tutorialJava/examenes/examen20250509/vista/PanelSociosPorEquipo.java b/src/tutorialJava/examenes/examen20250509/vista/PanelSociosPorEquipo.java new file mode 100644 index 0000000..ef3ad13 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250509/vista/PanelSociosPorEquipo.java @@ -0,0 +1,111 @@ +package tutorialJava.examenes.examen20250509.vista; + +import javax.swing.JPanel; +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.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; + +public class PanelSociosPorEquipo extends JPanel { + + private static final long serialVersionUID = 1L; + private JTable table; + + /** + * 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[]{1.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, 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); + + JComboBox comboBox = new JComboBox(); + GridBagConstraints gbc_comboBox = new GridBagConstraints(); + gbc_comboBox.insets = new Insets(0, 0, 5, 0); + gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_comboBox.gridx = 1; + gbc_comboBox.gridy = 1; + add(comboBox, gbc_comboBox); + + 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); + + JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button"); + GridBagConstraints gbc_rdbtnNewRadioButton = new GridBagConstraints(); + gbc_rdbtnNewRadioButton.insets = new Insets(0, 0, 5, 5); + gbc_rdbtnNewRadioButton.gridx = 0; + gbc_rdbtnNewRadioButton.gridy = 0; + panel.add(rdbtnNewRadioButton, gbc_rdbtnNewRadioButton); + + JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("New radio button"); + GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints(); + gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 0); + gbc_rdbtnNewRadioButton_1.gridx = 1; + gbc_rdbtnNewRadioButton_1.gridy = 0; + panel.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1); + + JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("New radio button"); + GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints(); + gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 0, 5); + gbc_rdbtnNewRadioButton_2.gridx = 0; + gbc_rdbtnNewRadioButton_2.gridy = 1; + panel.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2); + + JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("New radio button"); + GridBagConstraints gbc_rdbtnNewRadioButton_3 = new GridBagConstraints(); + gbc_rdbtnNewRadioButton_3.gridx = 1; + gbc_rdbtnNewRadioButton_3.gridy = 1; + panel.add(rdbtnNewRadioButton_3, gbc_rdbtnNewRadioButton_3); + + JScrollPane 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); + + } + +} diff --git a/src/tutorialJava/examenes/examen20250616/controlador/ConnectionManager.java b/src/tutorialJava/examenes/examen20250616/controlador/ConnectionManager.java new file mode 100644 index 0000000..92a3942 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/controlador/ConnectionManager.java @@ -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; + } +} diff --git a/src/tutorialJava/examenes/examen20250616/controlador/ControladorEquipo.java b/src/tutorialJava/examenes/examen20250616/controlador/ControladorEquipo.java new file mode 100644 index 0000000..f4950b3 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/controlador/ControladorEquipo.java @@ -0,0 +1,41 @@ +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 findAll () { + List list = new ArrayList(); + + 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; + } +} + + + + + + + diff --git a/src/tutorialJava/examenes/examen20250616/modelo/Equipo.java b/src/tutorialJava/examenes/examen20250616/modelo/Equipo.java new file mode 100644 index 0000000..8f6b139 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/modelo/Equipo.java @@ -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; + } + + +} diff --git a/src/tutorialJava/examenes/examen20250616/modelo/Socio.java b/src/tutorialJava/examenes/examen20250616/modelo/Socio.java new file mode 100644 index 0000000..91fb943 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/modelo/Socio.java @@ -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 + "]"; + } + + + +} diff --git a/src/tutorialJava/examenes/examen20250616/vista/PanelListaEquipos.java b/src/tutorialJava/examenes/examen20250616/vista/PanelListaEquipos.java new file mode 100644 index 0000000..21c76c2 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/vista/PanelListaEquipos.java @@ -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 dlmEquipos = new DefaultListModel(); + 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 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); + } + } +} + + + + + + + + + + + diff --git a/src/tutorialJava/examenes/examen20250616/vista/VentanaPrincipal.java b/src/tutorialJava/examenes/examen20250616/vista/VentanaPrincipal.java new file mode 100644 index 0000000..c369269 --- /dev/null +++ b/src/tutorialJava/examenes/examen20250616/vista/VentanaPrincipal.java @@ -0,0 +1,61 @@ +package tutorialJava.examenes.examen20250616.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 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("New label"); + contentPane.add(lblNewLabel, BorderLayout.NORTH); + + JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); + contentPane.add(tabbedPane, BorderLayout.CENTER); + + PanelListaEquipos panel = new PanelListaEquipos(); + tabbedPane.addTab("Gestión de equipos", null, panel, null); + + JPanel panel_1 = new JPanel(); + tabbedPane.addTab("New tab", null, panel_1, null); + + JPanel panel_2 = new JPanel(); + tabbedPane.addTab("New tab", null, panel_2, null); + } + +}