Advertisement
julibar

Aporte 5 - Panel Agregar (label genero, combobox y boton aceptar) - Panel Listado (dibuja la grilla)

May 7th, 2025
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.49 KB | None | 0 0
  1.     //archivo PanelAgregarPelicula.java
  2.     //va dentro de la funcion public void dibujarPanel(), debajo del aporte 4
  3.         JLabel lblGenero = new JLabel("Genero");
  4.         lblGenero.setFont(fuentePred);
  5.         GridBagConstraints gbc_lblGenero = new GridBagConstraints();
  6.         gbc_lblGenero.insets = new Insets(0, 0, 5, 5);
  7.         gbc_lblGenero.gridx = 1;
  8.         gbc_lblGenero.gridy = 3;
  9.         gbc_lblGenero.fill = GridBagConstraints.HORIZONTAL;
  10.         add(lblGenero, gbc_lblGenero);
  11.        
  12.         cbGenero = new JComboBox<Categoria>();
  13.         GridBagConstraints gbc_cbGenero = new GridBagConstraints();
  14.         cbGenero.setFont(fuentePred);
  15.         cbGenero.addItem(new Categoria("Seleccione un genero"));
  16.         cbGenero.addItem(new Categoria("Terror"));
  17.         cbGenero.addItem(new Categoria("Accion"));
  18.         cbGenero.addItem(new Categoria("Suspenso"));
  19.         cbGenero.addItem(new Categoria("Romantica"));              
  20.         gbc_cbGenero.insets = new Insets(0, 0, 5, 5);
  21.         gbc_cbGenero.fill = GridBagConstraints.HORIZONTAL;
  22.         gbc_cbGenero.gridx = 3;
  23.         gbc_cbGenero.gridy = 3;
  24.         add(cbGenero, gbc_cbGenero);
  25.        
  26.         btnNewButton = new JButton("Aceptar");
  27.         btnNewButton.addActionListener(new ActionListener() {
  28.             public void actionPerformed(ActionEvent e) {
  29.                
  30.                 if(!txtNombre.getText().isEmpty()) {   
  31.                     if(cbGenero.getSelectedIndex() != 0)    {
  32.                         Categoria seleccion = (Categoria) cbGenero.getSelectedItem();
  33.                         Pelicula Nueva = new Pelicula(txtNombre.getText().toString(),seleccion.getNombre());
  34.                         listPeliculas.addElement(Nueva);   
  35.                         txtNombre.setText("");
  36.                         lblProxID.setText(String.valueOf(Pelicula.getProxId()));
  37.                         cbGenero.setSelectedIndex(0);  
  38.                         }
  39.                     else
  40.                         {
  41.                          JOptionPane.showMessageDialog(null, "Debe seleccionar un genero");
  42.                         }
  43.                     }
  44.                 else
  45.                     {
  46.                         JOptionPane.showMessageDialog(null, "Debe ingresar un nombre");
  47.                     }              
  48.                
  49.             }
  50.         });
  51.         btnNewButton.setBackground(new Color(129, 208, 252));
  52.         btnNewButton.setFont(fuentePred);
  53.         GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
  54.         gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
  55.         gbc_btnNewButton.gridx = 1;
  56.         gbc_btnNewButton.gridy = 5;
  57.         add(btnNewButton, gbc_btnNewButton);               
  58.  
  59.     }
  60.    
  61.     public void setDefaultListModel(DefaultListModel<Pelicula> listPeliculaslRecibida) {
  62.         this.listPeliculas = listPeliculaslRecibida;
  63.     }
  64.  
  65. }
  66.  
  67.  
  68. //archivo PanelListadoPeliculas.java
  69.  
  70. package Paquete;
  71.  
  72.  
  73. import java.awt.GridBagConstraints;
  74. import java.awt.GridBagLayout;
  75. import java.awt.Insets;
  76. import java.util.Comparator;
  77. import java.util.TreeSet;
  78.  
  79. import javax.swing.DefaultListModel;
  80. import javax.swing.JList;
  81. import javax.swing.JPanel;
  82. import javax.swing.JScrollPane;
  83. import javax.swing.JLabel;
  84.  
  85. import java.awt.Dimension;
  86. import java.awt.Font;
  87.  
  88. public class PanelListadoPeliculas extends JPanel {
  89.  
  90.     private static final long serialVersionUID = 1L;
  91.    
  92.     private JScrollPane scrollPane;
  93.     private JList<Pelicula> listaPeliculasJL;
  94.     private DefaultListModel<Pelicula> listPeliculas;
  95.  
  96.     public PanelListadoPeliculas() {
  97.         dibujarPanel();
  98.        
  99.     }
  100.  
  101.     public void dibujarPanel() {       
  102.        
  103.         GridBagLayout gridBagLayout = new GridBagLayout();
  104.         gridBagLayout.columnWidths = new int[]{80, 0, 0, 0, 30, 0};
  105.         gridBagLayout.rowHeights = new int[]{30, 63, 0, 0, 30, 0};
  106.         gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  107.         gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  108.         setLayout(gridBagLayout);
  109.        
  110.  
  111.     // aca va el aporte 6
  112.        
  113.     }
  114.  
  115.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement