|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
help on small java matter.
Someone, please help.
I have a variable in class PrintCalendar.java, the variable is of type String, and is named monthString. It is in the main method. It holds an String array of months, and I also have an applet named CalendarApplet.java, and I want to use the value of the variable monthString from PrintCalendar.java in CalendarApplet.java. How on earth do I call it to CalendarApplet.java? Does it need to be declared again? Argh, I am pulling my teeth out over it. |
|
#2
|
||||
|
||||
|
Can you not just pass the variable to the method in the other class, or are you getting an error?
Make sure you've imported the class and created an instance of it... you can then call methods accordingly... remember that arrays are passed by reference, so any changes you make effect the array globally... |
|
#3
|
|||
|
|||
|
does not answer what I needed to know. I dont know how to pass the variable, thats the whole problem.
|
|
#4
|
||||
|
||||
|
[disclaimer]The following code is untested and off the top of my head... it may contain errors... also you will need to change it around to suit your needs, but I feel it gives a decent example of how to accomplish it. [/disclaimer] =)
The method that receives the variable: Code:
public class MyObject {
//some code
public static void myMethod(String argument)
{
System.out.println(argument);
}
//some code
}
then to call the method: Code:
String welcome = "Hello World"; MyObject obj = new MyObject(); obj.myMethod(welcome); |
|
#5
|
|||
|
|||
|
thanks do0d, much appreciated
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > help on small java matter. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|