April 1, 2003, 17:36
|
#1
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
Java quickie
can someone tell me why passing this boolean argument:
ballThread[i] = new Thread(new BallThread (ballArray [i], even)
to this:
public BallThread (Ball b, boolean e)
causes an error? it compiles fine without the boolean, all the variables are declared etc
even is just a boolean value based on whether an object in a thread is odd or even
cheers
|
|
|
|
April 1, 2003, 19:05
|
#2
|
Chieftain
Local Time: 22:55
Local Date: November 1, 2010
Join Date: Oct 2002
Location: I wish somewhere else.
Posts: 34
|
Are you sure that boolean even=true; ?
|
|
|
|
April 1, 2003, 19:07
|
#3
|
Local Time: 09:55
Local Date: November 2, 2010
Join Date: Aug 2001
Location: Skanky Father
Posts: 16,530
|
What exactly is the error when you try to compile it?
__________________
I'm building a wagon! On some other part of the internets, obviously (but not that other site).
|
|
|
|
April 1, 2003, 20:07
|
#4
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
thanks for responding, i'm still finding my feet with this, in answer to your questions
even = ((i %2) ==0);
that gives true or false?
the error is: 'constructor BallThread (Ball, boolean) not found in class .......'
as soon as i stop passing the boolean argument the program complies ok
thanks
|
|
|
|
April 1, 2003, 20:16
|
#5
|
Local Time: 09:55
Local Date: November 2, 2010
Join Date: Aug 2001
Location: Skanky Father
Posts: 16,530
|
Thought so.
You need a constructor BallThread (Ball, boolean) in the BallThread class that instanciates a BallThread object.
In other words, find the BallThread (Ball) object, copy the whole "function" and paste it below, then add a boolean functionality.
To explain what I mean, this is a quick demonstration.
Code:
|
BallThread( Ball b )
{
//This is your original function
this.ball = b;
}
BallThread( Ball b, boolean e )
{
//This is the new one you create
this.ball = b;
this.even = e;
} |
Hope this helps.
__________________
I'm building a wagon! On some other part of the internets, obviously (but not that other site).
|
|
|
|
April 1, 2003, 20:45
|
#6
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
many thanks Skanky, thats exacty what i needed! i was on the crest of a wave being able to tell if a number was odd or even!
even = ((i %2) ==0); // in one line as well!!!
line, then that error came up.
i still don't understand why i need the line 'even=e' before i use it, 'e' is passed to the constructor why can't i use it 'as-is'
thanks
|
|
|
|
April 1, 2003, 21:22
|
#7
|
Local Time: 09:55
Local Date: November 2, 2010
Join Date: Aug 2001
Location: Skanky Father
Posts: 16,530
|
That was just for demonstration purposes. In my example, the object stores that value for later use. For your program, you may use it when you initiate the object or store it too - what you need to do with it depends very much on what your program is doing and, well, what you need that value for.
Basically, if you don't need to store the value, then you don't need that line.
__________________
I'm building a wagon! On some other part of the internets, obviously (but not that other site).
|
|
|
|
April 1, 2003, 21:34
|
#8
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
gotcha! thats what i couldn't understand
thanks again
|
|
|
|
April 1, 2003, 21:45
|
#9
|
Chieftain
Local Time: 22:55
Local Date: November 1, 2010
Join Date: Oct 2002
Location: I wish somewhere else.
Posts: 34
|
Quote:
|
Originally posted by reds4ever
new BallThread (ballArray [i], ((i %2) ==0))
|
And I don't understand how can someone write one custom constructor and forget to write second.
Please tell me that you are just few week old student of Java, or you are heavilly overworked person.
|
|
|
|
April 1, 2003, 21:54
|
#10
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
Quote:
|
Originally posted by raghar
And I don't understand how can someone write one custom constructor and forget to write second.
Please tell me that you are just few week old student of Java, or you are heavilly overworked person.
|
got my first 'idiots guide' book the end of Febuary, weve all got to start sometime!!
i'll get there in the end, in the meantime, be on standby.....!!
|
|
|
|
April 1, 2003, 22:09
|
#11
|
Chieftain
Local Time: 22:55
Local Date: November 1, 2010
Join Date: Oct 2002
Location: I wish somewhere else.
Posts: 34
|
Well, it took me 6 months to find difference between public main (String ) and public main (string). I looked at Delphi at that time period and didn't have time to look at it properly. BTW it was windoze fault. It closed console window so quickly so I have no chance to see error message.
|
|
|
|
April 1, 2003, 22:11
|
#12
|
Local Time: 09:55
Local Date: November 2, 2010
Join Date: Aug 2001
Location: Skanky Father
Posts: 16,530
|
I open a dos window for compiling, just so I can see the errors (if they ever occur)
__________________
I'm building a wagon! On some other part of the internets, obviously (but not that other site).
|
|
|
|
April 1, 2003, 22:22
|
#13
|
Prince
Local Time: 23:55
Local Date: November 1, 2010
Join Date: Mar 2001
Location: of the Spion Kop
Posts: 861
|
i'm getting a lot of 'Doh!' moments, if you know what i mean?
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -4. The time now is 18:55.
|
|