Article View: borland.public.jbuilder.java.language
Article #14724Re: hiding methods
From: Steve Horsley
Date: Thu, 05 Aug 1999 00:00
Date: Thu, 05 Aug 1999 00:00
35 lines
1633 bytes
1633 bytes
I was pondering this recently. I decided that perhaps the best way
was to prevent the users from creating the class itself, and
providing a public method that creates my class and returns it as a
Component. That way, they can't add other components to it unless
they re-cast the class to a Container or Panel. I can't think of a
way of stopping them from doing that.
Like this:
private class Calculator extends JPanel {
public static Component makeMeOne() { return new Calculator (); }
...
}
Then the user does this:
Component calc = Calculator.makeMeOne();
myContainer.add(calc);
//---------------------------
Marcel van den Dungen wrote:
>
> hi,
>
> i am creating a class that extends Panel and has antoher panel and
> scrollbar laid out with the borderlayout. i want the users of this class
> to be unable to add other components, change the layout and other
> things. does anyone have a clue on how to achieve this, or is this
> inpossible for oop reasons?
>
> hoping that someone can help me out
> tia
> greetings
> casper
Technical Details
Message-ID:
<37A9750D.B0F53C0C@cwcom.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<37A94A3C.7124DC62@c-content.nl>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,c7695f50bddab9ba X-Google-Attributes: gidf74b3,public From: Steve Horsley <steve.horsley@cwcom.co.uk> Subject: Re: hiding methods Date: 1999/08/05 Message-ID: <37A9750D.B0F53C0C@cwcom.co.uk> X-Deja-AN: 509143304 Content-Transfer-Encoding: 7bit References: <37A94A3C.7124DC62@c-content.nl> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Cable & Wireless Communications Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language