diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/JFrameKK.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/JFrameKK.java deleted file mode 100644 index 864ee5a..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/JFrameKK.java +++ /dev/null @@ -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); - } - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/ConnectionManager.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/ConnectionManager.java deleted file mode 100644 index 17676c2..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/ConnectionManager.java +++ /dev/null @@ -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"); - } - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/Fabricante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/Fabricante.java deleted file mode 100644 index 33b35c4..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/Fabricante.java +++ /dev/null @@ -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; - } - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/GestionFabricante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/GestionFabricante.java deleted file mode 100644 index 3931575..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/GestionFabricante.java +++ /dev/null @@ -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(); - } - } - - - - - - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/SupertipoGestion.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/SupertipoGestion.java deleted file mode 100644 index ace1508..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/SupertipoGestion.java +++ /dev/null @@ -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; - } - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/VentanaFabricante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/VentanaFabricante.java deleted file mode 100644 index 9649213..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo01_GestionGraficaFabricante/VentanaFabricante.java +++ /dev/null @@ -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(); - } - - } -} - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/Principal.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/Principal.java deleted file mode 100644 index 127ff03..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/Principal.java +++ /dev/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); - } - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ConnectionManager.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ConnectionManager.java deleted file mode 100644 index 7e6de83..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ConnectionManager.java +++ /dev/null @@ -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"); - } - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorCurso.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorCurso.java deleted file mode 100644 index 72c4f24..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorCurso.java +++ /dev/null @@ -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 getTodos() { - List l = new ArrayList(); - - 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; - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorEstudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorEstudiante.java deleted file mode 100644 index a6b7313..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorEstudiante.java +++ /dev/null @@ -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 getTodos() { - List l = new ArrayList(); - - 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; - } - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorMateria.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorMateria.java deleted file mode 100644 index 9c988cb..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorMateria.java +++ /dev/null @@ -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 getTodos() { - List l = new ArrayList(); - - 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; - } - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorProfesor.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorProfesor.java deleted file mode 100644 index 00f37c0..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorProfesor.java +++ /dev/null @@ -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 getTodos() { - List l = new ArrayList(); - - 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; - } - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorValoracionMateria.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorValoracionMateria.java deleted file mode 100644 index d89b639..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/ControladorValoracionMateria.java +++ /dev/null @@ -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; - } -} - - - - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/SuperControlador.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/SuperControlador.java deleted file mode 100644 index 582ad02..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/controladores/SuperControlador.java +++ /dev/null @@ -1,5 +0,0 @@ -package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.controladores; - -public class SuperControlador { - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Curso.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Curso.java deleted file mode 100644 index bc771eb..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Curso.java +++ /dev/null @@ -1,51 +0,0 @@ -package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades; - -public class Curso { - - private int id; - private String descripcion; - - - - public Curso() { - super(); - } - - - public Curso(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; - } - - -} - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Estudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Estudiante.java deleted file mode 100644 index 661eed9..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Estudiante.java +++ /dev/null @@ -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; - } - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Materia.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Materia.java deleted file mode 100644 index 111cede..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Materia.java +++ /dev/null @@ -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; - } - - - - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Profesor.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Profesor.java deleted file mode 100644 index 4de07e9..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/Profesor.java +++ /dev/null @@ -1,34 +0,0 @@ -package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_GestionCentroEducativo.entitidades; - -public class Profesor { - - private int id; - private String nombre; - - public Profesor() { - 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; - } - - @Override - public String toString() { - return nombre; - } - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/ValoracionMateria.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/ValoracionMateria.java deleted file mode 100644 index c258f6c..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/entitidades/ValoracionMateria.java +++ /dev/null @@ -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 + "]"; - } - - - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelCurso.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelCurso.java deleted file mode 100644 index 4a90820..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelCurso.java +++ /dev/null @@ -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()); - } - } -} - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelDatosPersonales.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelDatosPersonales.java deleted file mode 100644 index 7d77dfc..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelDatosPersonales.java +++ /dev/null @@ -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; - } - - - -} - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelEstudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelEstudiante.java deleted file mode 100644 index c1c43dc..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelEstudiante.java +++ /dev/null @@ -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()); - } - -} - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelMateria.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelMateria.java deleted file mode 100644 index fe0d17c..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelMateria.java +++ /dev/null @@ -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 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(); - 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 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()); - } - } -} - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelSlotEvaluacionEstudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelSlotEvaluacionEstudiante.java deleted file mode 100644 index d3f81d4..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelSlotEvaluacionEstudiante.java +++ /dev/null @@ -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() { - - } - -} - - - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelValoracionMateriaOpcion1.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelValoracionMateriaOpcion1.java deleted file mode 100644 index dd9e9b8..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_GestionCentroEducativo/vista/PanelValoracionMateriaOpcion1.java +++ /dev/null @@ -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 jcbMateria; - JComboBox jcbProfesor; - JPanel panelEstudiantes; - List listaSlotsValoracion = new ArrayList(); - - /** - * 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(); - 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(); - 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 l = ControladorMateria.getTodos(); - for (Materia m : l) { - this.jcbMateria.addItem(m); - } - } - - - private void cargarTodProfesores() { - List l = ControladorProfesor.getTodos(); - for (Profesor p : l) { - this.jcbProfesor.addItem(p); - } - } - - - - private void refrescarEstudiantes() { - List 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(); - } - } - - -} - - - - - - - - - - - - - diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/PanelDentroDeDialogo.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/PanelDentroDeDialogo.java deleted file mode 100644 index ffe520c..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/PanelDentroDeDialogo.java +++ /dev/null @@ -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); - - } - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/VentanaPrincipal.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/VentanaPrincipal.java deleted file mode 100644 index 51c9c8e..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemploPanelDentroDeDialogo/VentanaPrincipal.java +++ /dev/null @@ -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�logo - dialogo.setResizable(true); - // t�tulo del d�alogo - dialogo.setTitle("Gestión de empresas"); - // Introducimos el panel creado sobre el di�logo - dialogo.setContentPane(new PanelDentroDeDialogo()); - // Empaquetar el di�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�logo es modal - dialogo.setModal(true); - // Centro el di�logo en pantalla - dialogo.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width)/2 - dialogo.getWidth()/2, - (Toolkit.getDefaultToolkit().getScreenSize().height)/2 - dialogo.getHeight()/2); - // Muestro el di�logo en pantalla - dialogo.setVisible(true); - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/MiJRadioButtonKk.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/MiJRadioButtonKk.java deleted file mode 100644 index 859bc8a..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/MiJRadioButtonKk.java +++ /dev/null @@ -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; - } - - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/controller/EstudianteControlador.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/controller/EstudianteControlador.java deleted file mode 100644 index 34f19b9..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/controller/EstudianteControlador.java +++ /dev/null @@ -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 findAll() { - EntityManager em = entityManagerFactory.createEntityManager(); - Query q = em.createNativeQuery("SELECT * FROM estudiante;", Est.class); - List l = (List) q.getResultList(); - - em.close(); - return l; - } - - - -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/model/Est.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/model/Est.java deleted file mode 100644 index 8fbb08e..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/model/Est.java +++ /dev/null @@ -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; - } - -} \ No newline at end of file diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/PanelGestionEstudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/PanelGestionEstudiante.java deleted file mode 100644 index cd66f1a..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/PanelGestionEstudiante.java +++ /dev/null @@ -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()); - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/Tabla.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/Tabla.java deleted file mode 100644 index ef6b89e..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/Tabla.java +++ /dev/null @@ -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 estudiantes = new ArrayList(); - 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; - } -} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/VentanaPrincipal.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/VentanaPrincipal.java deleted file mode 100644 index a2f4f59..0000000 --- a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/jTableEstudiantes/view/VentanaPrincipal.java +++ /dev/null @@ -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; - } - - - -}