Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package mx.jalan.gdcu.Vista.Gestor; import javax.swing.JOptionPane; import mx.jalan.gdcu.Modelo.Archivo; import org.apache.commons.validator.UrlValidator; /** * * @author Jorge */ public class Detalles extends javax.swing.JDialog { private boolean ok; private String fuente; private String descarga; private String comentarios; /** * Creates new form Detalles */ public Detalles(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); this.setLocationRelativeTo(null); this.setVisible(true); } public Detalles(java.awt.Frame parent, boolean modal, Archivo archivo) { super(parent, modal); initComponents(); if (archivo.getLinkFuente() != null) txtFuente.setText(archivo.getLinkFuente()); if (archivo.getLinkDescarga() != null) txtDescarga.setText(archivo.getLinkDescarga()); if (archivo.getComentarios() != null) txtComentarios.setText(archivo.getComentarios()); this.setLocationRelativeTo(null); this.setVisible(true); } public boolean pressOk() { return ok; } public String getLinkDescarga() { return txtDescarga.getText(); } public String getLinkFuente() { return txtFuente.getText(); } public String getComentarios() { return txtComentarios.getText(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { txtFuente = new javax.swing.JTextField(); btnAceptar = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtDescarga = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); txtComentarios = new javax.swing.JTextArea(); btnCancelar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Agregar detalles"); btnAceptar.setText("Aceptar"); btnAceptar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAceptarActionPerformed(evt); } }); jLabel1.setText("Fuente del archivo"); jLabel2.setText("Link de descarga"); jLabel3.setText("Comentarios"); txtComentarios.setColumns(20); txtComentarios.setRows(3); txtComentarios.setTabSize(5); jScrollPane1.setViewportView(txtComentarios); btnCancelar.setText("Cancelar"); btnCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelarActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2).addComponent(jLabel1).addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtFuente) .addComponent(txtDescarga, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup().addGap(94, 94, 94).addComponent(btnAceptar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCancelar).addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtFuente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(txtDescarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnAceptar).addComponent(btnCancelar)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed ok = true; String mensaje = ""; UrlValidator validador = new UrlValidator(); if (!txtFuente.getText().trim().isEmpty()) { if (!validador.isValid(txtFuente.getText())) { mensaje += "La url fuente no es valida\n"; } else { fuente = txtFuente.getText(); } } if (!txtDescarga.getText().trim().isEmpty()) { if (!validador.isValid(txtDescarga.getText())) { mensaje += "La url descarga no es valida\n"; } else { descarga = txtDescarga.getText(); } } if (!mensaje.equals("")) { JOptionPane.showMessageDialog(this, mensaje, "Revisa los campos", JOptionPane.ERROR_MESSAGE); return; } this.dispose(); }//GEN-LAST:event_btnAceptarActionPerformed private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed ok = false; this.dispose(); }//GEN-LAST:event_btnCancelarActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAceptar; private javax.swing.JButton btnCancelar; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea txtComentarios; private javax.swing.JTextField txtDescarga; private javax.swing.JTextField txtFuente; // End of variables declaration//GEN-END:variables }