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