Re-Arbres java

CicinhoRaul Messages postés 221 Date d'inscription lundi 18 juin 2007 Statut Membre Dernière intervention 16 janvier 2009 - 18 juil. 2007 à 15:29
CicinhoRaul Messages postés 221 Date d'inscription lundi 18 juin 2007 Statut Membre Dernière intervention 16 janvier 2009 - 18 juil. 2007 à 21:23
Salut je voulais juste demander comment ferait-on pour afficher une fenetre lors d'un clic sur un bouton .

En effet ,j'arrive à créer une nouvelle branche mais j'aimerai qu'elle contienne une fenetre identique à celles deja existantes.

Merci .

2 réponses

cs_GodConan Messages postés 2113 Date d'inscription samedi 8 novembre 2003 Statut Contributeur Dernière intervention 6 octobre 2012 12
18 juil. 2007 à 19:58
une fenetre?!!! emploi les dénomination java ce sera plus simple de te comprendre... ou soit plus explicite...

GodConan ;o)
0
CicinhoRaul Messages postés 221 Date d'inscription lundi 18 juin 2007 Statut Membre Dernière intervention 16 janvier 2009
18 juil. 2007 à 21:23
Salut, quans tu execute le programme tu remarque qu'il y a une branche qui lors du clique nous donne le premier formulaire avec nom,prenom,date de naissance , ok et nouveau.

Mais le probleme est que je souhaiterais des que je clique sur "Nouveau":

1- une nouvelle branche d'arbre se crée
2-lors du clic sur cette branche on a la meme fenetre avec Nom prenom,date de naissance ok et nouveau
3- et donc ainsi de suite quand tu cliqueras sur nouveau à chaque fois dans la nouvelle fenetre tu creeras une nouvelle branche.

Voici le code(merci d'avoir repondu une premiere fois):

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;


/* PROGRAMME PAGE 846 DU LIVRE */


public class JTreeEvents extends JApplet implements ActionListener
{
 /**
  *
  */
 private static final long serialVersionUID = 1L;
 JTree tree;
 JTextField jtf;
 CardLayout Carte;
 JPanel panneauDroite;
 static JTextField nom,prenom,datedenaissance,loisirs,langagesinfos,age;
 static JButton ok,nouveau;
 static JButton nouvellephase2;
 DefaultMutableTreeNode top,a;
 
 public void init()
 {
  
  nouveau = new JButton("Nouveau");
  nouveau.addActionListener(this);
  
  ok = new JButton("OK");
  ok.addActionListener(this);
  
  nouvellephase2 = new JButton("Nouvelle Phase 2");
  nouvellephase2.addActionListener(this);
  
  nom = new JTextField(10);
  nom.addActionListener(this);
  
  prenom = new JTextField(10);
  prenom.addActionListener(this);
  
  datedenaissance = new JTextField(10);
  datedenaissance.addActionListener(this);
  
  loisirs = new JTextField(10);
  loisirs.addActionListener(this);
  
  langagesinfos = new JTextField(10);
  langagesinfos.addActionListener(this);
  
  age = new JTextField(10);
  age.addActionListener(this);
  
  Container contentPane = this.getContentPane();
 
  JPanel panneau = new JPanel(new BorderLayout());
  panneauDroite = new JPanel();
  
  JPanel Phase1 = new JPanel();
  Phase1.add(new JLabel("Nom"));
  Phase1.add(nom);
  Phase1.add(new JLabel("Prenom"));
  Phase1.add(prenom);
  Phase1.add(new JLabel("Date de Naissance"));
  Phase1.add(datedenaissance);
  Phase1.add(ok);
  Phase1.add(nouveau);
  
  JPanel Phase2 = new JPanel();
  Phase2.add(new JLabel("Loisirs"));
  Phase2.add(loisirs);
  Phase2.add(new JLabel("Langages infos"));
  Phase2.add(langagesinfos);
  Phase2.add(new JLabel("Age"));
  Phase2.add(age);
  Phase2.add(nouvellephase2);
  
  
  Carte = new CardLayout();
  
  panneauDroite.setLayout(Carte);
  panneauDroite.add("Phase1",Phase1);
  panneauDroite.add("Phase2",Phase2);
  
  contentPane.add(panneau);
  JPanel panneauTree = new JPanel(new BorderLayout());
  
  JSplitPane unSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panneauTree,panneauDroite);
  panneau.add(unSplitPane);
  
  top = new DefaultMutableTreeNode("Options");
  
  a = new DefaultMutableTreeNode("A");
  top.add(a);
  
  DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
  a.add(a1);
  
  DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
  a.add(a2);
    
  DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
  top.add(b);
  
  DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
  b.add(b1);
  
  DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
  b.add(b2);
  
  tree = new JTree(top);
  
  int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
  int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
  JScrollPane jsp = new JScrollPane(tree,v,h);
  
  panneauTree.add(jsp, BorderLayout.CENTER);
   
  jtf = new JTextField("",20);
  panneauTree.add(jtf,BorderLayout.SOUTH);
  
  tree.addMouseListener(new MouseAdapter()
  {
   public void mouseClicked(MouseEvent me)
   {
    doMouseClicked(me);
   }
  });
 }
 
 void doMouseClicked(MouseEvent me)
 {
  TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
  
  if (tp != null)
  {
   
    Object[] mytp = tp.getPath();
   
   if (mytp.length >= 3)
   {
    jtf.setText(mytp[2].toString());
    Carte.show(panneauDroite,"Phase2");
   }
   else if (mytp.length == 2)
   {
    jtf.setText(mytp[1].toString());
    Carte.show(panneauDroite,"Phase1");
   }
  }
  
 }
 
 public void actionPerformed(ActionEvent evt)
 {
  if(evt.getSource() == nouveau)
  {
   
   tree = new JTree(top);
   int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
   int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
   JScrollPane jsp = new JScrollPane(tree,v,h);
   DefaultMutableTreeNode coucou = new DefaultMutableTreeNode("Nouveau");
   top.add(coucou);
  
   nom = new JTextField(10);
   nom.addActionListener(this);
   
   prenom = new JTextField(10);
   prenom.addActionListener(this);
   
   datedenaissance = new JTextField(10);
   datedenaissance.addActionListener(this);
     
   nouveau = new JButton("Nouveau");
   nouveau.addActionListener(this);
   
   ok = new JButton("OK");
   ok.addActionListener(this);
   
   JPanel Phase1 = new JPanel();
   
   Phase1.add(new JLabel("Nom"));
   Phase1.add(nom);
   Phase1.add(new JLabel("Prenom"));
   Phase1.add(prenom);
   Phase1.add(new JLabel("Date de Naissance"));
   Phase1.add(datedenaissance);
   Phase1.add(ok);
   Phase1.add(nouveau);
   
   panneauDroite.add("Phase1",Phase1);
   
   DefaultMutableTreeNode salut = new DefaultMutableTreeNode("New");
   coucou.add(salut);
   JPanel Phase2 = new JPanel();
   Phase2.add(new JLabel("Loisirs"));
   Phase2.add(loisirs);
   Phase2.add(new JLabel("Langages infos"));
   Phase2.add(langagesinfos);
   Phase2.add(new JLabel("Age"));
   Phase2.add(age);
   Phase2.add(nouvellephase2);
   panneauDroite.add("Phase2",Phase2);
   
   
   SwingUtilities.updateComponentTreeUI(this);
   
   
  }
  
  if(evt.getSource() == nouvellephase2)
  {
   DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("A2");
   a.add(a3);
  }
 }
}
0
Rejoignez-nous