954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Basic problem calling methods within a class

How can i move between different methods with the same class. When i programmed in VB, it was just the name of the subroutine, but i cant figure it out in java. Please put me out of my misery

rick4324528
Newbie Poster
5 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

what do you mean "move between methods"?

You want to call one method from another? Check your textbook, see those braces?

Learn the language syntax and all will become clear, or at least clearer than it is now.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

You use DOT notation (much like you do in VB I think.)

ClassInstanceName.MethodName(Optional parameters)

So if you have:

String myString = "Something";

// Then you could say:
System.out.println( myString.toUpper() );

'.toUpper' is a method of the String class that will output the string in upper case. :cool:

jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
 

Opps, that was to call a method in a class.

Same way in VB. Use the method name. Just consider if you have a return value in the method, if so then you need to assign the return value to the same type.

jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
 

Im still not sure. Heres the actual code

package animation;
import element.*;

public class Animation
{
public static void main (String args[])
{
int DrawingWindowWidth = 600, DrawingWindowHeight = 300;
ConsoleWindow c = new ConsoleWindow();
DrawingWindow d = new DrawingWindow(DrawingWindowWidth,DrawingWindowHeight);
// Draw Environment


}

public static void DrawCraneKitbox (String args[])
{

}



}

im trying to call the DrawCraneKitbox method from within the main method.

rick4324528
Newbie Poster
5 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Simple:

//Assuming you have a String Array (String args[]), lets call it:
String[] myStringArray = new String[2];

// And assuming you initilized myStringArray to somenting, you would have:
DrawCraneKitbox(myStringArray);


Since the Method was decalred asvoid, it has no return type. I would assume you want 'DrawCraneKitbox' to just do something. and then execute the next line of code.

jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You