Hello,
I created a .java code file in Visual J#.Net and converted it into
the application by adding the "public static void main(String args[])"
function.
I have created the two classes one extends from Applet, and the other
extends from Frame. The class which I inherited from the Frame class becomes
the inner class of the class extended from the Applet. Now How do I
call the functions of the class extended from Frame class - MenuBarFrame
class. the outline code is
public class menu_show extends Applet
{
------init , paint action function---------
}
public class MenuBarFrame extends Frame
{
paint,action function for Menu
}
public static void main(String args[])
{
applet class instance is created
instance of frame is created
Menu , MenuBar, MenuItem instance is created
and all these objects added
I have Created MenuBarFrame class instance as
Object x= new menu_show().new MenuBarFrame
????? How to call the functions -- action of MenuBarFrame class - what
should be its parameters??????
}
> Hi,
>
[quoted text clipped - 3 lines]
> Regards,
> Lars-Inge Tønnessen
Lars-Inge Tønnessen [VJ# MVP] - 22 Jul 2005 21:39 GMT
If out want ot call methods in an Object, you can do like this:
Lets say we have this class (this is you inner class you want to call), and
want to call "Action" with an int and a string as arguments.
public class test3
{
public test3()
{
}
public void Action( int number, String name )
{
System.out.println("Inner Action :" + number + " " + name);
}
}
From this code:
// Lets say "t" is you object x -> Object x= new menu_show().new
MenuBarFrame
Object t = new test3();
Class c = t.getClass();
try
{
// the method name and its parameters declarations.
java.lang.reflect.Method method = c.getMethod("Action", new
Class[]{int.class, String.class});
// Call the method " t.Action( 3, "This is me"); "
method.invoke( t, new Object[]{new Integer(3), new String("This is
me")} );
}
catch ( java.lang.NoSuchMethodException Nomethod )
{
Nomethod.printStackTrace();
}
catch ( java.lang.IllegalAccessException exexe )
{
exexe.printStackTrace();
}
catch ( java.lang.reflect.InvocationTargetException er )
{
er.printStackTrace();
}
Did this answer you question?
Regards,
Lars-Inge Tønnessen
Lars-Inge Tønnessen [VJ# MVP] - 22 Jul 2005 21:41 GMT
> I have created the two classes one extends from Applet, and the other
> extends from Frame.
If you are converting an applet into a stand alone application, this is a
good article:
http://java.sun.com/developer/technicalArticles/Programming/TurningAnApplet/
Regards,
Lars-Inge Tønnessen