Re: question on multidimensional array

From: Andrew Thompson (SeeMySites_at_www.invalid)
Date: 05/31/04


Date: Mon, 31 May 2004 08:24:52 GMT

On Mon, 31 May 2004 09:10:38 +0200, Huub wrote:

>> Short, Self contained, Complileable, Example.
>>
>> To Huub. My Newsreader lists posts
>> by how many lines they are.
>>
>> I just noticed, skimming the group that someone
>> posted a 173 line question, and one of the more
>> experienced members of the group posted a single
>> 250 line reply.
>>
>> Neither of these posts is extraordinary.
>>
>> [ But the shorter the better.. ]

( hinting at shorter than 173 lines.. )

> OK, here's the code (4 classes,

The example only requires two. If you can
pass a 2D arary between one class and another,
you can do it between 6, 10 or 50..

>..error is with the 1st and 2nd). I hope
> I'm not trying to do something impossible.

You are attempting to do something fairly
easy (from your description) but the
'penny has not dropped' yet. You will
kick yourself when it finally makes
sense, you will _then_ wonder how you
ever misunderstood it. ;-)

> import javax.swing.*;
...
> knoppen[9].addActionListener(

OK. I am gonna break in here.

Somebody else may wade through your code,
but I do not have the time to wade through
your 4 classes, spread over a 357 line post,
especially when the source needs to be broken
into separate files to compile, and includes
other compile errors in addition to that..

C:\Spel.java:19: ';' expected.
de knoppen in te plaatsen
          ^
C:\Spel.java:19: Duplicate variable declaration: de knoppen was JButton
knoppen[]
de knoppen in te plaatsen
           ^
C:\Spel.java:22: ';' expected.
het frame
         ^
C:\Spel.java:31: ';' expected.
voor het frame
        ^
C:\Spel.java:39: ';' expected.
en het menu
      ^
C:\Spel.java:274: Public class Speelveld must be defined in a file called
"Speelveld.java".
public class Speelveld
             ^
C:\Spel.java:308: Public class Speler must be defined in a file called
"Speler.java".
public class Speler
             ^
C:\Spel.java:320: Public class Pion must be defined in a file called
"Pion.java".
public class Pion
             ^
8 errors

....
Your SSCCE should be trimmed to under 100 lines.

You can make the 'public' classes 'default' so
that they compile in a single file.

Please have a _careful_ read of the SSCCE document
and you will note that you do not need a UI for this..
Especially not an UI with 9(!) buttons.

As I recall, I provided a self contained
example earlier.. Yeah.. there it is..
<http://groups.google.com/groups?th=7995d61159b0265c#link2>
less than 40 lines of code that can be copy/pasted/compiled/run
that demonstrate passing a 2D array between classes.

Also check Woebegone's even shorter example,
immediately below that post.

It is important to understand how you can
trim code down to the *simplest* code that
demonstrates a problem or solution.

-- 
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Quantcast