franciscominajas

Archivo2.java

Sep 11th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.io.File;
  5.  
  6. import javax.swing.JButton;
  7. import javax.swing.JFileChooser;
  8. import javax.swing.JFrame;
  9. import javax.swing.SwingUtilities;
  10. import javax.swing.UIManager;
  11.  
  12. public class Archivo2 extends JFrame {
  13.  
  14.     private JButton buttonBrowse;
  15.  
  16.     public Archivo2() {
  17. //      super("Save File Dialog Example");
  18. //      setLayout(new FlowLayout());
  19. //      buttonBrowse = new JButton("Save...");
  20. //      buttonBrowse.addActionListener(new ActionListener() {
  21. //
  22. //          public void actionPerformed(ActionEvent arg0) {
  23. //      String z="";
  24. //              z=showSaveFileDialog();
  25. //          }
  26. //      });
  27. //      getContentPane().add(buttonBrowse);
  28. //      setSize(300, 100);
  29. //      setLocationRelativeTo(null);
  30. //      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. //      setVisible(true);
  32.     }
  33.  
  34.     public static void main(String[] args) {
  35. //        try {
  36. //            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  37. //        } catch (Exception e) { }
  38. //
  39. //        SwingUtilities.invokeLater(new Runnable() {
  40.  
  41. //          public void run() {
  42. //              new Archivo2();
  43. ////            }
  44. //      });
  45.     }
  46.  
  47.     public String showSaveFileDialog()
  48.     {
  49.         String dir="";
  50.         JFileChooser fileChooser = new JFileChooser();
  51.         fileChooser.setDialogTitle("Specify a file to save");
  52.  
  53.         int userSelection = fileChooser.showSaveDialog(this);
  54.         if (userSelection == JFileChooser.APPROVE_OPTION) {
  55.             File fileToSave = fileChooser.getSelectedFile();
  56.             System.out.println("Save as file: " + fileToSave.getAbsolutePath());
  57.             dir=fileToSave.getAbsolutePath();
  58.         }
  59.         return dir;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment