Hello, all. This is my first Java question (am transitioning from VB to Java).
Simply put, if class A has method howdy, can I have A running, implement class B, and from B return a value to A's howdy method other than with "A.howdy(returnValueGoesHere)"--by using a string "A" that I know represents the A class? Below is a more complete description of my problem:
I have a "BlackBerry" Class, which requires users to enter various data. It has a "Select Date" JButton that invokes another class named "MyCalendar". I've set up the calendar so that when a user clicks a date, the string value (dateChosen) is sent to the (still running) BlackBerry instance via BlackBerry's "displayMessage" method, and is populated in the "Date" JTextField. The code that does this is:
I have about 20 different classes that all open the same MyCalendar application (e.g. BlackBerry, Treo, etc.). I know using a selection structure to grab the class name that instantiated MyCalendar is wasteful, so I'm trying to grab the name of the class that called MyCalendar (this is a string, I think) and use it to run the displayMessage method (which all 20 classes contain).
With this I can grab the name of the instantiating class:
variable = callingClass.getClass().getName()
Is there any way to use the variable to actually run the displayMessage method?
These don't work:
I read several threads here at EE with suggestions regarding using forName, as below, but they create new instances of the class I want to return a value to, and fail to return the dateChosen value to the class (BlackBerry, Treo, etc.) that originally called MyCalendar(and is still running while waiting for the user to select a date):
Class findClass = Class.forName("BlackBerry");
BlackBerry findIt = (BlackBerry)findClass.newInstance();