As I understand I have to add .getWidth and .getHeight to center. so it
gets like:
int col_l = center.getWidth() / 50;
I just get an exception-error with this, so I guess I do it wrong.
> Yes, you understand the question. These are 2 snippets of code I use:
> > center = new Scherm();
[quoted text clipped - 14 lines]
> > }
> > else if (scherm == 2)
> As I understand I have to add .getWidth and .getHeight to center. so it
> gets like:
>
> int col_l = center.getWidth() / 50;
Something like that, yeah. It really depends on where you want this
information. You've given a line of code above, but not told me where
it's supposed to go. Is it used in Scherm's paintComponent method? Or
somewhere else? If you're getting an exception from that line of code,
then that's almost certainly because the reference 'center' is null when
it's executed... that is, you haven't created the Scherm yet, or you
didn't store it in that reference. If you're getting the exception on a
future line, it could be a lot of things.
(Incidentally, that center.repaint at the end shouldnot be necessary.
Simply displaying it will cause it to be painted.)
> I just get an exception-error with this, so I guess I do it wrong.
So please post the exception message. That's important information
given to you by the compiler about what's going wrong, and it's rather
important to know when trying to diagnose your problem.

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Huub - 06 Dec 2003 19:39 GMT
>>Yes, you understand the question. These are 2 snippets of code I use:
>>
[quoted text clipped - 39 lines]
> given to you by the compiler about what's going wrong, and it's rather
> important to know when trying to diagnose your problem.
In global declaration I put:
> Scherm center;
> int col_l = center.getWidth() / 50;
The 2nd line is instead of this line:
> int col_l = 75;
The 1st errormessage is for the second line.
> Exception in thread "main" java.lang.NullPointerException
> at Standaardscherm.<init>(Standaardscherm.java:24)
> at Standaardscherm.main(Standaardscherm.java:394)
The 2nd message is for the line where the constructor is being created:
> Standaardscherm frame = new Standaardscherm();
Hope it's not getting messy..
Chris Smith - 06 Dec 2003 18:02 GMT
> In global declaration I put:
> > Scherm center;
> > int col_l = center.getWidth() / 50;
That's your problem, then. At that point, there is no Scherm at all.
All you've done is declare a reference variable that is capable of
keeping track of a Scherm in the future. You can't do anything through
that variable until you give it a Scherm object to keep track of.
You earlier posted the following code, which does exactly that:
> >>> center = new Scherm();
So what you need to do, first of all, is make sure that the
"center.getWidth()" call doesn't happen until after the line directly
above. The NullPointerException means exactly that: you're attempting
to communicate with the object that the 'center' variable is referring
to (or in other words, keeping track of), but 'center' isn't referring
to any object yet.
Unfortunately, that's not all. When you first create a Scherm, it will
have a size of zero by zero pixels. It won't be resized to be larger
until after it added to some container, and that container has the
chance to lay it out. That requires either a setSize or pack method
call on the container it's added to. So you don't want to ask for the
size the instant you create an object, either, because that size will
just be zero.
It's really best to just wait until you actually *need* the size, and
figure it out then, rather than trying to ask once and store the value
away somewhere. If you wait until the last possible minute to get the
information, then as long as what you're trying to do makes some
rudimentary sense in the first place, the information you need will be
available.

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Huub - 06 Dec 2003 22:23 GMT
>>In global declaration I put:
>>
[quoted text clipped - 31 lines]
> rudimentary sense in the first place, the information you need will be
> available.
Thank you very much. Using center.getWidth() and center.getHeight() as
the (x,y)-coordinates now. Working ok now.