ActionListener java swing -
i have being trying create window using swing ad have put buttons on right side that's why used boxlayout can't find way use actionlistener on button have. that's program working on:
public class fenetre2 extends jframe { private jsplitpane splitpan=null; public fenetre2 (){ jpanel pan = new jpanel (); // caracteristique fenetre this.settitle("gestion employe"); this.setsize(800, 400); this.setlocationrelativeto(null); this.setdefaultcloseoperation(jframe.exit_on_close); pan.setbackground(color.white); this.setcontentpane(pan); // add button container c = getcontentpane(); c.setlayout( new borderlayout( 30, 30 ) ); box boxes[] = new box[ 4 ]; boxes[ 0 ] = box.createhorizontalbox(); boxes[ 1 ] = box.createverticalbox(); boxes[ 2 ] = box.createhorizontalbox(); boxes[ 3 ] = box.createverticalbox(); // create strut , add buttons boxes[ 1 ] boxes[ 1 ].add( new jbutton( "ajouter" ) ); boxes[ 1 ].add( new jbutton( "suprimer" ) ); boxes[ 1 ].add( new jbutton( "afficher" ) ); c.add( boxes[ 1 ], borderlayout.east ); //tree defaultmutabletreenode root = new defaultmutabletreenode("structure employe"); //create child nodes defaultmutabletreenode pdgnode = new defaultmutabletreenode("pdg"); defaultmutabletreenode departement1node = new defaultmutabletreenode("departement 1"); departement1node.add(new defaultmutabletreenode("chef departement")); departement1node.add(new defaultmutabletreenode("employee1")); departement1node.add(new defaultmutabletreenode("employee2")); departement1node.add(new defaultmutabletreenode("employee3")); //add child nodes root node root.add(pdgnode); pdgnode.add(departement1node); jtree tree = new jtree(root); this.add(tree); jscrollpane scroll=new jscrollpane(tree); splitpan=new jsplitpane(jsplitpane.horizontal_split,scroll,new jlabel("aaaaa")); splitpan.setsize(this.getmaximumsize()); add(splitpan); this.setvisible(true); } public static void main (string args []){ fenetre2 fen = new fenetre2(); } }
you should not add buttons directly panel instead instantiate them , add actionlistener
them or whatever else want them. example:
jbutton ajouterbutton = new jbutton("ajouter"); ajouterbutton.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { // code goes here } });
then can add button array:
boxes[1].add(ajouterbutton);
then same thing buttons.
Comments
Post a Comment