File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Window arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Window arrays" Watch "Window arrays" New topic
Author

Window arrays

Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 63
Hi,
I'm trying to make an application that has a toolbox. The toolbox has a file menu in which there are(or will be) the standard commands of New, Open, Save, etc...

My problem is that I want to be able to have multiple document windows open and visible at a time. I'm familar with VB in which you would use an object array, however, I tried this technique in Java using the following line of code, and the command prompt filled with text while the app did nothing:



Any ideas?


Life is 10% what happens and 90% how you react to it.
Attitude is everything.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi Derek,

Welcome to JavaRanch!

That's all pretty close; the only problem is that declaring an array variable -- or any variable that's not a primitive type like int, double, float, short, char -- creates only a reference to an object, not the object itself. Your array variable is "null", meaning it points to no array at all. The "console filling with text" is stack dumps resulting from a NullPointerException being thrown when you try to add an element to that non-existent array object.

You have to actually create the array:

public ImageFrame[] canvas = new ImageFrame[10];

That creates an array that would hold ImageFrames. Java arrays have a fixed size. If you need something that might grow over time, look at the java.util.ArrayList class.


[Jess in Action][AskingGoodQuestions]
Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 63
I thought a bout doing that, but logically it seems like the array would then be filled when it's initialized. I wasn't sure if that was the case or not.

Thanks for clearing it up for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Window arrays