Advertisement
Guest User

P5-19

a guest
Nov 28th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1. package es.uca.gii.csi.sauron.gui;
  2.  
  3. import javax.swing.JInternalFrame;
  4.  
  5. public class IfrSala extends JInternalFrame {
  6.     /**
  7.     *
  8.     */
  9.     private static final long serialVersionUID = 1L;
  10.     private JTextField _txtNombre;
  11.     private JTextField _txtEslogan;
  12.     private JButton _butSave;
  13.     private Sala _sala = null;
  14.     private JLabel _lblCapacidadActual;
  15.     private JTextField _txtCapacidadActual;
  16.  
  17.     /**
  18.     * Create the frame.
  19.     */
  20.     public IfrSala(Sala sala) {
  21.         //Doble clic en búsqueda
  22.         if(sala != null){
  23.             _sala = sala;
  24.             _txtNombre = new JTextField(_sala.getNombre());
  25.             _txtEslogan = new JTextField(_sala.getEslogan());
  26.             _txtCapacidadActual = new JTextField(Integer.toString(sala.getCapacidadActual()));
  27.             JOptionPane.showMessageDialog(null, "Funciona, Sala: " + _txtNombre.getText());
  28.         }
  29.         //
  30.         setClosable(true);
  31.         setResizable(true);
  32.         setTitle("Sala");
  33.         setBounds(100, 100, 450, 300);
  34.         getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
  35.             FormSpecs.RELATED_GAP_COLSPEC,
  36.             FormSpecs.DEFAULT_COLSPEC,
  37.             FormSpecs.RELATED_GAP_COLSPEC,
  38.             ColumnSpec.decode("default:grow"),},
  39.             new RowSpec[] {
  40.                 FormSpecs.RELATED_GAP_ROWSPEC,
  41.                 FormSpecs.DEFAULT_ROWSPEC,
  42.                 FormSpecs.RELATED_GAP_ROWSPEC,
  43.                 FormSpecs.DEFAULT_ROWSPEC,
  44.                 FormSpecs.RELATED_GAP_ROWSPEC,
  45.                 FormSpecs.DEFAULT_ROWSPEC,
  46.                 FormSpecs.RELATED_GAP_ROWSPEC,
  47.                 FormSpecs.DEFAULT_ROWSPEC,
  48.                 FormSpecs.RELATED_GAP_ROWSPEC,
  49.                 FormSpecs.DEFAULT_ROWSPEC,
  50.                 FormSpecs.RELATED_GAP_ROWSPEC,
  51.                 FormSpecs.DEFAULT_ROWSPEC,
  52.                 FormSpecs.RELATED_GAP_ROWSPEC,
  53.                 FormSpecs.DEFAULT_ROWSPEC,
  54.                 FormSpecs.RELATED_GAP_ROWSPEC,
  55.                 FormSpecs.DEFAULT_ROWSPEC,
  56.                 FormSpecs.RELATED_GAP_ROWSPEC,
  57.                 FormSpecs.DEFAULT_ROWSPEC,}));
  58.  
  59.         JLabel lblNombre = new JLabel("Nombre");
  60.         getContentPane().add(lblNombre, "2, 4, right, default");
  61.  
  62.         _txtNombre = new JTextField();
  63.         getContentPane().add(_txtNombre, "4, 4, fill, default");
  64.         _txtNombre.setColumns(10);
  65.  
  66.         JLabel lblEslogan = new JLabel("Eslogan");
  67.         getContentPane().add(lblEslogan, "2, 6, right, default");
  68.  
  69.         _txtEslogan = new JTextField();
  70.         getContentPane().add(_txtEslogan, "4, 6, fill, default");
  71.         _txtEslogan.setColumns(10);
  72.  
  73.         _lblCapacidadActual = new JLabel("Capacidad Actual");
  74.         getContentPane().add(_lblCapacidadActual, "2, 8, right, default");
  75.  
  76.         _txtCapacidadActual = new JTextField();
  77.         getContentPane().add(_txtCapacidadActual, "4, 8, fill, default");
  78.         _txtCapacidadActual.setColumns(10);
  79.  
  80.         _butSave = new JButton("Guardar");
  81.         _butSave.addActionListener(new ActionListener() {
  82.             public void actionPerformed(ActionEvent e) {
  83.                 if(_sala == null)
  84.                     try {
  85.                     _sala = Sala.Create(Integer.parseInt(_txtCapacidadActual.getText()), _txtNombre.getText(), _txtEslogan.getText(), null);
  86.                     } catch (Exception e1){
  87.                         JOptionPane.showMessageDialog(null, "¡Error al crear la sala!");
  88.                     }
  89.                 else{
  90.                     _sala.setNombre(_txtNombre.getText());
  91.                     _sala.setEslogan(_txtEslogan.getText());
  92.                     _sala.setCapacidadActual(Integer.parseInt(_txtCapacidadActual.getText()));
  93.                     try {
  94.                         _sala.Update();
  95.                     } catch (Exception e1) {
  96.                         JOptionPane.showMessageDialog(null, "¡Error al actualizar la sala!");
  97.                     }
  98.                 }
  99.             }
  100.         });
  101.         getContentPane().add(_butSave, "2, 12, 3, 1");
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement