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
19 Commits
ac7ecde4d4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4200da990 | ||
|
|
3ec83f87d6 | ||
|
|
f66e4a5dc0 | ||
|
|
8d3b26bf60 | ||
|
|
3e859f9db9 | ||
|
|
5b3b41dba0 | ||
|
|
263bd4220b | ||
|
|
dc2cbeefbe | ||
|
|
b6b59798dc | ||
|
|
f0c090da0d | ||
|
|
abf5adcfe9 | ||
|
|
8e18fb286b | ||
|
|
fbcc8026ed | ||
|
|
9ec8ab1912 | ||
|
|
7dbbed7984 | ||
|
|
738c42f160 | ||
|
|
d8c4fa5e4b | ||
|
|
c054a8c34b | ||
|
|
037db3e9a8 |
File diff suppressed because one or more lines are too long
@@ -1,42 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos;
|
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
public class JFrameKK 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 {
|
|
||||||
JFrameKK frame = new JFrameKK();
|
|
||||||
frame.setVisible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the frame.
|
|
||||||
*/
|
|
||||||
public JFrameKK() {
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setBounds(100, 100, 450, 300);
|
|
||||||
contentPane = new JPanel();
|
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
|
|
||||||
setContentPane(contentPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.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/tutorialjavacoches?serverTimezone=UTC",
|
||||||
|
"root", "1234");
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,39 +2,45 @@ package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.controlad
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.modelo.Fabricante;
|
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.modelo.Fabricante;
|
||||||
|
|
||||||
public class ControladorFabricante {
|
public class ControladorFabricante {
|
||||||
|
|
||||||
private Connection getConexion () throws Exception {
|
|
||||||
String driver = JDBCPropiedades.getProperty("JDBC_DRIVER_CLASS");
|
public static Fabricante getPrimero() {
|
||||||
String user = JDBCPropiedades.getProperty("JDBC_USER");
|
return getFabricante("Select * from fabricante order by id asc limit 1");
|
||||||
String password = JDBCPropiedades.getProperty("JDBC_PASSWORD");
|
}
|
||||||
String host = JDBCPropiedades.getProperty("JDBC_HOST");
|
|
||||||
String schema = JDBCPropiedades.getProperty("JDBC_SCHEMA_NAME");
|
public static Fabricante getUltimo() {
|
||||||
String properties = JDBCPropiedades.getProperty("JDBC_PROPERTIES");
|
return getFabricante("Select * from fabricante order by id desc limit 1");
|
||||||
|
}
|
||||||
Class.forName(driver);
|
|
||||||
|
|
||||||
Connection conexion = (Connection) DriverManager.getConnection (
|
public static Fabricante getSiguiente(int idActual) {
|
||||||
"jdbc:mysql://" + host + "/" + schema + properties,
|
return getFabricante("Select * from fabricante "
|
||||||
user, password);
|
+ "where id > " + idActual + " order by id asc limit 1");
|
||||||
|
}
|
||||||
return conexion;
|
|
||||||
|
public static Fabricante getAnterior(int idActual) {
|
||||||
|
return getFabricante("Select * from fabricante "
|
||||||
|
+ "where id < " + idActual + " order by id desc limit 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Fabricante getPrimerFabricante() {
|
public static Fabricante getFabricante(String sql) {
|
||||||
try {
|
try {
|
||||||
Connection conn = getConexion();
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
|
||||||
Statement s = conn.createStatement();
|
Statement s = conn.createStatement();
|
||||||
ResultSet rs =
|
ResultSet rs =
|
||||||
s.executeQuery("Select * from fabricante order "
|
s.executeQuery(sql);
|
||||||
+ "by id asc limit 1");
|
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
Fabricante f = new Fabricante();
|
Fabricante f = new Fabricante();
|
||||||
@@ -49,6 +55,121 @@ public class ControladorFabricante {
|
|||||||
}
|
}
|
||||||
return null;
|
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) {
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
String sql = "update tutorialjavacoches.fabricante "
|
||||||
|
+ "set nombre = ?, cif = ? "
|
||||||
|
+ "where id = ?";
|
||||||
|
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql);
|
||||||
|
ps.setString(1, f.getNombre());
|
||||||
|
ps.setString(2, f.getCif());
|
||||||
|
ps.setInt(3, f.getId());
|
||||||
|
|
||||||
|
return ps.executeUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
private static int getSiguienteIdValido(Connection conn) throws SQLException {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
ResultSet rs = s.executeQuery("select max(id) as maximoId "
|
||||||
|
+ "from fabricante");
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
return rs.getInt(1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param f
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int insertaFabricante(Fabricante f) {
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
String sql = "insert into fabricante (id, nombre, cif) "
|
||||||
|
+ "values (?, ?, ?)";
|
||||||
|
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql);
|
||||||
|
ps.setInt(1, getSiguienteIdValido(conn));
|
||||||
|
ps.setString(2, f.getNombre());
|
||||||
|
ps.setString(3, f.getCif());
|
||||||
|
|
||||||
|
return ps.executeUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.controlador;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class JDBCPropiedades {
|
|
||||||
|
|
||||||
private static Properties propiedades = null;
|
|
||||||
|
|
||||||
public JDBCPropiedades () {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static Properties getPropiedades() {
|
|
||||||
if (propiedades == null) {
|
|
||||||
propiedades = new Properties();
|
|
||||||
|
|
||||||
try {
|
|
||||||
File file = new File("./src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_Fabricante/controlador/jdbc.properties");
|
|
||||||
propiedades.load(new FileReader(file));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return propiedades;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param nombrePropiedad
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getProperty(String nombrePropiedad) {
|
|
||||||
return getPropiedades().getProperty(nombrePropiedad);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param nombrePropiedad
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int getIntProperty (String nombrePropiedad) {
|
|
||||||
return Integer.parseInt(getPropiedades().getProperty(nombrePropiedad));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param nombrePropiedad
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Float getFloatProperty (String nombrePropiedad) {
|
|
||||||
return Float.parseFloat(getPropiedades().getProperty(nombrePropiedad));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# par<61>metros de conexi<78>n a BBDD
|
|
||||||
JDBC_DRIVER_CLASS=com.mysql.cj.jdbc.Driver
|
|
||||||
JDBC_USER=root
|
|
||||||
JDBC_PASSWORD=1234
|
|
||||||
JDBC_HOST=localhost:3306
|
|
||||||
JDBC_SCHEMA_NAME=tutorialjavacoches
|
|
||||||
JDBC_PROPERTIES=?autoReconnect=true&serverTimezone=Europe/Madrid&useSSL=False&allowPublicKeyRetrieval=TRUE
|
|
||||||
@@ -11,6 +11,8 @@ import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_Fabricante.modelo.Fab
|
|||||||
|
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
@@ -27,6 +29,10 @@ public class VentanaGestionFabricante extends JFrame {
|
|||||||
private JTextField jtfId;
|
private JTextField jtfId;
|
||||||
private JTextField jtfNombre;
|
private JTextField jtfNombre;
|
||||||
private JTextField jtfCif;
|
private JTextField jtfCif;
|
||||||
|
private JButton btnPrimero;
|
||||||
|
private JButton btnAnterior;
|
||||||
|
private JButton btnSiguiente;
|
||||||
|
private JButton btnUltimo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch the application.
|
* Launch the application.
|
||||||
@@ -80,27 +86,43 @@ public class VentanaGestionFabricante extends JFrame {
|
|||||||
gbc_panel.gridy = 1;
|
gbc_panel.gridy = 1;
|
||||||
contentPane.add(panel, gbc_panel);
|
contentPane.add(panel, gbc_panel);
|
||||||
|
|
||||||
JButton btnNewButton = new JButton("Primero");
|
btnPrimero = new JButton("Primero");
|
||||||
btnNewButton.addActionListener(new ActionListener() {
|
btnPrimero.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Fabricante fab =
|
mostrarFabricanteEnPantalla(
|
||||||
new ControladorFabricante().getPrimerFabricante();
|
ControladorFabricante.getPrimero());
|
||||||
jtfId.setText("" + fab.getId());
|
|
||||||
jtfNombre.setText(fab.getNombre());
|
|
||||||
jtfCif.setText(fab.getCif());
|
|
||||||
System.out.println("Fab nombre: " + fab.getNombre());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(btnNewButton);
|
panel.add(btnPrimero);
|
||||||
|
|
||||||
JButton btnNewButton_1 = new JButton("Anterior");
|
btnAnterior = new JButton("Anterior");
|
||||||
panel.add(btnNewButton_1);
|
btnAnterior.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
mostrarFabricanteEnPantalla(
|
||||||
|
ControladorFabricante.getAnterior(
|
||||||
|
Integer.parseInt(jtfId.getText())));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(btnAnterior);
|
||||||
|
|
||||||
JButton btnNewButton_2 = new JButton("Siguiente");
|
btnSiguiente = new JButton("Siguiente");
|
||||||
panel.add(btnNewButton_2);
|
btnSiguiente.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
mostrarFabricanteEnPantalla(
|
||||||
|
ControladorFabricante.getSiguiente(
|
||||||
|
Integer.parseInt(jtfId.getText())));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(btnSiguiente);
|
||||||
|
|
||||||
JButton btnNewButton_3 = new JButton("Último");
|
btnUltimo = new JButton("Último");
|
||||||
panel.add(btnNewButton_3);
|
btnUltimo.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
mostrarFabricanteEnPantalla(
|
||||||
|
ControladorFabricante.getUltimo());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(btnUltimo);
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Id:");
|
JLabel lblNewLabel_1 = new JLabel("Id:");
|
||||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||||
@@ -111,6 +133,7 @@ public class VentanaGestionFabricante extends JFrame {
|
|||||||
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||||
|
|
||||||
jtfId = new JTextField();
|
jtfId = new JTextField();
|
||||||
|
jtfId.setEnabled(false);
|
||||||
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
GridBagConstraints gbc_jtfId = new GridBagConstraints();
|
||||||
gbc_jtfId.insets = new Insets(0, 0, 5, 0);
|
gbc_jtfId.insets = new Insets(0, 0, 5, 0);
|
||||||
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
gbc_jtfId.fill = GridBagConstraints.HORIZONTAL;
|
||||||
@@ -164,13 +187,153 @@ public class VentanaGestionFabricante extends JFrame {
|
|||||||
contentPane.add(panel_1, gbc_panel_1);
|
contentPane.add(panel_1, gbc_panel_1);
|
||||||
|
|
||||||
JButton btnNewButton_4 = new JButton("Guardar");
|
JButton btnNewButton_4 = new JButton("Guardar");
|
||||||
|
btnNewButton_4.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
guardar();
|
||||||
|
}
|
||||||
|
});
|
||||||
panel_1.add(btnNewButton_4);
|
panel_1.add(btnNewButton_4);
|
||||||
|
|
||||||
JButton btnNewButton_5 = new JButton("Nuevo");
|
JButton btnNewButton_5 = new JButton("Nuevo");
|
||||||
|
btnNewButton_5.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
nuevo();
|
||||||
|
}
|
||||||
|
});
|
||||||
panel_1.add(btnNewButton_5);
|
panel_1.add(btnNewButton_5);
|
||||||
|
|
||||||
JButton btnNewButton_6 = new JButton("Eliminar");
|
JButton btnNewButton_6 = new JButton("Eliminar");
|
||||||
|
btnNewButton_6.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
eliminar();
|
||||||
|
}
|
||||||
|
});
|
||||||
panel_1.add(btnNewButton_6);
|
panel_1.add(btnNewButton_6);
|
||||||
|
|
||||||
|
|
||||||
|
mostrarFabricanteEnPantalla(ControladorFabricante.getPrimero());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param f
|
||||||
|
*/
|
||||||
|
private void mostrarFabricanteEnPantalla(Fabricante f) {
|
||||||
|
if (f != null) {
|
||||||
|
jtfId.setText("" + f.getId());
|
||||||
|
jtfNombre.setText(f.getNombre());
|
||||||
|
jtfCif.setText(f.getCif());
|
||||||
|
|
||||||
|
// Compruebo si existe un siguiente
|
||||||
|
boolean existeSiguiente =
|
||||||
|
ControladorFabricante.getSiguiente(f.getId()) != null;
|
||||||
|
this.btnSiguiente.setEnabled(existeSiguiente);
|
||||||
|
this.btnUltimo.setEnabled(existeSiguiente);
|
||||||
|
|
||||||
|
// Compruebo si existe un anterior
|
||||||
|
boolean existeAnterior =
|
||||||
|
ControladorFabricante.getAnterior(f.getId()) != null;
|
||||||
|
this.btnAnterior.setEnabled(existeAnterior);
|
||||||
|
this.btnPrimero.setEnabled(existeAnterior);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Fabricante getDesdePantalla() {
|
||||||
|
Fabricante f = new Fabricante();
|
||||||
|
f.setId(Integer.parseInt(this.jtfId.getText()));
|
||||||
|
f.setNombre(this.jtfNombre.getText());
|
||||||
|
f.setCif(this.jtfCif.getText());
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void guardar() {
|
||||||
|
int regModificados;
|
||||||
|
|
||||||
|
Fabricante f = getDesdePantalla();
|
||||||
|
|
||||||
|
if (f.getId() == 0) { // Es una inserción
|
||||||
|
regModificados =
|
||||||
|
ControladorFabricante.insertaFabricante(getDesdePantalla());
|
||||||
|
mostrarFabricanteEnPantalla(ControladorFabricante.getUltimo());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
regModificados =
|
||||||
|
ControladorFabricante.modificaFabricante(getDesdePantalla());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regModificados > 0) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Registro modificado");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Error en la modificación");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void nuevo() {
|
||||||
|
this.jtfId.setText("0");
|
||||||
|
this.jtfNombre.setText("");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_GestionGraficaFabricante;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ConnectionManager {
|
|
||||||
|
|
||||||
private static Connection conexion = null;
|
|
||||||
|
|
||||||
|
|
||||||
public static Connection getConexion () throws SQLException {
|
|
||||||
// Si es la primera vez que accedemos a la conexión, debemos instanciarla
|
|
||||||
if (conexion == null) {
|
|
||||||
conectar();
|
|
||||||
}
|
|
||||||
// Compruebo si la conexión sigue estando activa
|
|
||||||
while (!conexion.isValid(5)) {
|
|
||||||
conectar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return conexion;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
private static void conectar () throws SQLException {
|
|
||||||
try {
|
|
||||||
// A través de la siguiente línea comprobamos si tenemos acceso al driver MySQL, si no fuera así
|
|
||||||
// no podemos trabajar con esa BBDD.
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
||||||
|
|
||||||
// Necesitamos obtener un acceso a la BBDD, eso se materializa en un objeto de tipo Connection, al cual
|
|
||||||
// le tenemos que pasar los parámetros de conexión.
|
|
||||||
conexion = (Connection) DriverManager.getConnection (
|
|
||||||
"jdbc:mysql://localhost:3310/tutorialjavacoches?serverTimezone=UTC",
|
|
||||||
"root",
|
|
||||||
"1234");
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex) {
|
|
||||||
System.out.println("Imposible acceder al driver Mysql");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_GestionGraficaFabricante;
|
|
||||||
|
|
||||||
public class Fabricante {
|
|
||||||
private int id;
|
|
||||||
private String cif;
|
|
||||||
private String nombre;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Fabricante() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @param cif
|
|
||||||
* @param nombre
|
|
||||||
*/
|
|
||||||
public Fabricante(int id, String cif, String nombre) {
|
|
||||||
super();
|
|
||||||
this.id = id;
|
|
||||||
this.cif = cif;
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
public String getCif() {
|
|
||||||
return cif;
|
|
||||||
}
|
|
||||||
public void setCif(String cif) {
|
|
||||||
this.cif = cif;
|
|
||||||
}
|
|
||||||
public String getNombre() {
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
public void setNombre(String nombre) {
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_GestionGraficaFabricante;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
public class GestionFabricante extends SupertipoGestion {
|
|
||||||
|
|
||||||
public static Fabricante getPrimero(Connection conn) throws SQLException {
|
|
||||||
return getFabricante (conn,
|
|
||||||
"select * from tutorialjavacoches.fabricante "
|
|
||||||
+ "order by id asc limit 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Fabricante getUltimo(Connection conn) throws SQLException {
|
|
||||||
return getFabricante(conn,
|
|
||||||
"select * from tutorialjavacoches.fabricante "
|
|
||||||
+ "order by id desc limit 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Fabricante getAnterior(Connection conn, int idActual) throws SQLException {
|
|
||||||
String sql = "select * from tutorialjavacoches.fabricante where id < " + idActual
|
|
||||||
+ " order by id desc limit 1";
|
|
||||||
// System.out.println("sql: " + sql);
|
|
||||||
return getFabricante (conn, sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Fabricante getSiguiente(Connection conn, int idActual) throws SQLException {
|
|
||||||
return getFabricante (conn,
|
|
||||||
"select * from tutorialjavacoches.fabricante where id > " + idActual
|
|
||||||
+ " order by id asc limit 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Fabricante getFabricante(Connection conn, String sql) throws SQLException {
|
|
||||||
Statement s = conn.createStatement();
|
|
||||||
ResultSet rs = s.executeQuery(sql);
|
|
||||||
|
|
||||||
Fabricante f = null;
|
|
||||||
if (rs.next()) {
|
|
||||||
f = new Fabricante();
|
|
||||||
f.setId(rs.getInt("id"));
|
|
||||||
f.setCif(rs.getString("cif"));
|
|
||||||
f.setNombre(rs.getString("nombre"));
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static int insercion (Fabricante f, Connection conn) {
|
|
||||||
try {
|
|
||||||
int nuevoId = nextIdEnTabla("fabricante");
|
|
||||||
PreparedStatement ps = conn.prepareStatement(""
|
|
||||||
+ "insert into fabricante (id, cif, nombre) "
|
|
||||||
+ "values (?, ?, ?)");
|
|
||||||
ps.setInt(1, nuevoId);
|
|
||||||
ps.setString(2, f.getCif());
|
|
||||||
ps.setString(3, f.getNombre());
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
|
||||||
return nuevoId;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static void modificacion (Fabricante f, Connection conn) {
|
|
||||||
try {
|
|
||||||
PreparedStatement ps = conn.prepareStatement(""
|
|
||||||
+ "update fabricante set cif = ?, nombre = ? "
|
|
||||||
+ "where id = ?");
|
|
||||||
ps.setString(1, f.getCif());
|
|
||||||
ps.setString(2, f.getNombre());
|
|
||||||
ps.setInt(3, f.getId());
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static void eliminacion (int id, Connection conn) {
|
|
||||||
try {
|
|
||||||
PreparedStatement ps = conn.prepareStatement(""
|
|
||||||
+ "delete fabricante where id = ?");
|
|
||||||
ps.setInt(1, id);
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_GestionGraficaFabricante;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class SupertipoGestion {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param nombreTabla
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected static int nextIdEnTabla(String nombreTabla) {
|
|
||||||
try {
|
|
||||||
Statement s = ConnectionManager.getConexion().createStatement();
|
|
||||||
ResultSet rs = s.executeQuery("Select max(id) from " + nombreTabla);
|
|
||||||
|
|
||||||
if (rs.next()) {
|
|
||||||
return rs.getInt(1) + 1;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,381 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo01_GestionGraficaFabricante;
|
|
||||||
|
|
||||||
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 javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
|
|
||||||
public class VentanaFabricante extends JFrame {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private JPanel contentPane;
|
|
||||||
private JTextField jtfId;
|
|
||||||
private JTextField jtfCif;
|
|
||||||
private JTextField jtfNombre;
|
|
||||||
private JPanel panel;
|
|
||||||
private JButton btnPrimero;
|
|
||||||
private JButton btnAnterior;
|
|
||||||
private JButton btnSiguiente;
|
|
||||||
private JButton btnUltimo;
|
|
||||||
private JButton btnNuevo;
|
|
||||||
private JButton btnGuardar;
|
|
||||||
private JButton btnEliminar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch the application.
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
VentanaFabricante frame = new VentanaFabricante();
|
|
||||||
frame.setVisible(true);
|
|
||||||
frame.cargarPrimero();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the frame.
|
|
||||||
*/
|
|
||||||
public VentanaFabricante() {
|
|
||||||
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};
|
|
||||||
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, 1.0, Double.MIN_VALUE};
|
|
||||||
contentPane.setLayout(gbl_contentPane);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Gestión de fabricantes");
|
|
||||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 17));
|
|
||||||
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;
|
|
||||||
contentPane.add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Id:");
|
|
||||||
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);
|
|
||||||
|
|
||||||
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 = 1;
|
|
||||||
contentPane.add(jtfId, gbc_jtfId);
|
|
||||||
jtfId.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_2 = new JLabel("CIF:");
|
|
||||||
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);
|
|
||||||
|
|
||||||
jtfCif = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfCif = new GridBagConstraints();
|
|
||||||
gbc_jtfCif.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_jtfCif.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfCif.gridx = 1;
|
|
||||||
gbc_jtfCif.gridy = 2;
|
|
||||||
contentPane.add(jtfCif, gbc_jtfCif);
|
|
||||||
jtfCif.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_3 = new JLabel("Nombre:");
|
|
||||||
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);
|
|
||||||
|
|
||||||
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 = 3;
|
|
||||||
contentPane.add(jtfNombre, gbc_jtfNombre);
|
|
||||||
jtfNombre.setColumns(10);
|
|
||||||
|
|
||||||
panel = new JPanel();
|
|
||||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
||||||
gbc_panel.gridwidth = 2;
|
|
||||||
gbc_panel.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panel.gridx = 0;
|
|
||||||
gbc_panel.gridy = 4;
|
|
||||||
contentPane.add(panel, gbc_panel);
|
|
||||||
|
|
||||||
btnPrimero = new JButton("");
|
|
||||||
btnPrimero.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cargarPrimero();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnPrimero.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
|
||||||
panel.add(btnPrimero);
|
|
||||||
|
|
||||||
btnAnterior = new JButton("");
|
|
||||||
btnAnterior.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cargarAnterior();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnAnterior.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
|
||||||
panel.add(btnAnterior);
|
|
||||||
|
|
||||||
btnSiguiente = new JButton("");
|
|
||||||
btnSiguiente.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cargarSiguiente();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnSiguiente.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/next.png")));
|
|
||||||
panel.add(btnSiguiente);
|
|
||||||
|
|
||||||
btnUltimo = new JButton("");
|
|
||||||
btnUltimo.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cargarUltimo();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnUltimo.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotoend.png")));
|
|
||||||
panel.add(btnUltimo);
|
|
||||||
|
|
||||||
btnNuevo = new JButton("");
|
|
||||||
btnNuevo.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
nuevo();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnNuevo.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/nuevo.png")));
|
|
||||||
panel.add(btnNuevo);
|
|
||||||
|
|
||||||
btnGuardar = new JButton("");
|
|
||||||
btnGuardar.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
guardar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnGuardar.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/guardar.png")));
|
|
||||||
panel.add(btnGuardar);
|
|
||||||
|
|
||||||
btnEliminar = new JButton("");
|
|
||||||
btnEliminar.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
eliminar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnEliminar.setIcon(new ImageIcon(VentanaFabricante.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/eliminar.png")));
|
|
||||||
panel.add(btnEliminar);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarPrimero () {
|
|
||||||
try {
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
Fabricante f = GestionFabricante.getPrimero(conn);
|
|
||||||
cargaFabricanteEnPantalla(f);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarAnterior () {
|
|
||||||
try {
|
|
||||||
String strIdActual = jtfId.getText();
|
|
||||||
if (!strIdActual.trim().equals("")) {
|
|
||||||
int idActual = Integer.parseInt(strIdActual);
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
Fabricante f = GestionFabricante.getAnterior(conn, idActual);
|
|
||||||
cargaFabricanteEnPantalla(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarUltimo () {
|
|
||||||
try {
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
Fabricante f = GestionFabricante.getUltimo(conn);
|
|
||||||
cargaFabricanteEnPantalla(f);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarSiguiente () {
|
|
||||||
try {
|
|
||||||
String strIdActual = jtfId.getText();
|
|
||||||
if (!strIdActual.trim().equals("")) {
|
|
||||||
int idActual = Integer.parseInt(strIdActual);
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
Fabricante f = GestionFabricante.getSiguiente(conn, idActual);
|
|
||||||
cargaFabricanteEnPantalla(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param f
|
|
||||||
*/
|
|
||||||
private void cargaFabricanteEnPantalla(Fabricante f) {
|
|
||||||
if (f != null) {
|
|
||||||
jtfId.setText("" + f.getId());
|
|
||||||
jtfCif.setText(f.getCif());
|
|
||||||
jtfNombre.setText(f.getNombre());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void nuevo() {
|
|
||||||
this.jtfId.setText("");
|
|
||||||
this.jtfCif.setText("");
|
|
||||||
this.jtfNombre.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void guardar() {
|
|
||||||
try {
|
|
||||||
Fabricante f = new Fabricante();
|
|
||||||
|
|
||||||
f.setId(-1);
|
|
||||||
if (!this.jtfId.getText().trim().equals("")) { // El id tiene número
|
|
||||||
f.setId(Integer.parseInt(this.jtfId.getText()));
|
|
||||||
}
|
|
||||||
f.setCif(this.jtfCif.getText());
|
|
||||||
f.setNombre(this.jtfNombre.getText());
|
|
||||||
|
|
||||||
// Decido si debo insertar o modificar
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
if (f.getId() == -1) { // Inserción
|
|
||||||
int nuevoId = GestionFabricante.insercion(f, conn);
|
|
||||||
this.jtfId.setText("" + nuevoId);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
GestionFabricante.modificacion(f, conn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void eliminar () {
|
|
||||||
try {
|
|
||||||
String respuestas[] = new String[] {"Sí", "No"};
|
|
||||||
int opcionElegida = JOptionPane.showOptionDialog(
|
|
||||||
null,
|
|
||||||
"¿Realmente desea eliminar el registro?",
|
|
||||||
"Eliminación de fabricante",
|
|
||||||
JOptionPane.DEFAULT_OPTION,
|
|
||||||
JOptionPane.WARNING_MESSAGE,
|
|
||||||
null, respuestas,
|
|
||||||
respuestas[1]);
|
|
||||||
|
|
||||||
if(opcionElegida == 0) {
|
|
||||||
if (!this.jtfId.getText().trim().equals("")) {
|
|
||||||
int idActual = Integer.parseInt(this.jtfId.getText());
|
|
||||||
Connection conn = ConnectionManager.getConexion();
|
|
||||||
GestionFabricante.eliminacion(idActual, conn);
|
|
||||||
|
|
||||||
// Decido qué registro voy a mostrar en pantalla.
|
|
||||||
// Voy a comprobar si existe un anterior, si existe lo muestro
|
|
||||||
// Si no existe anterior compruebo si existe siguiente,
|
|
||||||
// si existe lo muestro. En caso contrario, no quedan registros
|
|
||||||
// así que muestro en blanco la pantalla
|
|
||||||
Fabricante fabriAMostrar = GestionFabricante.getAnterior(conn, idActual);
|
|
||||||
if (fabriAMostrar != null) { // Existe un anterior, lo muestro
|
|
||||||
cargaFabricanteEnPantalla(fabriAMostrar);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fabriAMostrar = GestionFabricante.getSiguiente(conn, idActual);
|
|
||||||
if (fabriAMostrar != null) { // Existe un siguiente
|
|
||||||
cargaFabricanteEnPantalla(fabriAMostrar);
|
|
||||||
}
|
|
||||||
else { // No quedan registros en la tabla
|
|
||||||
nuevo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JTabbedPane;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista.PanelCurso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista.PanelEstudiante;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista.PanelMateria;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista.PanelValoracionMateriaOpcion1;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.utils.Apariencia;
|
|
||||||
|
|
||||||
public class Principal extends JFrame {
|
|
||||||
|
|
||||||
// Establecer la apariencia típica de Windows
|
|
||||||
static {
|
|
||||||
Apariencia.setAparienciasOrdenadas(Apariencia.aparienciasOrdenadas);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Principal() {
|
|
||||||
super("Gestión de centro educativo");
|
|
||||||
|
|
||||||
this.setBounds(0, 0, 800, 600);
|
|
||||||
|
|
||||||
PanelCurso panelCurso = new PanelCurso();
|
|
||||||
PanelMateria panelMateria = new PanelMateria();
|
|
||||||
|
|
||||||
JTabbedPane panelTabbed = new JTabbedPane();
|
|
||||||
panelTabbed.addTab("Cursos", panelCurso);
|
|
||||||
panelTabbed.addTab("Materias", panelMateria);
|
|
||||||
panelTabbed.addTab("Estudiantes", new PanelEstudiante());
|
|
||||||
panelTabbed.addTab("Valoración Materia", new PanelValoracionMateriaOpcion1());
|
|
||||||
panelTabbed.setSelectedIndex(0);
|
|
||||||
|
|
||||||
this.getContentPane().add(panelTabbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Principal ventana = new Principal();
|
|
||||||
ventana.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ConnectionManager {
|
|
||||||
|
|
||||||
private static Connection conexion = null;
|
|
||||||
|
|
||||||
|
|
||||||
public static Connection getConexion () throws SQLException {
|
|
||||||
// Si es la primera vez que accedemos a la conexión, debemos instanciarla
|
|
||||||
if (conexion == null) {
|
|
||||||
conectar();
|
|
||||||
}
|
|
||||||
// Compruebo si la conexión sigue estando activa
|
|
||||||
while (!conexion.isValid(5)) {
|
|
||||||
conectar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return conexion;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
private static void conectar () throws SQLException {
|
|
||||||
try {
|
|
||||||
// A través de la siguiente línea comprobamos si tenemos acceso al driver MySQL, si no fuera así
|
|
||||||
// no podemos trabajar con esa BBDD.
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
||||||
|
|
||||||
// Necesitamos obtener un acceso a la BBDD, eso se materializa en un objeto de tipo Connection, al cual
|
|
||||||
// le tenemos que pasar los parámetros de conexión.
|
|
||||||
conexion = (Connection) DriverManager.getConnection (
|
|
||||||
"jdbc:mysql://localhost:3310/centroeducativo?serverTimezone=UTC",
|
|
||||||
"root",
|
|
||||||
"1234");
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex) {
|
|
||||||
System.out.println("Imposible acceder al driver Mysql");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
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.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
|
|
||||||
|
|
||||||
public class ControladorCurso {
|
|
||||||
|
|
||||||
private static String nombreTabla = "centroeducativo.curso";
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Curso> getTodos() {
|
|
||||||
List<Curso> l = new ArrayList<Curso>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = ConnectionManager.getConexion().createStatement()
|
|
||||||
.executeQuery("Select * from " + nombreTabla);
|
|
||||||
while (rs.next()) {
|
|
||||||
Curso o = getEntidadFromResultSet(rs);
|
|
||||||
l.add(o);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Curso getPrimero() {
|
|
||||||
try {
|
|
||||||
return getEntidad (ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla
|
|
||||||
+ " order by id asc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Curso getUltimo() {
|
|
||||||
try {
|
|
||||||
return getEntidad(ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla
|
|
||||||
+ " order by id desc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Curso getAnterior(int idActual) {
|
|
||||||
try {
|
|
||||||
String sql = "select * from " + nombreTabla + " where id < " + idActual
|
|
||||||
+ " order by id desc limit 1";
|
|
||||||
return getEntidad (ConnectionManager.getConexion(), sql);
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Curso getSiguiente(int idActual) {
|
|
||||||
try {
|
|
||||||
return getEntidad (ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla + " where id > " + idActual
|
|
||||||
+ " order by id asc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Curso getEntidad(Connection conn, String sql) throws SQLException {
|
|
||||||
Statement s = conn.createStatement();
|
|
||||||
ResultSet rs = s.executeQuery(sql);
|
|
||||||
|
|
||||||
Curso o = null;
|
|
||||||
if (rs.next()) {
|
|
||||||
o = getEntidadFromResultSet(rs);
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static Curso getEntidadFromResultSet (ResultSet rs) throws SQLException {
|
|
||||||
Curso o = new Curso();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setDescripcion(rs.getString("descripcion"));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
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.ejemplo02_GestionCentroEducativo.entitidades.Estudiante;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ControladorEstudiante {
|
|
||||||
|
|
||||||
private static String nombreTabla = "estudiante";
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Estudiante> getTodos() {
|
|
||||||
List<Estudiante> l = new ArrayList<Estudiante>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = ConnectionManager.getConexion().createStatement()
|
|
||||||
.executeQuery("Select * from " + nombreTabla);
|
|
||||||
while (rs.next()) {
|
|
||||||
Estudiante o = getEntidadFromResultSet(rs);
|
|
||||||
l.add(o);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Estudiante getEntidadFromResultSet (ResultSet rs) throws SQLException {
|
|
||||||
Estudiante o = new Estudiante();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setNombre(rs.getString("nombre"));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
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.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Materia;
|
|
||||||
|
|
||||||
|
|
||||||
public class ControladorMateria {
|
|
||||||
|
|
||||||
private static String nombreTabla = "centroeducativo.materia";
|
|
||||||
|
|
||||||
public static Materia getPrimero() {
|
|
||||||
try {
|
|
||||||
return getEntidad (ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla
|
|
||||||
+ " order by id asc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Materia getUltimo() {
|
|
||||||
try {
|
|
||||||
return getEntidad(ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla
|
|
||||||
+ " order by id desc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Materia getAnterior(int idActual) {
|
|
||||||
try {
|
|
||||||
String sql = "select * from " + nombreTabla + " where id < " + idActual
|
|
||||||
+ " order by id desc limit 1";
|
|
||||||
return getEntidad (ConnectionManager.getConexion(), sql);
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Materia getSiguiente(int idActual) {
|
|
||||||
try {
|
|
||||||
return getEntidad (ConnectionManager.getConexion(),
|
|
||||||
"select * from " + nombreTabla + " where id > " + idActual
|
|
||||||
+ " order by id asc limit 1");
|
|
||||||
}
|
|
||||||
catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Materia> getTodos() {
|
|
||||||
List<Materia> l = new ArrayList<Materia>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = ConnectionManager.getConexion().createStatement()
|
|
||||||
.executeQuery("Select * from " + nombreTabla);
|
|
||||||
while (rs.next()) {
|
|
||||||
Materia o = getEntidadFromResultSet(rs);
|
|
||||||
l.add(o);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Materia getEntidadFromResultSet (ResultSet rs) throws SQLException {
|
|
||||||
Materia o = new Materia();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setCursoId(rs.getInt("curso_id"));
|
|
||||||
o.setAcronimo(rs.getString("acronimo"));
|
|
||||||
o.setNombre(rs.getString("nombre"));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Materia getEntidad(Connection conn, String sql) throws SQLException {
|
|
||||||
Statement s = conn.createStatement();
|
|
||||||
ResultSet rs = s.executeQuery(sql);
|
|
||||||
|
|
||||||
Materia o = null;
|
|
||||||
if (rs.next()) {
|
|
||||||
o = new Materia();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setCursoId(rs.getInt("curso_id"));
|
|
||||||
o.setAcronimo(rs.getString("acronimo"));
|
|
||||||
o.setNombre(rs.getString("nombre"));
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
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.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Materia;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Profesor;
|
|
||||||
|
|
||||||
|
|
||||||
public class ControladorProfesor {
|
|
||||||
|
|
||||||
private static String nombreTabla = "profesor";
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Profesor> getTodos() {
|
|
||||||
List<Profesor> l = new ArrayList<Profesor>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = ConnectionManager.getConexion().createStatement()
|
|
||||||
.executeQuery("Select * from " + nombreTabla);
|
|
||||||
while (rs.next()) {
|
|
||||||
Profesor o = getEntidadFromResultSet(rs);
|
|
||||||
l.add(o);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Profesor getEntidadFromResultSet (ResultSet rs) throws SQLException {
|
|
||||||
Profesor o = new Profesor();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setNombre(rs.getString("nombre"));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
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.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.ValoracionMateria;
|
|
||||||
|
|
||||||
|
|
||||||
public class ControladorValoracionMateria {
|
|
||||||
|
|
||||||
private static String nombreTabla = "valoracionmateria";
|
|
||||||
|
|
||||||
|
|
||||||
public static ValoracionMateria findByIdMateriaAndIdProfesorAndIdEstudiante(
|
|
||||||
int idMateria, int idProfesor, int idEstudiante) {
|
|
||||||
|
|
||||||
ValoracionMateria v = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
PreparedStatement ps = ConnectionManager.getConexion().prepareStatement(
|
|
||||||
"select * from " + nombreTabla + " where idProfesor = ? and"
|
|
||||||
+ " idMateria = ? and idEstudiante = ? limit 1 ");
|
|
||||||
|
|
||||||
ps.setInt(1, idProfesor);
|
|
||||||
ps.setInt(2, idMateria);
|
|
||||||
ps.setInt(3, idEstudiante);
|
|
||||||
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
if (rs.next()) {
|
|
||||||
v = getEntidadFromResultSet(rs);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param rs
|
|
||||||
* @return
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
private static ValoracionMateria getEntidadFromResultSet (ResultSet rs) throws SQLException {
|
|
||||||
ValoracionMateria o = new ValoracionMateria();
|
|
||||||
o.setId(rs.getInt("id"));
|
|
||||||
o.setIdEstudiante(rs.getInt("idEstudiante"));
|
|
||||||
o.setIdMateria(rs.getInt("idMateria"));
|
|
||||||
o.setIdProfesor(rs.getInt("idProfesor"));
|
|
||||||
o.setValoracion(rs.getFloat("valoracion"));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores;
|
|
||||||
|
|
||||||
public class SuperControlador {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades;
|
|
||||||
|
|
||||||
public class Estudiante {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String nombre;
|
|
||||||
|
|
||||||
public Estudiante() {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades;
|
|
||||||
|
|
||||||
public class Materia {
|
|
||||||
private int id;
|
|
||||||
private int cursoId;
|
|
||||||
private String nombre;
|
|
||||||
private String acronimo;
|
|
||||||
|
|
||||||
|
|
||||||
public Materia() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Materia(int id, int cursoId, String nombre, String acronimo) {
|
|
||||||
super();
|
|
||||||
this.id = id;
|
|
||||||
this.cursoId = cursoId;
|
|
||||||
this.nombre = nombre;
|
|
||||||
this.acronimo = acronimo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getCursoId() {
|
|
||||||
return cursoId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setCursoId(int cursoId) {
|
|
||||||
this.cursoId = cursoId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getNombre() {
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setNombre(String nombre) {
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getAcronimo() {
|
|
||||||
return acronimo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setAcronimo(String acronimo) {
|
|
||||||
this.acronimo = acronimo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades;
|
|
||||||
|
|
||||||
public class ValoracionMateria {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private int idProfesor;
|
|
||||||
private int idMateria;
|
|
||||||
private int idEstudiante;
|
|
||||||
private float valoracion;
|
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
public int getIdProfesor() {
|
|
||||||
return idProfesor;
|
|
||||||
}
|
|
||||||
public void setIdProfesor(int idProfesor) {
|
|
||||||
this.idProfesor = idProfesor;
|
|
||||||
}
|
|
||||||
public int getIdMateria() {
|
|
||||||
return idMateria;
|
|
||||||
}
|
|
||||||
public void setIdMateria(int idMateria) {
|
|
||||||
this.idMateria = idMateria;
|
|
||||||
}
|
|
||||||
public int getIdEstudiante() {
|
|
||||||
return idEstudiante;
|
|
||||||
}
|
|
||||||
public void setIdEstudiante(int idEstudiante) {
|
|
||||||
this.idEstudiante = idEstudiante;
|
|
||||||
}
|
|
||||||
public float getValoracion() {
|
|
||||||
return valoracion;
|
|
||||||
}
|
|
||||||
public void setValoracion(float valoracion) {
|
|
||||||
this.valoracion = valoracion;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ValoracionMateria [id=" + id + ", idProfesor=" + idProfesor + ", idMateria=" + idMateria
|
|
||||||
+ ", idEstudiante=" + idEstudiante + ", valoracion=" + valoracion + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import javax.swing.JToolBar;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorCurso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Font;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
|
|
||||||
public class PanelCurso extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private JTextField jtfId;
|
|
||||||
private JTextField jtfDescripcion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelCurso() {
|
|
||||||
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) {
|
|
||||||
cargarPrimero();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnPrimero.setIcon(new ImageIcon(PanelCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
|
||||||
toolBar.add(btnPrimero);
|
|
||||||
|
|
||||||
JButton btnAnterior = new JButton("");
|
|
||||||
btnAnterior.setIcon(new ImageIcon(PanelCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
|
||||||
toolBar.add(btnAnterior);
|
|
||||||
|
|
||||||
JButton btnSiguiente = new JButton("");
|
|
||||||
btnSiguiente.setIcon(new ImageIcon(PanelCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/next.png")));
|
|
||||||
toolBar.add(btnSiguiente);
|
|
||||||
|
|
||||||
JButton btnUltimo = new JButton("");
|
|
||||||
btnUltimo.setIcon(new ImageIcon(PanelCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotoend.png")));
|
|
||||||
toolBar.add(btnUltimo);
|
|
||||||
|
|
||||||
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};
|
|
||||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Gestión de Curso");
|
|
||||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 17));
|
|
||||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_lblNewLabel.gridwidth = 2;
|
|
||||||
gbc_lblNewLabel.gridx = 0;
|
|
||||||
gbc_lblNewLabel.gridy = 0;
|
|
||||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_2 = new JLabel("Id:");
|
|
||||||
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 = 1;
|
|
||||||
panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
|
||||||
|
|
||||||
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 = 1;
|
|
||||||
panel.add(jtfId, gbc_jtfId);
|
|
||||||
jtfId.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Descripción:");
|
|
||||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_lblNewLabel_1.gridx = 0;
|
|
||||||
gbc_lblNewLabel_1.gridy = 2;
|
|
||||||
panel.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
|
||||||
|
|
||||||
jtfDescripcion = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfDescripcion = new GridBagConstraints();
|
|
||||||
gbc_jtfDescripcion.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfDescripcion.gridx = 1;
|
|
||||||
gbc_jtfDescripcion.gridy = 2;
|
|
||||||
panel.add(jtfDescripcion, gbc_jtfDescripcion);
|
|
||||||
jtfDescripcion.setColumns(10);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarPrimero() {
|
|
||||||
Curso o = ControladorCurso.getPrimero();
|
|
||||||
muestraEnPantalla(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void muestraEnPantalla(Curso o) {
|
|
||||||
if (o != null) {
|
|
||||||
this.jtfId.setText("" + o.getId());
|
|
||||||
this.jtfDescripcion.setText(o.getDescripcion());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import javax.swing.JToolBar;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
|
|
||||||
public class PanelDatosPersonales extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private JTextField jtfId;
|
|
||||||
private JTextField jtfNombre;
|
|
||||||
private JLabel lblTitulo;
|
|
||||||
private Runnable runnableMostrarPrimerRegistro;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelDatosPersonales() {
|
|
||||||
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) {
|
|
||||||
runnableMostrarPrimerRegistro.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnPrimero.setIcon(new ImageIcon(PanelDatosPersonales.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
|
||||||
toolBar.add(btnPrimero);
|
|
||||||
|
|
||||||
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};
|
|
||||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
|
|
||||||
lblTitulo = new JLabel("Título del componente");
|
|
||||||
lblTitulo.setFont(new Font("Tahoma", Font.BOLD, 17));
|
|
||||||
GridBagConstraints gbc_lblTitulo = new GridBagConstraints();
|
|
||||||
gbc_lblTitulo.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_lblTitulo.gridwidth = 2;
|
|
||||||
gbc_lblTitulo.gridx = 0;
|
|
||||||
gbc_lblTitulo.gridy = 0;
|
|
||||||
panel.add(lblTitulo, gbc_lblTitulo);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Id:");
|
|
||||||
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;
|
|
||||||
panel.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
|
||||||
|
|
||||||
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;
|
|
||||||
panel.add(jtfId, gbc_jtfId);
|
|
||||||
jtfId.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_2 = new JLabel("Nombre:");
|
|
||||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_lblNewLabel_2.gridx = 0;
|
|
||||||
gbc_lblNewLabel_2.gridy = 2;
|
|
||||||
panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
|
||||||
|
|
||||||
jtfNombre = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfNombre = new GridBagConstraints();
|
|
||||||
gbc_jtfNombre.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfNombre.gridx = 1;
|
|
||||||
gbc_jtfNombre.gridy = 2;
|
|
||||||
panel.add(jtfNombre, gbc_jtfNombre);
|
|
||||||
jtfNombre.setColumns(10);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param newTitulo
|
|
||||||
*/
|
|
||||||
public void setTitulo(String newTitulo) {
|
|
||||||
this.lblTitulo.setText(newTitulo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
public void setId (int id) {
|
|
||||||
this.jtfId.setText("" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public int getId () {
|
|
||||||
return Integer.parseInt(this.jtfId.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Runnable getRunnableMostrarPrimerRegistro() {
|
|
||||||
return runnableMostrarPrimerRegistro;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRunnableMostrarPrimerRegistro(Runnable runnableMostrarPrimerRegistro) {
|
|
||||||
this.runnableMostrarPrimerRegistro = runnableMostrarPrimerRegistro;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Estudiante;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
|
|
||||||
public class PanelEstudiante extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private PanelDatosPersonales panelDatos = new PanelDatosPersonales();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelEstudiante() {
|
|
||||||
setLayout(new BorderLayout(0, 0));
|
|
||||||
this.add(panelDatos, BorderLayout.CENTER);
|
|
||||||
this.panelDatos.setTitulo("Gestión de estudiantes");
|
|
||||||
|
|
||||||
this.panelDatos.setRunnableMostrarPrimerRegistro(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mostrarPrimero();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void mostrarPrimero() {
|
|
||||||
// En teoría aquí se produce una llamada a un controlador de estudiante
|
|
||||||
// que obtiene un objeto de tipo estudiante y que lo envía para ser
|
|
||||||
// mostrado
|
|
||||||
Estudiante mockEstudiante = new Estudiante();
|
|
||||||
mockEstudiante.setId(1);
|
|
||||||
mockEstudiante.setNombre("Rafa");
|
|
||||||
mostrarEntidad(mockEstudiante);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void mostrarEntidad(Estudiante e) {
|
|
||||||
this.panelDatos.setId(e.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import javax.swing.JToolBar;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorCurso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorMateria;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Curso;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Materia;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Font;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
|
|
||||||
public class PanelMateria extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private JTextField jtfId;
|
|
||||||
private JTextField jtfAcronimo;
|
|
||||||
private JTextField jtfNombre;
|
|
||||||
private JComboBox<Curso> jcbCurso;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelMateria() {
|
|
||||||
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) {
|
|
||||||
cargarPrimero();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnPrimero.setIcon(new ImageIcon(PanelMateria.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) {
|
|
||||||
System.out.println("Curso id seleccionado: " +
|
|
||||||
((Curso) jcbCurso.getSelectedItem()).getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
btnAnterior.setIcon(new ImageIcon(PanelMateria.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
|
||||||
toolBar.add(btnAnterior);
|
|
||||||
|
|
||||||
JButton btnSiguiente = new JButton("");
|
|
||||||
btnSiguiente.setIcon(new ImageIcon(PanelMateria.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/next.png")));
|
|
||||||
toolBar.add(btnSiguiente);
|
|
||||||
|
|
||||||
JButton btnUltimo = new JButton("");
|
|
||||||
btnUltimo.setIcon(new ImageIcon(PanelMateria.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotoend.png")));
|
|
||||||
toolBar.add(btnUltimo);
|
|
||||||
|
|
||||||
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};
|
|
||||||
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, Double.MIN_VALUE};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Gestión de Materia");
|
|
||||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 17));
|
|
||||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_lblNewLabel.gridwidth = 2;
|
|
||||||
gbc_lblNewLabel.gridx = 0;
|
|
||||||
gbc_lblNewLabel.gridy = 0;
|
|
||||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_2 = new JLabel("Id:");
|
|
||||||
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 = 1;
|
|
||||||
panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
|
||||||
|
|
||||||
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 = 1;
|
|
||||||
panel.add(jtfId, gbc_jtfId);
|
|
||||||
jtfId.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Curso:");
|
|
||||||
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);
|
|
||||||
|
|
||||||
jcbCurso = new JComboBox<Curso>();
|
|
||||||
GridBagConstraints gbc_jcbCurso = new GridBagConstraints();
|
|
||||||
gbc_jcbCurso.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_jcbCurso.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jcbCurso.gridx = 1;
|
|
||||||
gbc_jcbCurso.gridy = 2;
|
|
||||||
panel.add(jcbCurso, gbc_jcbCurso);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_3 = new JLabel("Acrónimo:");
|
|
||||||
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel_3.anchor = GridBagConstraints.ABOVE_BASELINE_TRAILING;
|
|
||||||
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_lblNewLabel_3.gridx = 0;
|
|
||||||
gbc_lblNewLabel_3.gridy = 3;
|
|
||||||
panel.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
|
||||||
|
|
||||||
jtfAcronimo = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfAcronimo = new GridBagConstraints();
|
|
||||||
gbc_jtfAcronimo.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_jtfAcronimo.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfAcronimo.gridx = 1;
|
|
||||||
gbc_jtfAcronimo.gridy = 3;
|
|
||||||
panel.add(jtfAcronimo, gbc_jtfAcronimo);
|
|
||||||
jtfAcronimo.setColumns(10);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_4 = new JLabel("Nombre:");
|
|
||||||
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 = 4;
|
|
||||||
panel.add(lblNewLabel_4, gbc_lblNewLabel_4);
|
|
||||||
|
|
||||||
jtfNombre = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfNombre = new GridBagConstraints();
|
|
||||||
gbc_jtfNombre.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfNombre.gridx = 1;
|
|
||||||
gbc_jtfNombre.gridy = 4;
|
|
||||||
panel.add(jtfNombre, gbc_jtfNombre);
|
|
||||||
jtfNombre.setColumns(10);
|
|
||||||
|
|
||||||
// Cargo todos los cursos en el jcombo
|
|
||||||
cargarTodosCursos();
|
|
||||||
cargarPrimero();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void cargarTodosCursos () {
|
|
||||||
List<Curso> l = ControladorCurso.getTodos();
|
|
||||||
|
|
||||||
for (Curso o : l) {
|
|
||||||
jcbCurso.addItem(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarPrimero() {
|
|
||||||
Materia o = ControladorMateria.getPrimero();
|
|
||||||
muestraEnPantalla(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void muestraEnPantalla(Materia o) {
|
|
||||||
if (o != null) {
|
|
||||||
this.jtfId.setText("" + o.getId());
|
|
||||||
for (int i = 0; i < jcbCurso.getItemCount(); i++) {
|
|
||||||
if (jcbCurso.getItemAt(i).getId() == o.getCursoId()) {
|
|
||||||
jcbCurso.setSelectedIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.jtfAcronimo.setText(o.getAcronimo());
|
|
||||||
this.jtfNombre.setText(o.getNombre());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorValoracionMateria;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Estudiante;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Materia;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Profesor;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.ValoracionMateria;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Insets;
|
|
||||||
|
|
||||||
public class PanelSlotEvaluacionEstudiante extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private JTextField jtfValoracion;
|
|
||||||
private Profesor profesor;
|
|
||||||
private Materia materia;
|
|
||||||
private Estudiante estudiante;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelSlotEvaluacionEstudiante(Profesor p, Estudiante e, Materia m) {
|
|
||||||
this.profesor = p;
|
|
||||||
this.estudiante = e;
|
|
||||||
this.materia = m;
|
|
||||||
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
JLabel lblNombreEstudiante = new JLabel("New label");
|
|
||||||
GridBagConstraints gbc_lblNombreEstudiante = new GridBagConstraints();
|
|
||||||
gbc_lblNombreEstudiante.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_lblNombreEstudiante.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblNombreEstudiante.gridx = 0;
|
|
||||||
gbc_lblNombreEstudiante.gridy = 0;
|
|
||||||
add(lblNombreEstudiante, gbc_lblNombreEstudiante);
|
|
||||||
|
|
||||||
jtfValoracion = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfValoracion = new GridBagConstraints();
|
|
||||||
gbc_jtfValoracion.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfValoracion.gridx = 1;
|
|
||||||
gbc_jtfValoracion.gridy = 0;
|
|
||||||
add(jtfValoracion, gbc_jtfValoracion);
|
|
||||||
jtfValoracion.setColumns(10);
|
|
||||||
|
|
||||||
|
|
||||||
// Establezco valores iniciales
|
|
||||||
lblNombreEstudiante.setText(this.estudiante.getNombre());
|
|
||||||
cargarNotaActual();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void cargarNotaActual() {
|
|
||||||
ValoracionMateria v =
|
|
||||||
ControladorValoracionMateria.findByIdMateriaAndIdProfesorAndIdEstudiante(
|
|
||||||
this.materia.getId(), this.profesor.getId(), this.estudiante.getId());
|
|
||||||
|
|
||||||
if (v != null) {
|
|
||||||
this.jtfValoracion.setText("" + v.getValoracion());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void guardarNota() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.vista;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorEstudiante;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorMateria;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores.ControladorProfesor;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Estudiante;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Materia;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades.Profesor;
|
|
||||||
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
|
|
||||||
public class PanelValoracionMateriaOpcion1 extends JPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
JComboBox<Materia> jcbMateria;
|
|
||||||
JComboBox<Profesor> jcbProfesor;
|
|
||||||
JPanel panelEstudiantes;
|
|
||||||
List<PanelSlotEvaluacionEstudiante> listaSlotsValoracion = new ArrayList<PanelSlotEvaluacionEstudiante>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelValoracionMateriaOpcion1() {
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
JPanel panelProfesorMateria = new JPanel();
|
|
||||||
GridBagConstraints gbc_panelProfesorMateria = new GridBagConstraints();
|
|
||||||
gbc_panelProfesorMateria.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_panelProfesorMateria.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panelProfesorMateria.gridx = 0;
|
|
||||||
gbc_panelProfesorMateria.gridy = 0;
|
|
||||||
add(panelProfesorMateria, gbc_panelProfesorMateria);
|
|
||||||
GridBagLayout gbl_panelProfesorMateria = new GridBagLayout();
|
|
||||||
gbl_panelProfesorMateria.columnWidths = new int[]{0, 0, 0, 0};
|
|
||||||
gbl_panelProfesorMateria.rowHeights = new int[]{0, 0, 0, 0};
|
|
||||||
gbl_panelProfesorMateria.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
|
||||||
gbl_panelProfesorMateria.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
||||||
panelProfesorMateria.setLayout(gbl_panelProfesorMateria);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Materia:");
|
|
||||||
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;
|
|
||||||
panelProfesorMateria.add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
|
|
||||||
jcbMateria = new JComboBox<Materia>();
|
|
||||||
GridBagConstraints gbc_jcbMateria = new GridBagConstraints();
|
|
||||||
gbc_jcbMateria.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_jcbMateria.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jcbMateria.gridx = 1;
|
|
||||||
gbc_jcbMateria.gridy = 0;
|
|
||||||
panelProfesorMateria.add(jcbMateria, gbc_jcbMateria);
|
|
||||||
|
|
||||||
JLabel lblNewLabel_1 = new JLabel("Profesor:");
|
|
||||||
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;
|
|
||||||
panelProfesorMateria.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
|
||||||
|
|
||||||
jcbProfesor = new JComboBox<Profesor>();
|
|
||||||
GridBagConstraints gbc_jcbProfesor = new GridBagConstraints();
|
|
||||||
gbc_jcbProfesor.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_jcbProfesor.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jcbProfesor.gridx = 1;
|
|
||||||
gbc_jcbProfesor.gridy = 1;
|
|
||||||
panelProfesorMateria.add(jcbProfesor, gbc_jcbProfesor);
|
|
||||||
|
|
||||||
JButton btnRefrescar = new JButton("Refrescar");
|
|
||||||
btnRefrescar.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
refrescarEstudiantes();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
GridBagConstraints gbc_btnRefrescar = new GridBagConstraints();
|
|
||||||
gbc_btnRefrescar.gridx = 2;
|
|
||||||
gbc_btnRefrescar.gridy = 2;
|
|
||||||
panelProfesorMateria.add(btnRefrescar, gbc_btnRefrescar);
|
|
||||||
|
|
||||||
panelEstudiantes = new JPanel();
|
|
||||||
GridBagConstraints gbc_panelEstudiantes = new GridBagConstraints();
|
|
||||||
gbc_panelEstudiantes.weighty = 1.0;
|
|
||||||
gbc_panelEstudiantes.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_panelEstudiantes.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panelEstudiantes.gridx = 0;
|
|
||||||
gbc_panelEstudiantes.gridy = 1;
|
|
||||||
add(panelEstudiantes, gbc_panelEstudiantes);
|
|
||||||
panelEstudiantes.setLayout(new BoxLayout(panelEstudiantes, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
JButton btnGuardar = new JButton("Guardar");
|
|
||||||
btnGuardar.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
guardar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
|
|
||||||
gbc_btnGuardar.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_btnGuardar.gridx = 0;
|
|
||||||
gbc_btnGuardar.gridy = 2;
|
|
||||||
add(btnGuardar, gbc_btnGuardar);
|
|
||||||
|
|
||||||
|
|
||||||
cargarTodasMaterias();
|
|
||||||
cargarTodProfesores();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void cargarTodasMaterias() {
|
|
||||||
List<Materia> l = ControladorMateria.getTodos();
|
|
||||||
for (Materia m : l) {
|
|
||||||
this.jcbMateria.addItem(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void cargarTodProfesores() {
|
|
||||||
List<Profesor> l = ControladorProfesor.getTodos();
|
|
||||||
for (Profesor p : l) {
|
|
||||||
this.jcbProfesor.addItem(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void refrescarEstudiantes() {
|
|
||||||
List<Estudiante> l = ControladorEstudiante.getTodos();
|
|
||||||
Profesor profSeleccionado = (Profesor) this.jcbProfesor.getSelectedItem();
|
|
||||||
Materia matSeleccionada = (Materia) this.jcbMateria.getSelectedItem();
|
|
||||||
|
|
||||||
this.panelEstudiantes.removeAll();
|
|
||||||
this.listaSlotsValoracion.clear();
|
|
||||||
|
|
||||||
for(Estudiante e : l) {
|
|
||||||
PanelSlotEvaluacionEstudiante slot =
|
|
||||||
new PanelSlotEvaluacionEstudiante(profSeleccionado, e, matSeleccionada);
|
|
||||||
|
|
||||||
this.listaSlotsValoracion.add(slot);
|
|
||||||
|
|
||||||
this.panelEstudiantes.add(slot);
|
|
||||||
}
|
|
||||||
this.panelEstudiantes.revalidate();
|
|
||||||
this.panelEstudiantes.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void guardar() {
|
|
||||||
for(PanelSlotEvaluacionEstudiante panel : this.listaSlotsValoracion) {
|
|
||||||
panel.guardarNota();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemploPanelDentroDeDialogo;
|
|
||||||
|
|
||||||
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.JComboBox;
|
|
||||||
|
|
||||||
public class PanelDentroDeDialogo extends JPanel {
|
|
||||||
private JTextField textField;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelDentroDeDialogo() {
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("New label");
|
|
||||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_lblNewLabel.gridx = 0;
|
|
||||||
gbc_lblNewLabel.gridy = 0;
|
|
||||||
add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
|
|
||||||
textField = new JTextField();
|
|
||||||
GridBagConstraints gbc_textField = new GridBagConstraints();
|
|
||||||
gbc_textField.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_textField.gridx = 0;
|
|
||||||
gbc_textField.gridy = 1;
|
|
||||||
add(textField, gbc_textField);
|
|
||||||
textField.setColumns(10);
|
|
||||||
|
|
||||||
JComboBox comboBox = new JComboBox();
|
|
||||||
GridBagConstraints gbc_comboBox = new GridBagConstraints();
|
|
||||||
gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_comboBox.gridx = 0;
|
|
||||||
gbc_comboBox.gridy = 2;
|
|
||||||
add(comboBox, gbc_comboBox);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemploPanelDentroDeDialogo;
|
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JDialog;
|
|
||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
|
|
||||||
public class VentanaPrincipal extends JFrame {
|
|
||||||
|
|
||||||
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);
|
|
||||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
|
||||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
|
||||||
gbl_contentPane.rowHeights = new int[]{0, 0};
|
|
||||||
gbl_contentPane.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
gbl_contentPane.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
contentPane.setLayout(gbl_contentPane);
|
|
||||||
|
|
||||||
JButton btnNewButton = new JButton("New button");
|
|
||||||
btnNewButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
abrirNuevoDialogo();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
|
||||||
gbc_btnNewButton.gridx = 0;
|
|
||||||
gbc_btnNewButton.gridy = 0;
|
|
||||||
contentPane.add(btnNewButton, gbc_btnNewButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void abrirNuevoDialogo() {
|
|
||||||
JDialog dialogo = new JDialog();
|
|
||||||
// El usuario no puede redimensionar el di<64>logo
|
|
||||||
dialogo.setResizable(true);
|
|
||||||
// t<>tulo del d<>alogo
|
|
||||||
dialogo.setTitle("Gestión de empresas");
|
|
||||||
// Introducimos el panel creado sobre el di<64>logo
|
|
||||||
dialogo.setContentPane(new PanelDentroDeDialogo());
|
|
||||||
// Empaquetar el di<64>logo hace que todos los componentes ocupen el espacio que deben y el lugar adecuado
|
|
||||||
dialogo.pack();
|
|
||||||
// El usuario no puede hacer clic sobre la ventana padre, si el Di<44>logo es modal
|
|
||||||
dialogo.setModal(true);
|
|
||||||
// Centro el di<64>logo en pantalla
|
|
||||||
dialogo.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width)/2 - dialogo.getWidth()/2,
|
|
||||||
(Toolkit.getDefaultToolkit().getScreenSize().height)/2 - dialogo.getHeight()/2);
|
|
||||||
// Muestro el di<64>logo en pantalla
|
|
||||||
dialogo.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes;
|
|
||||||
|
|
||||||
import javax.swing.Action;
|
|
||||||
import javax.swing.Icon;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
|
|
||||||
public class MiJRadioButtonKk extends JRadioButton {
|
|
||||||
|
|
||||||
int idDisciplina;
|
|
||||||
|
|
||||||
public MiJRadioButtonKk() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(int idDisciplina) {
|
|
||||||
this.idDisciplina = idDisciplina;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(Icon icon) {
|
|
||||||
super(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(Action a) {
|
|
||||||
super(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(String text) {
|
|
||||||
super(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(Icon icon, boolean selected) {
|
|
||||||
super(icon, selected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(String text, boolean selected) {
|
|
||||||
super(text, selected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(String text, Icon icon) {
|
|
||||||
super(text, icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MiJRadioButtonKk(String text, Icon icon, boolean selected) {
|
|
||||||
super(text, icon, selected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdDisciplina() {
|
|
||||||
return idDisciplina;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdDisciplina(int idDisciplina) {
|
|
||||||
this.idDisciplina = idDisciplina;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.controller;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.Persistence;
|
|
||||||
import javax.persistence.Query;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.model.Est;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class EstudianteControlador {
|
|
||||||
|
|
||||||
private static EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("CentroEducativo");
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Est> findAll() {
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
Query q = em.createNativeQuery("SELECT * FROM estudiante;", Est.class);
|
|
||||||
List<Est> l = (List<Est>) q.getResultList();
|
|
||||||
|
|
||||||
em.close();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.model;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import javax.persistence.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The persistent class for the estudiante database table.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
@Table(name="estudiante")
|
|
||||||
@NamedQuery(name="Est.findAll", query="SELECT e FROM Est e")
|
|
||||||
public class Est implements Serializable {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
private String apellido1;
|
|
||||||
|
|
||||||
private String apellido2;
|
|
||||||
|
|
||||||
private String direccion;
|
|
||||||
|
|
||||||
private String dni;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private int idTipologiaSexo;
|
|
||||||
|
|
||||||
@Lob
|
|
||||||
private byte[] imagen;
|
|
||||||
|
|
||||||
private String nombre;
|
|
||||||
|
|
||||||
private String telefono;
|
|
||||||
|
|
||||||
public Est() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApellido1() {
|
|
||||||
return this.apellido1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApellido1(String apellido1) {
|
|
||||||
this.apellido1 = apellido1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApellido2() {
|
|
||||||
return this.apellido2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApellido2(String apellido2) {
|
|
||||||
this.apellido2 = apellido2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDireccion() {
|
|
||||||
return this.direccion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDireccion(String direccion) {
|
|
||||||
this.direccion = direccion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDni() {
|
|
||||||
return this.dni;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDni(String dni) {
|
|
||||||
this.dni = dni;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return this.email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdTipologiaSexo() {
|
|
||||||
return this.idTipologiaSexo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdTipologiaSexo(int idTipologiaSexo) {
|
|
||||||
this.idTipologiaSexo = idTipologiaSexo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getImagen() {
|
|
||||||
return this.imagen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImagen(byte[] imagen) {
|
|
||||||
this.imagen = imagen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNombre() {
|
|
||||||
return this.nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNombre(String nombre) {
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTelefono() {
|
|
||||||
return this.telefono;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTelefono(String telefono) {
|
|
||||||
this.telefono = telefono;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.view;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.model.Est;
|
|
||||||
|
|
||||||
public class PanelGestionEstudiante extends JPanel {
|
|
||||||
private JTextField jtfId;
|
|
||||||
private JTextField jtfNombre;
|
|
||||||
private JTextField jtfApellido1;
|
|
||||||
private JTextField jtfApellido2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the panel.
|
|
||||||
*/
|
|
||||||
public PanelGestionEstudiante() {
|
|
||||||
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, 0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
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;
|
|
||||||
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 = 0;
|
|
||||||
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 = 1;
|
|
||||||
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 = 1;
|
|
||||||
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 = 2;
|
|
||||||
add(lblNewLabel_2, gbc_lblNewLabel_2);
|
|
||||||
|
|
||||||
jtfApellido1 = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfApellido1 = new GridBagConstraints();
|
|
||||||
gbc_jtfApellido1.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_jtfApellido1.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfApellido1.gridx = 1;
|
|
||||||
gbc_jtfApellido1.gridy = 2;
|
|
||||||
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, 0, 5);
|
|
||||||
gbc_lblNewLabel_3.gridx = 0;
|
|
||||||
gbc_lblNewLabel_3.gridy = 3;
|
|
||||||
add(lblNewLabel_3, gbc_lblNewLabel_3);
|
|
||||||
|
|
||||||
jtfApellido2 = new JTextField();
|
|
||||||
GridBagConstraints gbc_jtfApellido2 = new GridBagConstraints();
|
|
||||||
gbc_jtfApellido2.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_jtfApellido2.gridx = 1;
|
|
||||||
gbc_jtfApellido2.gridy = 3;
|
|
||||||
add(jtfApellido2, gbc_jtfApellido2);
|
|
||||||
jtfApellido2.setColumns(10);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setEstudiante(Est e) {
|
|
||||||
this.jtfId.setText("" + e.getId());
|
|
||||||
this.jtfNombre.setText(e.getNombre());
|
|
||||||
this.jtfApellido1.setText(e.getApellido1());
|
|
||||||
this.jtfApellido2.setText(e.getApellido2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.view;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.controller.EstudianteControlador;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.model.Est;
|
|
||||||
|
|
||||||
public class Tabla extends JPanel {
|
|
||||||
|
|
||||||
List<Est> estudiantes = new ArrayList<Est>();
|
|
||||||
JTable table = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Tabla () {
|
|
||||||
//Creo un objeto JTable con el constructor m<>s sencillo del que dispone
|
|
||||||
table = new JTable(getDatosDeTabla(),
|
|
||||||
new String[] {"Id", "Nombre", "Primer apellido", "Segundo apellido"});
|
|
||||||
//Creamos un JscrollPane y le agregamos la JTable
|
|
||||||
JScrollPane scrollPane = new JScrollPane(table);
|
|
||||||
|
|
||||||
// Accedo a los clics realizados sobre la tabla
|
|
||||||
table.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
super.mouseClicked(e);
|
|
||||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
VentanaPrincipal.getInstance().getPanelGestionEstudiante()
|
|
||||||
.setEstudiante(estudiantes.get(table.getSelectedRow()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Agregamos el JScrollPane al contenedor
|
|
||||||
this.setLayout(new BorderLayout());
|
|
||||||
this.add(scrollPane, BorderLayout.CENTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Object[][] getDatosDeTabla() {
|
|
||||||
estudiantes = EstudianteControlador.findAll();
|
|
||||||
|
|
||||||
Object[][] matrizDatos = new Object[estudiantes.size()][4];
|
|
||||||
|
|
||||||
for (int i = 0; i < estudiantes.size(); i++) {
|
|
||||||
matrizDatos[i][0] = estudiantes.get(i).getId();
|
|
||||||
matrizDatos[i][1] = estudiantes.get(i).getNombre();
|
|
||||||
matrizDatos[i][2] = estudiantes.get(i).getApellido1();
|
|
||||||
matrizDatos[i][3] = estudiantes.get(i).getApellido2();
|
|
||||||
}
|
|
||||||
|
|
||||||
return matrizDatos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.view;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.controller.EstudianteControlador;
|
|
||||||
import tutorialJava.capitulo9_AWT_SWING.ejemplos.jTableEstudiantes.model.Est;
|
|
||||||
|
|
||||||
import javax.swing.JSplitPane;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
|
|
||||||
public class VentanaPrincipal extends JFrame {
|
|
||||||
|
|
||||||
private JPanel contentPane;
|
|
||||||
private PanelGestionEstudiante panelGestionEstudiante = new PanelGestionEstudiante();
|
|
||||||
private Tabla tabla = new Tabla();
|
|
||||||
|
|
||||||
private static VentanaPrincipal singleton = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static VentanaPrincipal getInstance() {
|
|
||||||
if (singleton == null) {
|
|
||||||
singleton = new VentanaPrincipal();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch the application.
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
EstudianteControlador.findAll();
|
|
||||||
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
VentanaPrincipal.getInstance().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);
|
|
||||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
|
||||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
|
||||||
gbl_contentPane.rowHeights = new int[]{0, 0};
|
|
||||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
contentPane.setLayout(gbl_contentPane);
|
|
||||||
|
|
||||||
JSplitPane splitPane = new JSplitPane();
|
|
||||||
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
|
||||||
GridBagConstraints gbc_splitPane = new GridBagConstraints();
|
|
||||||
gbc_splitPane.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_splitPane.gridx = 0;
|
|
||||||
gbc_splitPane.gridy = 0;
|
|
||||||
contentPane.add(splitPane, gbc_splitPane);
|
|
||||||
|
|
||||||
tabla.setMinimumSize(new Dimension(100, 100));
|
|
||||||
splitPane.setLeftComponent(tabla);
|
|
||||||
// splitPane.setDividerLocation(0.7);
|
|
||||||
|
|
||||||
splitPane.setRightComponent(panelGestionEstudiante);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public PanelGestionEstudiante getPanelGestionEstudiante() {
|
|
||||||
return panelGestionEstudiante;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,8 @@ public class Menu extends JMenuBar {
|
|||||||
// Menú Archivo de la aplicación
|
// Menú Archivo de la aplicación
|
||||||
JMenu menuArchivo = new JMenu("Archivo");
|
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");
|
JMenu menuExportar = new JMenu("Exportar");
|
||||||
menuExportar.add(crearNuevoMenuItem("Como Word", "ruedadentada.png", KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())));
|
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");
|
Connection conexion = (Connection) DriverManager.getConnection ("jdbc:mysql://localhost/centroeducativo?serverTimezone=UTC","java", "Abcdefgh.1");
|
||||||
|
|
||||||
PreparedStatement ps = (PreparedStatement) conexion.
|
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.setBytes(1, imagenEnArrayDeBytes);
|
||||||
ps.setInt(2, 1);
|
ps.setInt(2, 1);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
|
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorProvincia;
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.ProvinciaControlador;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||||
|
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
|
|
||||||
@@ -24,11 +24,11 @@ public class PanelJList extends JPanel {
|
|||||||
|
|
||||||
// Elemento JList a utilizar en el ejemplo
|
// Elemento JList a utilizar en el ejemplo
|
||||||
private JList jlistProvincias;
|
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;
|
private DefaultListModel<Provincia> listModelProvincias = null;
|
||||||
// Lista de todas las provincias de la BBDD, para incluir en el elemento JList
|
// Lista de todas las provincias de la BBDD, para incluir en el elemento JList
|
||||||
private List<Provincia> provincias = ProvinciaControlador.getControlador().findAllProvincias();
|
private List<Provincia> provincias = ControladorProvincia.findAll();
|
||||||
// <EFBFBD>ndice de la <EFBFBD>ltima provincia agregada, para saber cu<EFBFBD>l debe ser la siguiente provincia a agregar
|
// Ìndice de la última provincia agregada, para saber cuál debe ser la siguiente provincia a agregar
|
||||||
private int indiceProximaProvinciaParaAgregar = 0;
|
private int indiceProximaProvinciaParaAgregar = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,8 +50,8 @@ public class PanelJList extends JPanel {
|
|||||||
gbc_lblEjemploDeUso.gridy = 0;
|
gbc_lblEjemploDeUso.gridy = 0;
|
||||||
add(lblEjemploDeUso, gbc_lblEjemploDeUso);
|
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
|
// La JList debe ir dentro de un ScrollPane, y se construye con el modelo de JList sobre el que después
|
||||||
// se agregar<EFBFBD>n o eliminar<EFBFBD>n provincias.
|
// se agregarán o eliminarán provincias.
|
||||||
jlistProvincias = new JList(this.getDefaultListModel());
|
jlistProvincias = new JList(this.getDefaultListModel());
|
||||||
// Tipos de selecci<63>n disponibles en JList
|
// Tipos de selecci<63>n disponibles en JList
|
||||||
//this.jlistProvincias.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
//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 () {
|
private DefaultListModel getDefaultListModel () {
|
||||||
this.listModelProvincias = new DefaultListModel<Provincia>();
|
this.listModelProvincias = new DefaultListModel<Provincia>();
|
||||||
@@ -108,16 +108,16 @@ public class PanelJList extends JPanel {
|
|||||||
*/
|
*/
|
||||||
private void agregarProvincia () {
|
private void agregarProvincia () {
|
||||||
this.listModelProvincias.addElement(this.provincias.get(this.indiceProximaProvinciaParaAgregar));
|
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++;
|
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()) {
|
if (this.indiceProximaProvinciaParaAgregar == this.provincias.size()) {
|
||||||
this.indiceProximaProvinciaParaAgregar = 0;
|
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 () {
|
private void eliminarProvinciasSeleccionadas () {
|
||||||
for (int i = this.jlistProvincias.getSelectedIndices().length - 1; i >= 0; i--) {
|
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 java.util.List;
|
||||||
|
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Persona;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorPersona;
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.PersonaControlador;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Persona;
|
||||||
|
|
||||||
|
|
||||||
public class DatosDeTabla {
|
public class DatosDeTabla {
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ public class DatosDeTabla {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String[] getTitulosColumnas() {
|
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() {
|
public static Object[][] getDatosDeTabla() {
|
||||||
// Obtengo todas las personas
|
// 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
|
// Preparo una estructura para pasar al constructor de la JTable
|
||||||
Object[][] datos = new Object[personas.size()][8];
|
Object[][] datos = new Object[personas.size()][8];
|
||||||
// Cargo los datos de la lista de personas en la matriz de los datos
|
// 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);
|
Persona persona = personas.get(i);
|
||||||
datos[i][0] = persona.getId();
|
datos[i][0] = persona.getId();
|
||||||
datos[i][1] = persona.getNombre();
|
datos[i][1] = persona.getNombre();
|
||||||
datos[i][2] = persona.getPrimerApellido();
|
datos[i][2] = persona.getApellido1();
|
||||||
datos[i][3] = persona.getSegundoApellido();
|
datos[i][3] = persona.getApellido2();
|
||||||
datos[i][4] = persona.getFechaNacimiento();
|
datos[i][4] = persona.getFechaNacimiento();
|
||||||
datos[i][5] = persona.getEdad();
|
datos[i][5] = persona.getEdad();
|
||||||
datos[i][6] = persona.getActivo();
|
datos[i][6] = persona.isActivo();
|
||||||
datos[i][7] = persona.getProvincia();
|
datos[i][7] = persona.getProvincia();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,17 +62,27 @@ public class v02_TablaConDefaultTableModel extends JPanel {
|
|||||||
*/
|
*/
|
||||||
private DefaultTableModel getDefaultTableModelNoEditable () {
|
private DefaultTableModel getDefaultTableModelNoEditable () {
|
||||||
DefaultTableModel dtm = new DefaultTableModel(datosEnTabla, titulosEnTabla) {
|
DefaultTableModel dtm = new DefaultTableModel(datosEnTabla, titulosEnTabla) {
|
||||||
|
|
||||||
/**
|
|
||||||
* La sobreescritura de este m<>todo nos permite controlar qu<71> celdas queremos que sean editables
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCellEditable(int row, int column) {
|
public boolean isCellEditable(int row, int column) {
|
||||||
if (column != 1) {
|
if (column == 1)
|
||||||
return false;
|
return true;
|
||||||
}
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 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;
|
return dtm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import javax.swing.DefaultCellEditor;
|
|||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.controller.ControladorProvincia;
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.controladores.ProvinciaControlador;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||||
|
|
||||||
|
|
||||||
public class MiProvinciaTableCellEditor extends DefaultCellEditor {
|
public class MiProvinciaTableCellEditor extends DefaultCellEditor {
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ public class MiProvinciaTableCellEditor extends DefaultCellEditor {
|
|||||||
jcbProvincias.removeAllItems();
|
jcbProvincias.removeAllItems();
|
||||||
|
|
||||||
// Inicializo los elementos del combobox a todas las provincias disponibles y selecciono la correcta
|
// 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) {
|
for (Provincia provincia : provincias) {
|
||||||
jcbProvincias.addItem(provincia);
|
jcbProvincias.addItem(provincia);
|
||||||
if (value != null && value instanceof Provincia) {
|
if (value != null && value instanceof Provincia) {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import javax.swing.JScrollPane;
|
|||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
import tutorialJava.modelosBasesDeDatosComunesJPA.poblacionPorProvincias.Provincia;
|
import tutorialJava.capitulo9_AWT_SWING.v05_JListConDefaultListModel.model.Provincia;
|
||||||
|
|
||||||
|
|
||||||
public class TablaEnScrollPane extends JPanel {
|
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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,38 +1,35 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades;
|
package tutorialJava.examenes.examen20250321.modelo;
|
||||||
|
|
||||||
public class Curso {
|
|
||||||
|
|
||||||
|
public class Localidad {
|
||||||
private int id;
|
private int id;
|
||||||
private String descripcion;
|
private String descripcion;
|
||||||
|
|
||||||
|
public Localidad() {
|
||||||
|
|
||||||
public Curso() {
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Localidad(int id, String descripcion) {
|
||||||
public Curso(int id, String descripcion) {
|
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.descripcion = descripcion;
|
this.descripcion = descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescripcion() {
|
public String getDescripcion() {
|
||||||
return descripcion;
|
return descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescripcion(String descripcion) {
|
public void setDescripcion(String descripcion) {
|
||||||
this.descripcion = descripcion;
|
this.descripcion = descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return descripcion;
|
return descripcion;
|
||||||
@@ -40,12 +37,3 @@ public class Curso {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades;
|
package tutorialJava.examenes.examen20250509.modelo;
|
||||||
|
|
||||||
public class Profesor {
|
|
||||||
|
|
||||||
|
public class Grupo {
|
||||||
private int id;
|
private int id;
|
||||||
private String nombre;
|
private String nombre;
|
||||||
|
private String estilo;
|
||||||
|
|
||||||
public Profesor() {
|
public Grupo() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +25,14 @@ public class Profesor {
|
|||||||
this.nombre = nombre;
|
this.nombre = nombre;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEstilo() {
|
||||||
|
return estilo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEstilo(String estilo) {
|
||||||
|
this.estilo = estilo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return nombre;
|
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