Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Java compatibility issues (WAS: MF having issues?)
"James J. Gavan" <jgavandeletethis@shaw.ca> wrote in message
news:n6qPf.119714$sa3.33638@pd7tw1no...
>
> Probably a more effective usage, rather than just growing, element by
> element, which means you are repetitively going though an 'expansion'
> procedure. Knowing that you have a list which could contain 100 elements,
> you can start by making the collection have a CAPACITY of 100. You only
> load 50 elements. invoke myCollection "size" returning size. If SIZE is
> less than CAPACITY - stupid method-name coming up - invoke MyCollection
> "growTo" using mySize - "growTo" meaning increase or decrease - adjusting
> your memory requirements.

"ArrayList" is one particular type of collection available in Java. The
documentation for using it is available at
http://java.sun.com/j2se/1.5.0/docs.../ArrayList.html

The way it works is when you create a new ArrayList, you can specify its
initial capacity. If you don't, it just uses some arbitrary non-documented
value (e.g. perhaps 10). If the size of the collection is the same as it's
capacity, and you try to add another item, the collection will silently grow
itself and, now having sufficient capacity, accept your item, all under the
cover without you being aware that anything peculiar has happened.

There's an "ensureCapacity" method which you provide an integer representing
the desired capacity. When you call this, the ArrayList will grow if the
requested capacity is larger than the actual one, or simply ignore your
message if the actual capacity is already larger than the requested one.
There's no direct way of finding out what the actual capacity is (you could
find out by using a debugger, for example).

There's also a "trimToSize" method which takes no arguments or parameters at
all. The intended usage is for when you've finished changing the size of the
collection (i.e. not adding or removing items anymore), you can then
instruct the ArrayList to size itself so that its capacity exactly matches
its current size to save a bit of memory.

>
> So WOULD I ! M/F have support classes to create various collections but
> never figured out how you could do it so that one element could contain
> both the displayable object and the text for the method-name. Perhaps a
> two level collection - but couldn't figure it ? So while I consider it
> clumsy, it works.
>
> Incidentally when defining dictionaries in M/F they can be expressed as
> follows :-
>
>        Key     Data
>        ----    ----
>        Object  Object
>        Object  Text
>        Text    Object
>        Text    Text
>
> Given that you have a Primekey/DB-ID of 12345 and name Joe Blow each can
> be the Key or Data. With those options above you have to specify
> Dictionary structures - that's what I would have liked to have done rather
> than those two Collections I have above. (I wouldn't mind betting Robert
> Wagner could have figured this one for me).

Not sure if I understood the question, but if you want a dictionary and
you want to associate a key with two objects (and always exactly two objects
for every single key), you could create a so-called "Pair" class, pack both
your objects into the pair, then put the pair into the dictionary.

class Pair {
DisplayableObject displayable;
TextForMethodName text;
}

Pair p = new Pair();
p.displayable = myDisplayableObject;
p.text = "Object Label";

dictionary.put("key", p);

Pair anotherPair = dictionary.get("anotherKey");
print(anotherPair.text);

>
> I have my PrimeKey/SQL-ID built into my list elements. And if I use the
> feature display ByKey - that's the sequencing I get. In the case of
> Droplists I don't want to confuse users with mnemonics when selecting
> 'Canada' - tip from Ken Mullins, make the droplist Mono spaced font which
> stretches it out, exceeding the width of your droplist, so that the code
> is hidden to the right.

I don't know if the library you're using supports this, but droplists in
Java can have an "ListCellRenderer" object associated with them. The
ListCellRenderer object takes the actual content of the list, and takes care
of their appearances on the GUI.

For example, maybe the actual contents of your list (i.e. in memory) are
a bunch of text strings like "http://myserver/images/image1.jpg",
"http://myserver/images/image2.jpg", etc.

And the ListCellRenderer doesn't merely display the text, but rather
treats the text as an URL, connects to the server, downloads the file,
treats it as an image, and displays it as one of the items in the drop list.
(Not sure if you've ever seen a droplist with images in them; if not, you
can see what it looks like at
[url]http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#renderer[
/url] )

If your library supports something like a custom renderer, then you
could probably go that route, and just only render the text that you want to
be actually visible. If not, maybe you can take this idea and modify it to
fit with the API of your library.

- Oliver


Report this thread to moderator Post Follow-up to this message
Old Post
Oliver Wong
03-08-06 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:03 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.