Article View: borland.public.jbuilder.java.language
Article #17595Re: Inheritance and Applets
From: Greg Hamer
Date: Sat, 24 Oct 1998 00:00
Date: Sat, 24 Oct 1998 00:00
95 lines
4094 bytes
4094 bytes
The designer does not do this very well, if at all. The designer can design
individual panels, and if you had some method to expose each page of your
tabset panel as a Panel of its own, you could design the individual pages.
Admitedly this is a lot of hoops to jump through, but if you are interested
...
Say you have an Applet that has a tabsetPanel with two pages:
public class BaseApplet extends Applet
TabsetPanel tabsetPanel = new TabsetPanel();
Panel page1 = new Panel();
Panel page2 = new Panel();
...
public BaseApplet() {
//when the designer instantiates this class when we design things that are
extending it, jbInit needs to run, and that is done from the init method,
so to get it to work in the designer without messing up at runtime...
if (java.beans.Beans.isDesignTime())
init();
}
private void jbInit()
{
tabsetPanel.add(page1,"page 1");
tabsetPanel.add(page2,"page 2");
this.add(tabsetPanel,BorderLayout.CENTER);
}
Now you want to extend it and customize the individual pages
so you add some methods to the base class...
public Panel getPage(int pageNumber) {
switch (pageNumber) {
case 1:
return page1;
case 2:
return page2;
}
public TabsetPanel getTabsetPanel() {
return tabsetPanel;
}
So then you extend BaseApplet and want to customize the indivual pages, and
maybe add a third page
public class Applet1 extends BaseApplet;
//Parent-less Containers that designer will be willing to design
Panel basepage1;
Panel basepage2;
TabsetPanel tabsetPanel;
...
//initialize by hand the components that you will be customizing using the
methods that you added to BaseApplet
private void jbInit() {
basepage1 = this.getPanel(1); //assign basepage1 to page1; the designer
will call a method, but would not understand basepage1 = page1;
basepage2 = this.getPanel(2);
tabsetPanel = this.getTabsetPanel();
}
Now when you go into design, you can design 'this', page1, page2 or the
tabsetPanel by selecting them in the tree, right clicking, and choosing
activate designer.
By designing the tabsetPanel, you can add pages to it, but not play with
the pages added by the superclass.
By designing page1 or page2, you can add stuff to the page, but you cannot
remove stuff added by the superclass.
Note that since it is a TabsetPanel we are designing, only one of the pages
is visible at a time, so when you activate the designer
for page2, you need to change the visible property to true in order to see
it. You will want to remove this property setting
by hand after you are done. Another thing to watch out for is that as you
are adding components via the designer, the designer is oblivious to any
name conflicts with existing variables in the base class, so it it best to
rename everything in the base class so that the designer's automatically
generated names will not match something from the base class.
Brian Hughes wrote:
> Hi -
>
> I am trying to design a series of applets that have the same basic
> behavior and graphical setup. I want to inherit from a base class that
> has a tabset container and a couple of panels and buttons. The
> subclasses of this base or parent class are able to "see" these
> components at compile-time, but I can't visually manipulate these
> components in the subclasses. How do I go about seeing inherited
> components in the design tab of JBuilder? Thanks for your help.
>
> --
> J. Brian Hughes
>
> Software Engineer
> R&D Switch Group
> NACT Telecommunications, Inc.
Technical Details
Message-ID:
<3632B29B.13988C6F@inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<362D1F7B.F042A09F@nact.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,11664b4082ef1ce4 X-Google-Attributes: gidf74b3,public From: Greg Hamer <ghamer@inprise.com> Subject: Re: Inheritance and Applets Date: 1998/10/24 Message-ID: <3632B29B.13988C6F@inprise.com> X-Deja-AN: 404786899 Content-Transfer-Encoding: 7bit References: <362D1F7B.F042A09F@nact.com> Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language