PageRenderTime 29ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/PracticasTAP/src/Ruta.java

https://bitbucket.org/adalram/practicastap
Java | 152 lines | 99 code | 20 blank | 33 comment | 4 complexity | acfc0df852d0ad68ea42167f2378796f MD5 | raw file
  1
  2
  3import java.io.File;
  4import java.util.logging.Level;
  5import java.util.logging.Logger;
  6import javax.swing.JFileChooser;
  7import javax.swing.UIManager;
  8import javax.swing.UnsupportedLookAndFeelException;
  9import javax.swing.filechooser.FileFilter;
 10
 11
 12
 13
 14/*
 15 * To change this license header, choose License Headers in Project Properties.
 16 * To change this template file, choose Tools | Templates
 17 * and open the template in the editor.
 18 */
 19
 20/**
 21 *
 22 * @author Adal
 23 */
 24public class Ruta extends javax.swing.JFrame {
 25
 26    /**
 27     * Creates new form Ruta
 28     */
 29    public Ruta() {
 30        initComponents();
 31        this.setLocationRelativeTo(null);
 32    }
 33
 34    /**
 35     * This method is called from within the constructor to initialize the form.
 36     * WARNING: Do NOT modify this code. The content of this method is always
 37     * regenerated by the Form Editor.
 38     */
 39    @SuppressWarnings("unchecked")
 40    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 41    private void initComponents() {
 42
 43        jLabel1 = new javax.swing.JLabel();
 44        jTextField1 = new javax.swing.JTextField();
 45        jButton1 = new javax.swing.JButton();
 46
 47        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 48        setTitle("Mostrar fichero ruta");
 49
 50        jLabel1.setText("Pulsa el boton y elige una ruta");
 51
 52        jButton1.setText("...");
 53        jButton1.addActionListener(new java.awt.event.ActionListener() {
 54            public void actionPerformed(java.awt.event.ActionEvent evt) {
 55                jButton1ActionPerformed(evt);
 56            }
 57        });
 58
 59        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 60        getContentPane().setLayout(layout);
 61        layout.setHorizontalGroup(
 62            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 63            .addGroup(layout.createSequentialGroup()
 64                .addGap(68, 68, 68)
 65                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 66                    .addComponent(jLabel1)
 67                    .addGroup(layout.createSequentialGroup()
 68                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE)
 69                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 70                        .addComponent(jButton1)))
 71                .addContainerGap(44, Short.MAX_VALUE))
 72        );
 73        layout.setVerticalGroup(
 74            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 75            .addGroup(layout.createSequentialGroup()
 76                .addContainerGap()
 77                .addComponent(jLabel1)
 78                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 79                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 80                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 81                    .addComponent(jButton1))
 82                .addContainerGap(37, Short.MAX_VALUE))
 83        );
 84
 85        pack();
 86    }// </editor-fold>//GEN-END:initComponents
 87
 88    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
 89        // TODO add your handling code here:
 90        JFileChooser jf = new JFileChooser();
 91        //FileFilter = new FileFilter();
 92        jf.showOpenDialog(this);
 93        
 94        //fch.addChoosableFileFilter(filter);
 95        File archivo  = jf.getSelectedFile();
 96        if(archivo != null){
 97            jTextField1.setText(archivo.getAbsolutePath());
 98        }
 99    }//GEN-LAST:event_jButton1ActionPerformed
100
101    /**
102     * @param args the command line arguments
103     */
104    public static void main(String args[]) {
105        /* Set the Nimbus look and feel */
106        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
107        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
108         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
109         */
110        try {
111            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
112                if ("Nimbus".equals(info.getName())) {
113                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
114                    break;
115                }
116            }
117        } catch (ClassNotFoundException ex) {
118            java.util.logging.Logger.getLogger(Ruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
119        } catch (InstantiationException ex) {
120            java.util.logging.Logger.getLogger(Ruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
121        } catch (IllegalAccessException ex) {
122            java.util.logging.Logger.getLogger(Ruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
123        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
124            java.util.logging.Logger.getLogger(Ruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
125        }
126        //</editor-fold>
127
128        /* Create and display the form */
129        java.awt.EventQueue.invokeLater(new Runnable() {
130            public void run() {
131                try {
132                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
133                } catch (ClassNotFoundException ex) {
134                    Logger.getLogger(Ruta.class.getName()).log(Level.SEVERE, null, ex);
135                } catch (InstantiationException ex) {
136                    Logger.getLogger(Ruta.class.getName()).log(Level.SEVERE, null, ex);
137                } catch (IllegalAccessException ex) {
138                    Logger.getLogger(Ruta.class.getName()).log(Level.SEVERE, null, ex);
139                } catch (UnsupportedLookAndFeelException ex) {
140                    Logger.getLogger(Ruta.class.getName()).log(Level.SEVERE, null, ex);
141                }
142                new Ruta().setVisible(true);
143            }
144        });
145    }
146
147    // Variables declaration - do not modify//GEN-BEGIN:variables
148    private javax.swing.JButton jButton1;
149    private javax.swing.JLabel jLabel1;
150    private javax.swing.JTextField jTextField1;
151    // End of variables declaration//GEN-END:variables
152}