|
|
|
| Web Hosting Guide |
![]() ![]() |
Simple Java Question, One Variable; Multiple Classes |
Jun 4 2008, 07:05 PM
Post
#1
|
|
|
Sparkx Group: [HOSTED] Posts: 376 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 myCENTs:55.07 |
I’m probably the only person that is able to do so much with Java3D and yet still can't even get some of the Java basics down. Anyway is it (and if so how is it) possible to make a variable editable and readable in multiple class files? It seems like this should be an easy question to answer, but here is a little code to help you understand what I am talking about.
CODE public class test extends Applet{ That should give you the basics what I am doing. I’m just trying to get the collision results back into my original class not just the Behavior class. public int Col = 0; [some long code basically all it does is call for a collision behavior] [(TestB multiple times every 100 milliseconds).] if(Col==1){ [...Some collision handling...] } } class TestB extends Behavior { [I check my collision now I want to set the variable so it can be accessed later] if(collision == true){ Col = 0; }else{ Col = 1; } } Thanks in advanced for helping me with this problem, Sparkx Edit: Spacing and Smilies fixed. This post has been edited by sparkx: Jun 4 2008, 07:07 PM |
|
|
|
Jun 5 2008, 05:28 PM
Post
#2
|
|
|
Whitest Black Mage Group: [MODERATOR] Posts: 1,381 Joined: 20-May 05 From: NB, Canada Member No.: 5,281 myCENTs:93.97 |
You could make use of global variables but they are not always the best idea since it's easy to introduce coding problems into applications by making wide use of globals. A good alternative is to simply pass the variables to the constructors or other methods for the different classes and store the true value in a variable in main and just have the various classes modifying the original value.
|
|
|
|
Aug 25 2008, 01:24 AM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: [HOSTED] Posts: 29 Joined: 16-August 08 Member No.: 32,092 |
Try declaring a public variable so you can used with all of the clases, or a protected type so it can be used only by the clases that are in the same package.
For example, public class startProgram{ public static int counter=0; ....... } Then when you want to call it from another class(adding 1): startProgram.counter++; This will be the same with a protected variable type, but you have to we aware that the classes were you are using the global variable are in the same package. Declaring it protected is better for security reasons(like I said before this variable is only reachable from the classes in the same package). If you need more help just write again in this topic I will review it in a time from now. Greetings, shotgun. ------------- OS:Windows Vista Ultimate Sp1 MD:Asus P5N-E CPU:2.40GHz/Intel Quad Core Q6600 RAM:Corsair Dual Channel 4GB 800Mhz VC:XFX GeForce 9800 GTX/512MB |
|
|
|
Aug 25 2008, 06:02 AM
Post
#4
|
|
|
Advanced Member Group: [HOSTED] Posts: 145 Joined: 7-November 05 Member No.: 9,489 myCENTs:33.08 |
Hi, How about if the startProgram.counter be able modify by different threads.
How do I sync it correctly ? Do I need to place this call in a method configured as synchronized ? Thanks, P.S. I'am new to java and still learning it. |
|
|
|
Apr 22 2009, 07:02 AM
Post
#5
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
java3d
Simple Java Question global or not, java3d threads (behaviour) cannot talk with runtime threads. Thats why finishing your work in alive behaviours is a must not an ease! -reply by tugalsan |
|
|
|
Nov 4 2009, 12:29 AM
Post
#6
|
|
|
Don't Worry, I'm here Group: Members Posts: 239 Joined: 3-October 09 From: Northeast, United States of America Member No.: 43,278 myCENTs:21.01 |
I don't get what your doing.
|
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
8 | xboxrulz | 1,243 | Yesterday, 08:31 PM Last post by: iG-Anon |
|||
![]() |
11 | divinity | 1,544 | 4th November 2009 - 12:35 AM Last post by: HannahI |
|||
![]() |
7 | amit nigam | 1,198 | 4th November 2009 - 12:33 AM Last post by: HannahI |
|||
![]() |
4 | rahid | 872 | 4th November 2009 - 12:27 AM Last post by: HannahI |
|||
![]() |
7 | bluefish | 2,757 | 3rd November 2009 - 09:29 PM Last post by: HannahI |
|||
![]() |
14 | sandeep | 2,276 | 3rd November 2009 - 09:11 PM Last post by: iG-rick |
|||
![]() |
19 | lonebyrd | 3,521 | 1st November 2009 - 03:49 PM Last post by: iG-Lukenda |
|||
![]() |
6 | FearfullyMade | 2,863 | 28th October 2009 - 08:14 PM Last post by: HannahI |
|||
![]() |
7 | TavoxPeru | 219 | 22nd October 2009 - 07:48 PM Last post by: starscream |
|||
![]() |
17 | vicky99 | 6,268 | 17th October 2009 - 11:51 AM Last post by: surfermac |
|||
![]() |
12 | WeaponX | 1,609 | 8th October 2009 - 07:59 PM Last post by: HannahI |
|||
![]() |
5 | vicky99 | 2,115 | 6th October 2009 - 07:02 AM Last post by: iG-Daniel |
|||
![]() |
14 | Normano | 1,196 | 3rd October 2009 - 07:44 PM Last post by: iG-anonymous |
|||
![]() |
0 | starscream | 87 | 24th September 2009 - 12:14 PM Last post by: starscream |
|||
![]() |
7 | suicide | 5,069 | 5th September 2009 - 02:11 PM Last post by: iG-sam |
|||
|
Lo-Fi Version | Time is now: 8th November 2009 - 06:48 PM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Jun 4 2008, 07:05 PM





