Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / November 2005

Tip: Looking for answers? Try searching our database.

calling action function of the inner class in main function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
anoop - 20 Jul 2005 17:39 GMT
Hello,
       How can I call the action function of the inner class in main
function of the .java code file applet Application.
                                                     Thank you.
Lars-Inge Tønnessen [VJ# MVP] - 21 Jul 2005 19:12 GMT
Hi,

Could you please give us more information what you want to do.
A few lines of code that is not working is very welcome.

Regards,
Lars-Inge Tønnessen
anoop - 22 Jul 2005 07:20 GMT
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
Tia - 20 Nov 2005 15:38 GMT
START YOUR OWN E-MAIL BUSINESS TODAY and TAKE ADVANTAGE OF THE FOLLOWING:

1.ALL CUSTOMERS PAY YOU IN CASH!!!
2. TOP PART-TIME OWNERS HAVE EARNED $5,000+ IN ONE MONTH!
3. TOP FULL-TIME OWNERS HAVE EARNED $10,000+ IN ONE MONTH!
4. YOU WILL SELL A PRODUCT WHICH COSTS NOTHING TO PRODUCE!
5. YOUR MAIN OVERHEAD IS YOUR TIME!
6. YOUR START UP COSTS ARE LESS THAN $25
7. YOU HAVE MORE THAN 40 MILLION POTENTIAL CUSTOMERS

For additional information please E-mail me at  saita@dodo.com.au
=====================================================

New Software that finds leads for YOU for F.R.E.E.!!!!!
http://www.contactthem.com/cgi-bin/at.cgi?a=316161

---
MAF Anti-Spam ID: 20051113184547I1n0UmZ7

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.