1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class Nouveau extends JDialog//JFrame
{
[...]
public Nouveau(Frame owner,String name)
{
super(owner,name,true);
contentPane = (JPanel) getContentPane();
contentPane.setLayout(gridBagLayout1);
setSize(new Dimension(300, 250));
setTitle("Nouveau");
setVisible(true);
setResizable(false);
jButton1.setText("Ouvrir");
jButton2.setText("Valider");
[...]
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event1)
{
System.out.println("Ouverture du fichier");
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonText("Choix du fichier...");
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
jTextField7.setText(chooser.getSelectedFile().getAbsolutePath()); //si un fichier est selectionné, récupérer le fichier puis sont path et l'afficher dans le champs de texte
}
}
});
jButton2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event2)
{
Nouveau.this.dispose();
}
}); |
Partager