From abf5adcfe914e85bcb7970750c888af73d7410b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20Mu=C3=B1oz?= Date: Tue, 25 Mar 2025 15:00:03 +0100 Subject: [PATCH] feat(ch 9): ex 2 initialized --- .../JPanelDatosPersonales.java | 103 ++++++++++++++++++ .../JPanelEstudiante.java | 28 +++++ .../JPanelProfesor.java | 23 ++++ .../PanelGestionCurso.java | 50 +++++++++ .../VentanaPrincipal.java | 69 ++++++++++++ .../v03_JComponentsAvanzados/Menu.java | 3 +- 6 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelDatosPersonales.java create mode 100644 src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelEstudiante.java create mode 100644 src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelProfesor.java create mode 100644 src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/PanelGestionCurso.java create mode 100644 src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/VentanaPrincipal.java diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelDatosPersonales.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelDatosPersonales.java new file mode 100644 index 0000000..75b49d1 --- /dev/null +++ b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelDatosPersonales.java @@ -0,0 +1,103 @@ +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; + +public class JPanelDatosPersonales extends JPanel { + + private static final long serialVersionUID = 1L; + private JTextField jtfId; + private JTextField jtfNombre; + private JTextField jtfAppelido1; + + /** + * Create the panel. + */ + public JPanelDatosPersonales() { + GridBagLayout gridBagLayout = new GridBagLayout(); + gridBagLayout.columnWidths = new int[]{0, 0, 0}; + gridBagLayout.rowHeights = new int[]{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, Double.MIN_VALUE}; + setLayout(gridBagLayout); + + 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 = 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("Apellido 1:"); + 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; + add(lblNewLabel_2, gbc_lblNewLabel_2); + + jtfAppelido1 = new JTextField(); + GridBagConstraints gbc_jtfAppelido1 = new GridBagConstraints(); + gbc_jtfAppelido1.fill = GridBagConstraints.HORIZONTAL; + gbc_jtfAppelido1.gridx = 1; + gbc_jtfAppelido1.gridy = 2; + add(jtfAppelido1, gbc_jtfAppelido1); + jtfAppelido1.setColumns(10); + + } + + + /** + * + * @param id + */ + public void setId(int id) { + this.jtfId.setText("" + id); + } + + public int getId() { + return Integer.parseInt(this.jtfId.getText()); + } +} + + + + + + + + + + + diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelEstudiante.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelEstudiante.java new file mode 100644 index 0000000..cbe725c --- /dev/null +++ b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelEstudiante.java @@ -0,0 +1,28 @@ +package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo; + +import javax.swing.JPanel; +import java.awt.BorderLayout; +import javax.swing.JLabel; + +public class JPanelEstudiante extends JPanel { + + private static final long serialVersionUID = 1L; + private JPanelDatosPersonales panelDatos = new JPanelDatosPersonales(); + + /** + * Create the panel. + */ + public JPanelEstudiante() { + setLayout(new BorderLayout(0, 0)); + + JLabel lblNewLabel = new JLabel("Gestión de Estudiantes"); + add(lblNewLabel, BorderLayout.NORTH); + add(panelDatos, BorderLayout.CENTER); + + } + + +// private void cargarEstudianteEnPantalla(Estudiante e) { +// this.panelDatos.setId(e.getId()); +// } +} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelProfesor.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelProfesor.java new file mode 100644 index 0000000..51626d9 --- /dev/null +++ b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/JPanelProfesor.java @@ -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); + + } + +} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/PanelGestionCurso.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/PanelGestionCurso.java new file mode 100644 index 0000000..5d2eb35 --- /dev/null +++ b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/PanelGestionCurso.java @@ -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); + + } + +} diff --git a/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/VentanaPrincipal.java b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/VentanaPrincipal.java new file mode 100644 index 0000000..3bfe651 --- /dev/null +++ b/src/tutorialJava/capitulo9_AWT_SWING/ejemplos/ejemplo02_CentroEducativo/VentanaPrincipal.java @@ -0,0 +1,69 @@ +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; + +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)); + + 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); + } + +} + + + + + diff --git a/src/tutorialJava/capitulo9_AWT_SWING/v03_JComponentsAvanzados/Menu.java b/src/tutorialJava/capitulo9_AWT_SWING/v03_JComponentsAvanzados/Menu.java index d356a05..2a66d79 100644 --- a/src/tutorialJava/capitulo9_AWT_SWING/v03_JComponentsAvanzados/Menu.java +++ b/src/tutorialJava/capitulo9_AWT_SWING/v03_JComponentsAvanzados/Menu.java @@ -25,7 +25,8 @@ public class Menu extends JMenuBar { // Menú Archivo de la aplicación JMenu menuArchivo = new JMenu("Archivo"); - menuArchivo.add(crearNuevoMenuItem("Abrir", "ruedadentada.png", KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()))); + menuArchivo.add(crearNuevoMenuItem("Abrir", "ruedadentada.png", + KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()))); JMenu menuExportar = new JMenu("Exportar"); menuExportar.add(crearNuevoMenuItem("Como Word", "ruedadentada.png", KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())));