Jump to content
  • Advertisement
Sign in to follow this  
hisDudeness

globals and custom functions in applets

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My program uses custom functions that I define and declare. However Java requires that all methods be contained inside of a class. I went ahead and made a class called CustomFunctions, which has all of the custom methods my program uses. I haven't compiled it yet (too many other errors), but I am assuming that in order for another function to gain access to my custom functions, I simply need to pass the function an instance of my CustomFunctions class and use the dot-operator to reference a method of the CustomFunctions object. Example: class CustomFunctions { int method1() { /* blah */ } int method2(byte b) { /* blah */ } // ... } // ... inside JApplet OR any other class for that matter CustomFunctions cf = new CustomFunctions(); int x = cf.method1(); But, surely there must be a better/easier way of doing this.... Can I just write my own custom functions inside the applet class instead of making my own class, or does JApplet only allow the life cycle method(init, start, stop, destroy,etc.) to be defined? Is there an easier way of going about all this?? Also, I defined several constants in my JApplet class that, in C++, would be globals for all the functions to use. Example: // inside CustomFunctions class' method2() int method2(byte b) { if(b == CONSTANT_1) {} else if(b == CONSTANT_2) {} // CONSTANT_1 and _2 defined in JApplet // ... etc. } How do I make the other Java classes (other than JApplet) aware of these constants so I can check for their values in conditional statements?

Share this post


Link to post
Share on other sites
Advertisement
I'm not very familiar with Java, and not at all familiar with JApplet, but I think what you're after is "static final" member variables. I'm not sure how that works out for member functions, but IIRC you should be able to do something similar there as well. In any case checking your Java documentation for "static" and "final" should at least point you in the right direction.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!