private void btnAceptarActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnAceptarActionPerformed etqError2.setText(""); Ciudad destino = (Ciudad) comboDestino.getSelectedItem(); String nombre = txtNombre.getText(); Date fechaInicio = JDateInicio.getDate(); Date fechaFin = JDateFin.getDate(); String descripcion = txtDescripcion.getText(); if (!sistema.getUsuarioIdentificado().existeViaje(fechaInicio)) { if (comboDestino.getItemCount() != 0) { try { sistema .getUsuarioIdentificado() .altaViaje(nombre, destino, fechaInicio, fechaFin, descripcion); etqCorrecto.setText("Registro exitoso."); etqError.setText(null); this.limpiarCampos(); } catch (ViajeException e) { etqError.setText(e.toString()); } catch (FechaException e) { etqError.setText(e.toString()); } } else { etqError.setText("Debe agregar un destino."); } } else { etqError.setText("Ya tiene un viaje en esa fecha"); } } // GEN-LAST:event_btnAceptarActionPerformed
public PanelAgendarViaje() { initComponents(); this.sistema = SistemaImp.getInstance(); if (this.sistema.esModoDesarrollador()) { this.txtNombre.requestFocusInWindow(); if (sistema.getListaDestinos().isEmpty()) { sistema.agregarDestino(new Ciudad("Miami")); } this.txtNombre.setText("Vacaciones"); this.txtDescripcion.setText("Nos vamos de vacaciones con la familia."); } else { this.txtNombre.requestFocusInWindow(); } Iterator<Ciudad> listadoDestino = sistema.listadoDestino(); while (listadoDestino.hasNext()) { Ciudad ciudad = listadoDestino.next(); comboDestino.addItem(ciudad); } etqError2.setText(""); Date fecha = new Date(); Date maniana = new Date(fecha.getYear(), fecha.getMonth(), fecha.getDate() + 1); JDateInicio.setDate(maniana); Date pasadoManiana = new Date(fecha.getYear(), fecha.getMonth(), fecha.getDate() + 2); JDateFin.setDate(pasadoManiana); }
@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); panelPrincipal = new javax.swing.JPanel(); panelTitulo = new javax.swing.JPanel(); etqTitulo = new javax.swing.JLabel(); panelCrearJugador = new javax.swing.JPanel(); etqDestino = new javax.swing.JLabel(); etqFechaIni = new javax.swing.JLabel(); btnAceptar = new javax.swing.JButton(); etqError = new javax.swing.JLabel(); etqCorrecto = new javax.swing.JLabel(); comboDestino = new javax.swing.JComboBox(); etqFechaFin = new javax.swing.JLabel(); etqDescripcion = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); txtDescripcion = new javax.swing.JTextPane(); etqNombre = new javax.swing.JLabel(); txtNombre = new javax.swing.JTextField(); btnNuevoDestino = new javax.swing.JButton(); etqError2 = new javax.swing.JLabel(); JDateInicio = new com.toedter.calendar.JDateChooser(); JDateFin = new com.toedter.calendar.JDateChooser(); jScrollPane1.setViewportView(jEditorPane1); setBackground(new java.awt.Color(245, 245, 245)); setPreferredSize(new java.awt.Dimension(460, 679)); panelPrincipal.setBackground(new java.awt.Color(245, 245, 245)); panelTitulo.setBackground(new java.awt.Color(39, 39, 39)); panelTitulo.setForeground(new java.awt.Color(255, 255, 255)); etqTitulo.setFont(new java.awt.Font("SansSerif", 0, 18)); // NOI18N etqTitulo.setForeground(new java.awt.Color(255, 255, 255)); etqTitulo.setText("Agendar viaje"); javax.swing.GroupLayout panelTituloLayout = new javax.swing.GroupLayout(panelTitulo); panelTitulo.setLayout(panelTituloLayout); panelTituloLayout.setHorizontalGroup( panelTituloLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelTituloLayout .createSequentialGroup() .addContainerGap() .addComponent(etqTitulo) .addContainerGap(312, Short.MAX_VALUE))); panelTituloLayout.setVerticalGroup( panelTituloLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelTituloLayout .createSequentialGroup() .addContainerGap() .addComponent(etqTitulo) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); panelCrearJugador.setBackground(new java.awt.Color(255, 255, 255)); panelCrearJugador.setBorder( new javax.swing.border.LineBorder(new java.awt.Color(39, 39, 39), 1, true)); panelCrearJugador.setMaximumSize(new java.awt.Dimension(380, 290)); panelCrearJugador.setPreferredSize(new java.awt.Dimension(380, 290)); etqDestino.setFont(new java.awt.Font("SansSerif", 0, 16)); // NOI18N etqDestino.setText("Destino:"); etqFechaIni.setFont(new java.awt.Font("SansSerif", 0, 16)); // NOI18N etqFechaIni.setText("Fecha inicio:"); btnAceptar.setBackground(new java.awt.Color(242, 242, 242)); btnAceptar.setFont(new java.awt.Font("SansSerif", 1, 14)); // NOI18N btnAceptar.setText("Agendar"); btnAceptar.setBorder( new javax.swing.border.LineBorder(new java.awt.Color(221, 221, 221), 1, true)); btnAceptar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); btnAceptar.setFocusPainted(false); btnAceptar.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAceptarActionPerformed(evt); } }); etqError.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N etqError.setForeground(new java.awt.Color(204, 0, 0)); etqError.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); etqCorrecto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N etqCorrecto.setForeground(new java.awt.Color(0, 153, 0)); comboDestino.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { comboDestinoFocusGained(evt); } }); etqFechaFin.setFont(new java.awt.Font("SansSerif", 0, 16)); // NOI18N etqFechaFin.setText("Fecha fin:"); etqDescripcion.setFont(new java.awt.Font("SansSerif", 0, 16)); // NOI18N etqDescripcion.setText("DescripciĆ³n:"); txtDescripcion.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtDescripcionFocusGained(evt); } }); jScrollPane2.setViewportView(txtDescripcion); txtDescripcion.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtDescripcion.setBorder(new LineBorder(new Color(77, 144, 254))); } public void focusLost(java.awt.event.FocusEvent evt) { txtDescripcion.setBorder(new LineBorder(new Color(217, 217, 217))); } }); txtDescripcion.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { if (!txtDescripcion.isFocusOwner()) { txtDescripcion.setBorder(new LineBorder(new Color(185, 185, 185))); } } public void mouseExited(java.awt.event.MouseEvent evt) { if (!txtDescripcion.isFocusOwner()) { txtDescripcion.setBorder(new LineBorder(new Color(217, 217, 217))); } } }); etqNombre.setFont(new java.awt.Font("SansSerif", 0, 16)); // NOI18N etqNombre.setText("Nombre:"); txtNombre.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N txtNombre.setBorder( new javax.swing.border.LineBorder(new java.awt.Color(217, 217, 217), 1, true)); txtNombre.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtNombreFocusGained(evt); } }); txtNombre.addKeyListener( new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txtNombreKeyReleased(evt); } }); txtNombre.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtNombre.setBorder(new LineBorder(new Color(77, 144, 254))); } public void focusLost(java.awt.event.FocusEvent evt) { txtNombre.setBorder(new LineBorder(new Color(217, 217, 217))); } }); txtNombre.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { if (!txtNombre.isFocusOwner()) { txtNombre.setBorder(new LineBorder(new Color(185, 185, 185))); } } public void mouseExited(java.awt.event.MouseEvent evt) { if (!txtNombre.isFocusOwner()) { txtNombre.setBorder(new LineBorder(new Color(217, 217, 217))); } } }); btnNuevoDestino.setText("Nuevo destino"); btnNuevoDestino.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNuevoDestinoActionPerformed(evt); } }); etqError2.setForeground(new java.awt.Color(255, 0, 0)); JDateInicio.setDateFormatString("dd-MM-yyyy"); JDateInicio.addFocusListener( new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { JDateInicioFocusGained(evt); } }); JDateFin.setDateFormatString("dd-MM-yyyy"); javax.swing.GroupLayout panelCrearJugadorLayout = new javax.swing.GroupLayout(panelCrearJugador); panelCrearJugador.setLayout(panelCrearJugadorLayout); panelCrearJugadorLayout.setHorizontalGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addContainerGap() .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( etqCorrecto, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addComponent( etqError, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 21, Short.MAX_VALUE)) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addGroup( panelCrearJugadorLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( etqDestino, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(etqFechaIni) .addComponent(etqFechaFin) .addComponent(etqDescripcion) .addComponent(etqNombre)) .addGap(38, 38, 38) .addGroup( panelCrearJugadorLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txtNombre) .addComponent( comboDestino, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addGroup( panelCrearJugadorLayout .createParallelGroup( javax.swing.GroupLayout.Alignment .LEADING) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addComponent(btnNuevoDestino) .addGap(18, 18, 18) .addComponent( etqError2, javax.swing.GroupLayout .PREFERRED_SIZE, 129, javax.swing.GroupLayout .PREFERRED_SIZE)) .addGroup( panelCrearJugadorLayout .createParallelGroup( javax.swing.GroupLayout .Alignment.TRAILING, false) .addComponent( JDateInicio, javax.swing.GroupLayout .Alignment.LEADING, javax.swing.GroupLayout .DEFAULT_SIZE, javax.swing.GroupLayout .DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( JDateFin, javax.swing.GroupLayout .Alignment.LEADING, javax.swing.GroupLayout .DEFAULT_SIZE, javax.swing.GroupLayout .DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE))))) .addContainerGap()) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addGap(98, 98, 98) .addComponent( btnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); panelCrearJugadorLayout.setVerticalGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addContainerGap() .addComponent( etqError, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(etqNombre) .addComponent( txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( comboDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( panelCrearJugadorLayout .createSequentialGroup() .addComponent( etqDestino, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( panelCrearJugadorLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnNuevoDestino) .addComponent( etqError2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(18, 18, 18) .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(etqFechaIni) .addComponent( JDateInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30) .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(etqFechaFin) .addComponent( JDateFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(36, 36, 36) .addGroup( panelCrearJugadorLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(etqDescripcion) .addComponent( jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent( etqCorrecto, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( btnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(18, Short.MAX_VALUE))); javax.swing.GroupLayout panelPrincipalLayout = new javax.swing.GroupLayout(panelPrincipal); panelPrincipal.setLayout(panelPrincipalLayout); panelPrincipalLayout.setHorizontalGroup( panelPrincipalLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelPrincipalLayout .createSequentialGroup() .addGroup( panelPrincipalLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( panelCrearJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( panelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(20, Short.MAX_VALUE))); panelPrincipalLayout.setVerticalGroup( panelPrincipalLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( panelPrincipalLayout .createSequentialGroup() .addComponent( panelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( panelCrearJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 505, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( panelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( panelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)); } // </editor-fold>//GEN-END:initComponents