Des fenetres frame en java

Fermé
mimi.gsm Messages postés 45 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 15 novembre 2010 - 11 déc. 2009 à 22:46
mimi.gsm Messages postés 45 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 15 novembre 2010 - 12 déc. 2009 à 20:20
Bonjour,
j'ai fait un menu qui affiche d'autres menus en appuyant sur ses boutons, le probleme c'est que je ne peux fermer la deuxieme fenetre qu'en fermant la fenetre principale...je suis débutante dans la programmation graphique en java et surtout avec les actionListener et les WindowListener. Je vous montre mon programme:


////////La classe principale:

import java.awt.*;
import java.awt.event.*;

public class Princ extends Frame implements WindowListener,ActionListener{
Button a;
Button b;
public static void main(String[] args) {
Princ myWindow = new Princ("Menu principal");
myWindow.setSize(350,100);
myWindow.setVisible(true);
}

public Princ(String title){
super(title);
setLayout(new FlowLayout());
addWindowListener(this);
a = new Button("1ermenu");
b = new Button("2ememenut");
add(a);
add(b);
a.addActionListener(new Actionaff());
b.addActionListener(new Actionaff());
}
public void actionPerformed(ActionEvent e) {


}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}


}

import java.awt.*;
import java.awt.event.*;

public class Actionaff implements ActionListener{
public void actionPerformed(ActionEvent e){
Fenaff myWindow = new Fenaff("l'autre menu");
myWindow.setSize(350,100);
myWindow.setVisible(true);

}

}


/////////un autre menu
import java.awt.*;
import java.awt.event.*;

public class Fenaff extends Frame implements WindowListener{
Button a;
Button b;

public Fenaff(String title){
a = new Button("un autre menu");
b = new Button("encore un autre");
add(a);
add(b);
setLayout(new FlowLayout());

}


public void windowClosing(WindowEvent e1) {
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e1) {}
public void windowActivated(WindowEvent e1) {}
public void windowIconified(WindowEvent e1) {}
public void windowDeiconified(WindowEvent e1) {}
public void windowDeactivated(WindowEvent e1) {}
public void windowClosed(WindowEvent e1) {}

}
A voir également:

1 réponse

mimi.gsm Messages postés 45 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 15 novembre 2010 1
12 déc. 2009 à 20:20
personne n'a repondu :(((((
0