Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import javax.swing.JButton;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- public class Archivo2 extends JFrame {
- private JButton buttonBrowse;
- public Archivo2() {
- // super("Save File Dialog Example");
- // setLayout(new FlowLayout());
- // buttonBrowse = new JButton("Save...");
- // buttonBrowse.addActionListener(new ActionListener() {
- //
- // public void actionPerformed(ActionEvent arg0) {
- // String z="";
- // z=showSaveFileDialog();
- // }
- // });
- // getContentPane().add(buttonBrowse);
- // setSize(300, 100);
- // setLocationRelativeTo(null);
- // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // setVisible(true);
- }
- public static void main(String[] args) {
- // try {
- // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- // } catch (Exception e) { }
- //
- // SwingUtilities.invokeLater(new Runnable() {
- // public void run() {
- // new Archivo2();
- //// }
- // });
- }
- public String showSaveFileDialog()
- {
- String dir="";
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Specify a file to save");
- int userSelection = fileChooser.showSaveDialog(this);
- if (userSelection == JFileChooser.APPROVE_OPTION) {
- File fileToSave = fileChooser.getSelectedFile();
- System.out.println("Save as file: " + fileToSave.getAbsolutePath());
- dir=fileToSave.getAbsolutePath();
- }
- return dir;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment