[4849] in java-interest

home help back first fref pref prev next nref lref last post

Re: Can't call methods in my applet

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Tue Jan 16 18:12:27 1996

Date: Tue, 16 Jan 1996 10:29:41 -0800
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: mikea@ai.mit.edu
Cc: java-interest@java.Eng.Sun.COM


Hi Mike,

> 	I am extending the java.awt.Scrollbar class to enable  the user to
> change more than just the position of the scrollbar.  I wish to update
> some fields in the main applet and thus have created a calculate()
> method in my main applet.
> 	I pass a refrence *Calc) to the applet in the scrollbar constructor,
> but get this error message when I try to call calculate:
> 
> C:\html\classes>c:\jdk2\java\bin\javac slider.java
> slider.java:68: Can't make static reference to method void calculate()
> in class
> Calc.
>                 Calc.calculate();
>                               ^
> 
> Can anyone:  1.  Exlpain this problem -- Why can't I do this?
> 	         2.  Suggest a method by which I can trigger an updating
> 
> 		method in the applet class.

The problem is that you are trying to call an instance method
using a class. "Calc" is a class, not an object. You can only do
that with static methods. You should either use an instance:

	obj.calculate();
	
or declare calculate to be static.

Have fun,

	Arthur van Hoff
	
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post