Voila j'ai le code suivant et je n'arrive pas à avoir une boite de dialogue "selection de fichier" quand je clique sur open, avez vous une idée pourquoi ?
Code :
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.lang.Runtime.*;
class InterfaceGraph
{
publicstaticvoid main(String []args)
{
MaFenetre f1 = new MaFenetre();
}
}
class MaFenetre extends JFrame
{
public MaFenetre()
{
/*creation d'une frame*/
JFrame f = new JFrame("Compilateur Algorithmique" );
/*creation d'une barre menu*/
JMenuBar monMenu = new JMenuBar();
/*ajout du menu "file" et sous_menu open*/
JMenu file = new JMenu("File" );
JMenuItem open = new JMenuItem("Open" );
file.add(open);
open.addActionListener(new OuvrirFichier());
file.addSeparator();
JMenuItem exit = new JMenuItem("Exit" );
exit.addActionListener(new GestionQuitter());
monMenu.add(file);
file.add(exit);
/*creation de boutons*/
f.setSize(700,600);
f.setVisible(true);
System.out.println("Au revoir" );
f.setLocation(100,100);
/*AFFICHAGE*/
f.setJMenuBar(monMenu);
f.addWindowListener(new ferme());
}
}
class OuvrirFichier implements ActionListener
{
publicvoid actionPerformed(ActionEvent evt)
{
JFileChooser choix = new JFileChooser();
choix.showOpenDialog(new JFrame());
}
}
class GestionQuitter implements ActionListener
{
publicvoid actionPerformed(ActionEvent evt)
{
System.exit(0);
}
}
class Compiler implements ActionListener
{
publicvoid actionPerformed(ActionEvent evt)
{
try {
Process p = null;
Runtime r = Runtime.getRuntime();
p = r.exec("compil.sh" );
int x = p.waitFor();
}
catch(Exception wordexp)
{
wordexp.printStackTrace();
}
}
}
/* Permet d'ajouter des actions a la frame */
class ferme implements WindowListener
{
publicvoid windowDeactivated(WindowEvent e)
{};
publicvoid windowActivated(WindowEvent e)
{};
publicvoid windowClosing(WindowEvent e)
{
System.exit(0);
}
publicvoid windowClosed(WindowEvent e)
{};
publicvoid windowOpened(WindowEvent e)
{};
publicvoid windowDeiconified(WindowEvent e)
{};
publicvoid windowIconified(WindowEvent e)
{};
}
Message édité par stan876 le 27-11-2005 à 23:52:20
class InterfaceGraph
{
public static void main(String []args)
{
MaFenetre f1 = new MaFenetre();
}
}
class MaFenetre extends JFrame implements WindowListener
{
public MaFenetre()
{
/*creation d'une frame*/
JFrame f = new JFrame("Compilateur Algorithmique" );
/*creation d'une barre menu*/
JMenuBar monMenu = new JMenuBar();
setJMenuBar(monMenu);
/*ajout du menu "file" et sous_menu open*/
JMenu file = new JMenu("File" );
JMenuItem open = new JMenuItem("Open" );
file.add(open);
open.addActionListener(new OuvrirFichier());
file.addSeparator();
JMenuItem exit = new JMenuItem("Exit" );
exit.addActionListener(new GestionQuitter());
monMenu.add(file);
/*creation de boutons*/
setSize(700,600);
setVisible(true);
System.out.println("Au revoir" );
setLocation(100,100);
/*AFFICHAGE*/
f.addWindowListener(this);
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
class OuvrirFichier implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
JFileChooser choix = new JFileChooser();
choix.showOpenDialog(new JFrame());
}
}
class GestionQuitter implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
}
class Compiler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
try {
Process p = null;
Runtime r = Runtime.getRuntime();
p = r.exec("compil.sh" );
int x = p.waitFor();
}
catch(Exception wordexp)
{
wordexp.printStackTrace();
}
}
}
/* Permet d'ajouter des actions a la frame */
class ferme implements WindowListener
{
public void windowDeactivated(WindowEvent e)
{};
public void windowActivated(WindowEvent e)
{};
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowClosed(WindowEvent e)
{};
public void windowOpened(WindowEvent e)
{};
public void windowDeiconified(WindowEvent e)
{};
public void windowIconified(WindowEvent e)
{};
}