Erreur pas compris

Résolu
cs_saif87 Messages postés 35 Date d'inscription dimanche 7 décembre 2008 Statut Membre Dernière intervention 16 juin 2010 - 18 déc. 2008 à 16:15
cs_saif87 Messages postés 35 Date d'inscription dimanche 7 décembre 2008 Statut Membre Dernière intervention 16 juin 2010 - 19 déc. 2008 à 11:00
bonjour je suis débutant en graphique de java et je veut créer une application pour une gestion bancaire donc il y'a une interface graphique(frame)composer de 3 boutton
b1:creation du client
b2:cretaion du compte
b3:affichage des inforamtion
si l'utilisateur tape b1 une frame apparait composer d'une suite de zone de text
et ainsi de suite......
voici mon code mais l'orsque je tape le boutton 3 frame apparait
 aidez moi svp
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel
{
    ButtonPanel()
    {
       
        JButton client=new JButton("cree un client");
        JButton compte=new JButton("cree un compte");
        JButton information=new JButton("afficher vos informations");
        add(client,BorderLayout.WEST);
        add(compte,BorderLayout.CENTER);
        add(information,BorderLayout.EAST);
        client.addActionListener(new ColorAction());
        compte.addActionListener(new ColorAction());
        information.addActionListener(new ColorAction());
    }

   
    class ColorAction implements ActionListener
    {
       
    ColorAction()
        {
        }

    public void actionPerformed(ActionEvent event)
        {
            //setBackground(color);
            Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
            int w=screenSize.width;
            int h=screenSize.height;
           

            JFrame frame1=new MainFrame(w/2,h/2,100,100,"frame1");
            //setBackground(color);
            /*frame.setBackground(Color.red);*/
            frame1.show();
           
            JFrame frame2=new MainFrame(w/2,h/2,100,100,"frame2");
            //setBackground(color);
            /*frame.setBackground(Color.red);*/
            frame2.show();
            JFrame frame3=new MainFrame(w/2,h/2,100,100,"frame3**");
            //setBackground(color);
            /*frame.setBackground(Color.red);*/
            frame3.show();

        }
    }
}
class MainGraphique4
{
  public static void main(String[] args)
    {
        Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
        int w=screenSize.width;
        int h=screenSize.height;
        JFrame frame=new MainFrame(w/2,h/2,0,0,"GESTION BANCAIRE");

    //    JFrame frame=new MainFrame(300,150,400,0);
        frame.show();
    }
   
}
class MainFrame extends JFrame
{
   MainFrame(int w,int h,int x,int y,String ch)
    {
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setTitle(ch);
       setSize(w,h);
       setLocation(x,y);
       getContentPane().add(new ButtonPanel());
       //setBackground();
    }
    /* MainFrame(int w,int h,int x,int y,Color c)
    {
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setTitle("soussi saif ");
       setSize(w,h);
       setLocation(x,y);
       getContentPane().add(new ButtonPanel());
       setBackground(c);
    }*/
}
j'utilise le jdk 1.4 c'est une obligation du prof
merci.

2 réponses

uhrand Messages postés 491 Date d'inscription samedi 20 mai 2006 Statut Membre Dernière intervention 15 juillet 2012 9
19 déc. 2008 à 04:56
Remarque: "show()" est déconseillé et remplacé par "setVisible(true)".
Une application n'a qu'un seul JFrame, les fenêtres auxiliaires étant réalisées par JDialog:

/*
 * MainGraphique4.java
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel implements ActionListener{
    private JButton client, compte, information;
    ButtonPanel() {
        client = new JButton("cree un client");
        compte = new JButton("cree un compte");
        information = new JButton("afficher vos informations");
        add(client, BorderLayout.WEST);
        add(compte, BorderLayout.CENTER);
        add(information, BorderLayout.EAST);
        client.addActionListener(this);
        compte.addActionListener(this);
        information.addActionListener(this);
    }
    public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
        JDialog d = null;
        JFrame parent = (JFrame)SwingUtilities.getRoot(ButtonPanel.this);
        if (source == client) {
            d = new JDialog(parent, "Nouveau Client", true);
        } else if (source == compte) {
            d = new JDialog(parent, "Nouveau Compte", true);
        } else if (source == information) {
            d = new JDialog(parent, "Informations", true);
        }
        if(d != null){
            d.setSize(400, 300);
            d.setLocationRelativeTo(parent);
            d.setVisible(true);
        }
    }
}
public class MainGraphique4 {
    public static void main(String[] args) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int w = screenSize.width;
        int h = screenSize.height;
        JFrame frame = new MainFrame(w / 2, h / 2, 0, 0, "GESTION BANCAIRE");
        frame.setVisible(true);
    }
}
class MainFrame extends JFrame {
    MainFrame(int w, int h, int x, int y, String ch) {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle(ch);
        setSize(w, h);
        setLocation(x, y);
        getContentPane().add(new ButtonPanel());
    }
}
3
cs_saif87 Messages postés 35 Date d'inscription dimanche 7 décembre 2008 Statut Membre Dernière intervention 16 juin 2010
19 déc. 2008 à 11:00
Merci Monsieur sa fonctionne bien je veut continuer mon travaille
0
Rejoignez-nous