ciao a tutti, compilando ed eseguendo il codice sotto riportato all'azione File->open non mi si "apre" subito il file selezionato ma mi esce:
in prima battuta la finestra "sposta elementi"
se annullo
la finestra "copia elementi"
se annullo
finalmente mi esegue il file selezionato.
Se eseguo l'azione di copia o sposta file tramite le finestre precedenti l'azione principiale (open) non viene eseguita!!!
La mia piattaforma è la 1.6 se eseguo l'applicazione su altre macchina con altre versioni di java tutto va come dovrebbe...
Chi mi dice perche non mi va sulla 1.6???????????
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package my.DesktopDemo;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URI;
import javax.swing.*;
/**
*
* @author baric
*/
public class DesktopDemo {
/** Creates a new instance of DesktopDemo */
static Desktop desktop;
public static void main(String[] args) {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
} else {
System.out.println("Desktop class is not supported");
System.exit(1);
}
JMenuItem openItem = new JMenuItem("Open");
JMenuItem editItem = new JMenuItem("Edit");
JMenuItem printItem = new JMenuItem("Print");
JMenuItem browseToItem = new JMenuItem("Go to www.java2s.com");
JMenuItem mailToItem = new JMenuItem("Email to a@java.com");
JMenu fileMenu = new JMenu("File");
JMenu mailMenu = new JMenu("Email");
JMenu browseMenu = new JMenu("Browser");
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int retval= chooser.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
try {
ile file=chooser.getSelectedFile().getAbsoluteFile();
desktop.open(file);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
fileMenu.add(openItem);
editItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
desktop.edit(chooser.getSelectedFile().getAbsolute File());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
fileMenu.add(editItem);
printItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
desktop.print(chooser.getSelectedFile().getAbsolut eFile());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
fileMenu.add(printItem);
browseToItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
URI browseURI = new URI("www.java2s.com");
desktop.browse(browseURI);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
});
browseMenu.add(browseToItem);
mailToItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
URI mailURI = new URI("mailto:support@java.com");
desktop.mail(mailURI);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
});
mailMenu.add(mailToItem);
JMenuBar jMenuBar = new JMenuBar();
jMenuBar.add(fileMenu);
jMenuBar.add(browseMenu);
jMenuBar.add(mailMenu);
JFrame frame = new JFrame();
frame.setTitle("Desktop Helper Applications");
frame.setSize(300, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setJMenuBar(jMenuBar);
frame.setVisible(true);
}
}