user interface - Java components from different class -


i trying create components , implement them jframe different classes within program.

i have created jtabbedpane, , each tab represents class. of components each tab placed in respective tabs.

//creates jtabbedpane, , panels. object creation. //panelx corisponds tab number well. tabbs counted left right.  tabpane1 = new jtabbedpane(); jpanel panel1 = new jpanel(); jpanel panel2 = new jpanel(); jpanel panel3 = new jpanel(); jpanel panel4 = new jpanel(); jpanel panel5 = new jpanel(); jpanel panel6 = new jpanel();  jlabel searchlabel1 = new jlabel("hey"); jlabel searchlabel2 = new jlabel("hi");  panel1.add(searchlabel1); panel1.add(searchlabel2);   //searchflight searchflightcomp = new searchflight();   tabpane1.addtab("search flight", panel1);  tabpane1.addtab("select flight", panel2);  tabpane1.addtab("flight price", new jlabel("this tab 1ffff"));   tabpane1.addtab("book ticket", new jlabel("this tab 1fff"));  tabpane1.addtab("book ticket", new jlabel("this tab fs1"));  tabpane1.addtab("payment", new jlabel("this tabgf 1"));  tabpane1.addtab("booking summary", new jlabel("this tabgf 1"));  //added jtabbedpane jframe.   frame.getcontentpane().add(tabpane1); 

this works. working first tab right feel how works ect. dont know how begin. create panel in other class , return it? or extend jframe?

thanks guys!

i assume you're refering commented line:

//searchflight searchflightcomp = new searchflight(); 

you either make searchflight subclass of jpanel or better controller creates jpanel tab , return it, e.g.

searchflight searchflightcomp = new searchflight(); tabpane1.addtab( searchflightcomp.getname(), searchflightcomp.buildpanel() ); 

as general tip should read on mvc pattern. might extent: the mvc pattern , swing


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -