Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help passing a value from a function

Status
Not open for further replies.

soas

Technical User
Aug 3, 2001
49
US
Im new to java applet, but it doesnt seem overly complex yet, but I dont get how to use functions from one class to another.. I thought I knew how but I cant find documentation on it from the sdk docs I downloaded

Anyways, heres the program example, Its kind of a pointless program, but you can see what I am trying to accomplish
I just wana figure out how to return the value from the Function class to the test class


import java.applet.*;
import java.awt.*;
import java.awt.Graphics;

public class test extends Applet {
public void paint(Graphics g, Function function)
{
int x;
x = function.getd(50);
g.drawString("Hello!", x, 25);

}
}

class Function
{

public int getd(int d)
{
int d1;
d1 = d+1;
return d1;
}
}


When I try to run it, I dont get any errors, nothing at all happens *Shrug* if anyone can tell me what Im doing wrong I would be really greatful

 
actually, i figured it out on my own like an hour after i asked, too bad i cant delete this hehe
 
Maybe you would like to share the solution?

Otherwise this is indeed completely wasted webspace.

greetz
 
import java.applet.*;
import java.awt.*;
import java.awt.Graphics;

public class test extends Applet {
public void paint(Graphics g)
{
Function function= new Function();
int x;
x = function.getd(1);
g.drawString("Hello!", x, 25);

}
}

class Function
{

public int getd(int d)
{
int d1;
d1 = d*8;
return d1;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top