Thread Tools
Old April 1, 2003, 17:36   #1
reds4ever
Prince
 
reds4ever's Avatar
 
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
reds4ever is offline  
Old April 1, 2003, 19:05   #2
raghar
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; ?
raghar is offline  
Old April 1, 2003, 19:07   #3
Skanky Burns
Alpha Centauri Democracy GameACDG The Cybernetic ConsciousnessC4DG Team Alpha CentauriansApolytoners Hall of FameACDG3 Spartans
 
Skanky Burns's Avatar
 
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).
Skanky Burns is offline  
Old April 1, 2003, 20:07   #4
reds4ever
Prince
 
reds4ever's Avatar
 
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
reds4ever is offline  
Old April 1, 2003, 20:16   #5
Skanky Burns
Alpha Centauri Democracy GameACDG The Cybernetic ConsciousnessC4DG Team Alpha CentauriansApolytoners Hall of FameACDG3 Spartans
 
Skanky Burns's Avatar
 
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).
Skanky Burns is offline  
Old April 1, 2003, 20:45   #6
reds4ever
Prince
 
reds4ever's Avatar
 
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
reds4ever is offline  
Old April 1, 2003, 21:22   #7
Skanky Burns
Alpha Centauri Democracy GameACDG The Cybernetic ConsciousnessC4DG Team Alpha CentauriansApolytoners Hall of FameACDG3 Spartans
 
Skanky Burns's Avatar
 
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).
Skanky Burns is offline  
Old April 1, 2003, 21:34   #8
reds4ever
Prince
 
reds4ever's Avatar
 
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
reds4ever is offline  
Old April 1, 2003, 21:45   #9
raghar
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.
raghar is offline  
Old April 1, 2003, 21:54   #10
reds4ever
Prince
 
reds4ever's Avatar
 
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.....!!
reds4ever is offline  
Old April 1, 2003, 22:09   #11
raghar
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.
raghar is offline  
Old April 1, 2003, 22:11   #12
Skanky Burns
Alpha Centauri Democracy GameACDG The Cybernetic ConsciousnessC4DG Team Alpha CentauriansApolytoners Hall of FameACDG3 Spartans
 
Skanky Burns's Avatar
 
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).
Skanky Burns is offline  
Old April 1, 2003, 22:22   #13
reds4ever
Prince
 
reds4ever's Avatar
 
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?
reds4ever is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 18:55.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team