mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
feat(ch 9): ex 2 initialized
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class JPanelProfesor extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public JPanelProfesor() {
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión de Profesores");
|
||||
add(lblNewLabel, BorderLayout.NORTH);
|
||||
add(new JPanelDatosPersonales(), BorderLayout.CENTER);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package tutorialJava.capitulo9_AWT_SWING.ejemplos.ejemplo02_CentroEducativo;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JToolBar;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class PanelGestionCurso extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelGestionCurso() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JToolBar toolBar = new JToolBar();
|
||||
GridBagConstraints gbc_toolBar = new GridBagConstraints();
|
||||
gbc_toolBar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_toolBar.gridx = 0;
|
||||
gbc_toolBar.gridy = 0;
|
||||
add(toolBar, gbc_toolBar);
|
||||
|
||||
JButton btnNewButton = new JButton("");
|
||||
btnNewButton.setIcon(new ImageIcon(PanelGestionCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/gotostart.png")));
|
||||
toolBar.add(btnNewButton);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("");
|
||||
btnNewButton_1.setIcon(new ImageIcon(PanelGestionCurso.class.getResource("/tutorialJava/capitulo9_AWT_SWING/res/previous.png")));
|
||||
toolBar.add(btnNewButton_1);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Gestión Cursos");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 1;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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())));
|
||||
|
||||
Reference in New Issue
Block a user