How to call a method of a class from another class
Hi,
Can some one explain me this? I want the label from the Label class to be displayed in the JFrame. I understand to do this, I have to call "label" to the ABC() and createAndShowGUI().
I am novice. It will be really helpful if you could explain me what you did.
class Label {
public Label() {
public JTextField label;
label = new JTextField("Hi");
public ABC() { //Constructor
Container c = getContentPane();
c.setLayout(new FlowLayout());
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(600, 400));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Will it be some thing like this?
public ABC() { //Constructor
Container c = getContentPane();
c.setLayout(new FlowLayout());
Label label = new Label();
label.add
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(600, 400));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.add(new Label());
//Display the window.
frame.pack();
frame.setVisible(true);
}
merit wrote:
Hi,
Can some one explain me this? I want the label from the Label class to be displayed in the JFrame. I understand to do this, I have to call "label" to the ABC() and createAndShowGUI().
I am novice. It will be really helpful if you could explain me what you did.
class Label {
public Label() {
public JTextField label;
label = new JTextField("Hi");
public ABC() { //Constructor
Container c = getContentPane();
c.setLayout(new FlowLayout());
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(600, 400));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Will it be some thing like this?
public ABC() { //Constructor
Container c = getContentPane();
c.setLayout(new FlowLayout());
Label label = new Label();
label.add
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(600, 400));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.add(new Label());
//Display the window.
frame.pack();
frame.setVisible(true);
You know it maybe that it's just too late at night for me, but I see you complete Label class, but I don't see a class definition for ABC; you have a constructor for it, but not a class definition for it.
In any case, when you define a class, you use it in the same way any other class is used...
MyClass myObjectRef = new MyClass();
Similar Messages
-
How to call a method in one JSP from another JSP?
say that I have 2 JSPs.
JSP one has a button.
JSP two has some method that, say, find the square root of the number passed from JPS one.
How to - when click - the button on page one call the method on page two?
Please note that I can not use object binding, but I want passing the actual parameter and call the method on page two.
Please note that this is an update of a previous post on the same topic called "Object scope".
Thank you all very much.No, i dont know how to call other than main methods from other classes
And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch)......... -
How to call main method in one class from another class
Suppose i have a code like this
class Demo
public static void main(String args[])
System.out.println("We are in First class");
class Demo1
public static void main(String args[])
System.out.println("We are in second class");
In the above program how to call main method in demo calss from Demo1 class......???????No, i dont know how to call other than main methods from other classes
And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch)......... -
How to call a method in the servlet from an applet
I want to get the data for the applet from the servlet.
How to call a method that exits in the servlet from the applet? I want to use http protocol to do this.
Any suggestions? Please help.
thanksNow that Web Services is around, I'd look at possibly implement a Web Service call in your applet, which can then be given back any object(s) on return. Set up your server side to handle Web Service calls. In this way, you can break the applet out into an application should you want to (with very little work) and it will still function the same
-
Need call a method of one iview from another iview
Hi,
There are 2 iviews in a component.
1) FirstView - contains abc() method & xyz() methods
2) SecondView (a popup) - asdf() method
i want to call abc() method from asdf() method. i.e. i want to call a method of the firstview from the secondview.
Note:
1) i couldn't able to copy the code of abc() method to component controller, as it has the code which uses (iview) local attributes (this can be done by context mapping) & main reason is from the method it calls the xyz() method of the same view (again i couldn't call a method of iview from component controller).
2) firstView contain 5 tabs, i want to be in the same tab from which secondview (popup) was called, if i use fire plugs between both view, the current tab will be chnaged (i suppose, not sure).
3) can we use event handlers, if yes how can we do that.
Please provide a better solution for calling a method of view from another view.
Thanks
Maha
Edited by: Maha Hussain on Jan 13, 2009 12:40 PMHi Maha,
It is better to have such methods in the component controller to make it reusable and avoid writing same code again and again.
You can have that method in component controller and call that method on click on a button from Iview1 and can pass the parameters in the mthgod only.
for example.
Say Method abc() which is currently in Iview1 and you are passing values from context say aa bb cc to the method now what i am suggesting is
have that method abc(String aa, String bb, String cc) ;
and call it on click on button in Iview1 and pass the required parameters.
Hope this will help
Regards
Narendra -
How to call particular method in action class from Portlets StrutsContent
I am developing a web application which uses weblogic portlets and struts. This is what I have for now in the .portlet file.
+<netuix:strutsContent action="getStudentList" module = "people/students"+
refreshAction = "getStudentList" reqestAttrpersistence="none"/>
I want it to change something like this:
+<netuix:strutsContent action="getStudentList.do?method=allGrads" module = "people/students"+
refreshAction = "getStudentLis.do?method=allGrads" reqestAttrpersistence="none"/>
But this is not working. So how can I achieve something like that?
Thanks
Edited by: user13634949 on Jun 23, 2011 1:22 PM
Edited by: user13634949 on Jun 23, 2011 1:22 PMNo, i dont know how to call other than main methods from other classes
And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch)......... -
How to call a method of a class where the name of method is string
i have a method of a class in the form of a string and i have the object of the class to which it belongs .what i want to do is call this method.
for ex:
S1 s=new S1();
// this is the object of my class. this class has one method called executeMe()
String methodname="executeMe";
//i have the name of the method with me in the form of string.
so how can i call the class's method in this scenario from the string like what should i write in sucha way that i get s.executeMe(); it is not presumed that this will only be the method that will be called. there maybe some other method too and it has also to be called this way. so please guide.S1 s = new S1();
String name = "executeMe";
Method m = s.getClass().getDeclaredMethod(name,null); // no parameters
m.invoke(s,null);Built from memory, maycontain flaws. -
How to call a method in IMPL class from one context node
Hi, I´ve been only study the posibility to access a method in the IMPL class from one context node class...CN## without using events, is there a way to call it ??? I don´t have it as requierement just learning thanks !.
Hi,
Try this by following this you can get the custom controller instacne in the view context nodes, for your requirement you can keep the view implementation class instance instead of cuco..
To get the custom controller instance in Context node getter/setter method:
1. Declare Cuco instance reference variable in ctxt class..
2. Set this cuco ref. in the Create context node method of ctxt class:
try.
gr_cucoadminh ?= owner->get_custom_controller( 'ICCMP_BTSHEAD/cucoadminh' ). "#EC NOTEXT
catch cx_root.
endtry.
you can avoid this step as this is not needed in case of view isntance
3. Assign this instance to the respective context node Create method using:
BTStatusH->gr_cuco ?= gr_cucoadminh. " here assign the view implementation ref. " me" instead of gr_cucoadminh
Here gr_cuco is the ref. variable of custom controller in the respective context node for eg. BtstatusH
Sample implementation of this can be found in
ICCMP_BTSHEAD/BTSHeader ->context node BTACTIVITYH-> attr ->GR_CUCO(instance of cuco)
Cheers,
Sumit Mittal -
How to call a method of one dc in another dc
Hi,
i have two dcs dc1 and dc2
i want to call the method of dc1 interface controller in component controller of dc2
plz help me, how to acheive it
Thanks & regards,
v santhoshHi Vanama,
Hope you have defined a method say method1() in interface controller of DC1
Add this to public part.
In DC2 , set DC1 as used DC.
give <DCUsageName>
now you can access the method in DC1 like this.
wdThis.wdGet<DCUsageName>().getmethod1();
Regards,
Murtuza -
How to call a sp that returns multi_columns from another sp
Hi,
Can anybody help me to solve this problem? I called a sp which
returns ename, sal using a weak ref cursor from another sp. Is
it possible to do this? or I did something wrong? The error
messages are:
ERROR at line 1:
ORA-00904: invalid column name
ORA-06512: at "SCOTT.TESTPKG", line 14
ORA-06512: at line 1
below is my code:
create or replace package testpkg AS //12/19/01
TYPE sumCur IS REF CURSOR;
TYPE estType IS REF CURSOR;
function totalNo (
dno IN NUMBER)
RETURN estType;
procedure test(
sum_cv IN OUT NOCOPY sumCur);
END;
CREATE OR REPLACE PACKAGE BODY testpkg AS
function totalNo (
dno IN NUMBER)
RETURN estType IS est_cv estType;
BEGIN
OPEN est_cv FOR SELECT ename, sal FROM emp
where deptno = dno and job = 'MANAGER';
RETURN est_cv;
END totalno;
procedure test(
sum_cv IN OUT NOCOPY sumCur) AS
sql_statement VARCHAR2(100);
BEGIN
sql_statement :='SELECT dname, totalNo(deptno)
from dept ';
OPEN sum_cv FOR sql_statement ;
END test;
END;
ThanksThe error that you are getting is because totalNo(deptno) needs
to be testpkg.totalNo(deptno), but that is not the only error.
Maybe you can use something like this:
SQL> CREATE OR REPLACE PACKAGE testpkg
2 AS
3 TYPE sumcur IS REF CURSOR;
4 FUNCTION totalno
5 (dno IN NUMBER)
6 RETURN VARCHAR2;
7 PROCEDURE test
8 (sum_cv IN OUT sumcur);
9 END testpkg;
10 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY testpkg
2 AS
3 FUNCTION totalno
4 (dno IN NUMBER)
5 RETURN VARCHAR2
6 IS
7 est_cv VARCHAR2 (30);
8 BEGIN
9 SELECT ename || ' ' || TO_CHAR (sal)
10 INTO est_cv
11 FROM emp
12 WHERE deptno = dno
13 AND job = 'MANAGER';
14 RETURN est_cv;
15 END totalno;
16 PROCEDURE test
17 (sum_cv IN OUT sumcur)
18 AS
19 sql_statement VARCHAR2 (100);
20 BEGIN
21 sql_statement :=
22 ' SELECT dname, testpkg.totalno (deptno)'
23 || ' FROM dept';
24 OPEN sum_cv FOR sql_statement;
25 END test;
26 END testpkg;
27 /
Package body created.
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC testpkg.test (:g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
DNAME
TESTPKG.TOTALNO(DEPTNO)
ACCOUNTING
CLARK 2450
RESEARCH
JONES 2975
SALES
BLAKE 2850
DNAME
TESTPKG.TOTALNO(DEPTNO)
OPERATIONS -
How to call setter Method of ActionScript class with in a Flex Application
Hi
I have Action class as shown :
public class MyClass
private var name:String
public function get name():String {
return _initialCount;
public function set name(name:String):void {
name = name;
Now please let me know how can i access this Action class under my Flex Application and call the setter Method of it to set the value for the name .
For example on entering some data in a TextInput and click of a submit Button , on to the Event Listener , i want to call the set name method of my ActionScript class .
Please share your ideas on this .Thanks Gordon for your resonse .
Say for example my Action class is like this :
public class MyClass
private var name:String
public function get name():String {
return name;
public function set name(name:String):void {
name = name;
This is inside the MXML
I know this way we can do it
public var myclass:MyClass = new MyClass();
myclass.name="Kiran";
Now my query is can we do in this way also ??
myclass.set name(SomeTextInput.text);
Please share your views on this , waiting for your replies .
Thanks in advance . -
How to call C function in .m file from another function in a .mm file
I am making an interface class between a C library and an objetive C application.
I have not problem calling function the C library from .mm funstions,
but I am having problems calling .m functions from the .mm class.
here is an example of what I mean.
here in my .m vector file
*struct dVector*
* float m_x;*
* float m_y;*
* float m_z;*
* float m_w;*
*struct dVector InitVector (float x, float y, float z, float w);*
*struct dVector AddVector (struct dVector* A, struct dVector* B);*
*struct dVector SubVector (struct dVector* A, struct dVector* B);*
here is my .mm class
*#import <Foundation/Foundation.h>*
*@interface iNewton : NSObject*
* void* m_world;*
*-(id) init;*
*-(void) dealloc;*
-(void) CreateBox: (Entity*) ent: (int) shapeId;*
@end
here is the implemrntation of function funtion CreateBox in a .mm file
[code]-(void*) CreateBox: (Entity*) ent: (int) shapeId
struct dVector minBox;
struct dVector maxBox;
// this is fine
[ent GetBBox: &minBox: &maxBox];
//calculate the box size and dimensions of the physics collision shape
// this report a link errors, and I do no knwo why
struct dVector size = SubVector(&maxBox, &minBox);
struct dVector origin = AddVector (&maxBox, &minBox);
// thsi work without problemen
return NewtonCreateBox ((NewtonWorld*) world, size.m_x, size.m_y, size.m_z, shapeId, &offset.mfront.mx);
I get these compiler errors
Building target “tutorial102AddingRigidBody” of project “newton_iPhone” with configuration “Debug_Emulation” — (3 errors)
cd /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone
setenv MACOSXDEPLOYMENTTARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr /bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2 .1.sdk -L/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newtoniPhone/build/DebugEmulation-iphonesimulator -L/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/../sdk -F/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newtoniPhone/build/DebugEmulation-iphonesimulator -filelist /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newtoniPhone/build/Debug_Emulation-iphonesimulator/tutorial_102_AddingRigidBody.build/ Objects-normal/i386/tutorial_102AddingRigidBodies.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework CoreGraphics -lnewton_iPhoneEmulation -o /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newtoniPhone/build/Debug_Emulation-iphonesimulator/tutorial_102_AddingRigidBodies.app/ tutorial_102AddingRigidBodies
Undefined symbols:
"AddVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"SubVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"Scale(dVector*, float)", referenced from:
-[iNewton CreateBox::] in iNewton.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
"AddVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"SubVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"Scale(dVector*, float)", referenced from:
-[iNewton CreateBox::] in iNewton.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build failed (3 errors)
Basically I can call objective C class methods from .mm files,
but I can not call functions who are not members of a class from .mm funtions.
Does any one knows how I can solve this?
I have two books on objective C and neither show how to do that.
Please I will apreciate if some one can help me with this.
Julio Jerezjulio jerez wrote:
// this is fine
[ent GetBBox: &minBox: &maxBox];
why will tha be wrong?
ent is a objective C class with a method GetBBox
wich I use in hundred of places with out problem.
Beside that is not the problem that.
Well, you've got me on this one. You are correct. Apparently you don't need to specify the parameter names. Still, I strongly encourage you to use parameter names. Even though they apparently aren't required, I've never seen them not used. I would have expected to see:
[ent GetBBoxMin: & minBox max: & maxBox]
The problem is calling C function that are declared in .m files.
if you read the errors, they are linking errors not compiler errors.
this is a C function that is declared in a .m file
struct dVector size = SubVector(&maxBox, &minBox);
beside I also use those functions in many other place as well in teh project and they work.
If it helps I can post a link to the a download place to the xcode project maybe it is eassy to see what I am trying to do.
That would probably be a good idea.
Normally, all you need is
extern "C"
but there is so much missing from what you've posted that I can't tell for sure what is going on. -
How to call the task flow one region from another region?
I have page with 3 regions (column wise) named as start, center, end.
currently I having task flow for middle(i.e, center) region which have panelCollection to perform view, create, & delete functions.
Task flow:-
From(action)To
View(create)Create
Create(Done)Execute (Execute is a method call)
Execute(*)View
View(self)Execute
By press create button on Center page, task flow takes to the Create page(in Centre region) but all other regions(start, end) remains same.
I have a usecase where we have a commandLink on Start region to show the View page on Center region. but it is not able to achieve when we move to Create/Edit page.
Plz help me out to built the same.
Thanq
KSB
Edited by: user641407 on Aug 28, 2008 2:22 PM
Edited by: user641407 on Aug 28, 2008 2:23 PMHi!
First, I'm not sure that your page layout is adequate. The regions are not intended to be navigated from outside. Yet, they can send navigation action to the container (page on which the region is placed) through Parent Action taskflow element. Also, you can investigate Contextual Events that can be raised by region, but I'm also not sure that this can be easily used for cross-region navigation.
I would suggest you to reconsider you page layout. You can use dynamic regions (which are populated by taskflow based on menu selection or click on actionLink or s button). This way, in the Start facet you place a navigation menu (links), which are connected with dynamic region in Center. If you want to reuse a navigation links (in Start), you can put all this in page template and reuse it over and over again.
Regards,
PaKo -
How to call a method in private section of a class in the public section
Hi Everybody,
i have written a method(meth1) in the private section of a class(C1).
it is as follows
class C1 definition.
private section.
methods: meth1 importing im_dt1 like tp1
im_dt2 like tp2
im_dt3 like tp3
im_dt4 like tp4
returning value(re_dt1) like tp5.
endclass.
i have the final data that has to be displayed in internal table re_dt1.
now my question is how to call this method present in private section into public section and display the data present in re_dt1.
Thanks,
learning.abap.Hi,
what you need is one public method being called at start-of-selection. Within this the private methods have to be called.
The question is, why has the method for reading the database tables to be private? If you have only one private method reading all database tables the public method being called at start-of-selection will only consist of a call-method statement.
This seems to be one call to much.
The logic for reading the different database tables is hidden inside the class anyway.
Is there any further logic reading the different database tables?
Have always all table to be read? If not another approach would be one private method for each database table being called by a public method deciding which table has to be read:
public section.
methods get_data returning value(re_Dt1).
private section.
methods:
get_table_a returning value(im_dt1),
get_table_b returning value(im_dt2),
get_table_c returning value(im_dt3),
get_table_d returning value(im_dt4),
combine_data importing im_dt1
im_dt2
im_dt3
im_dt4
returning value(re_dt1).
*- implementation of public method:
method get_data.
data: lt_dt1 ...
lt_dt2,
lt_dt3,
lt_dt4.
* here decide which tables have to be read:
lt_dt1 = get_table_a( ).
lt_dt2 = get_table_b( ).
lt_dt3 = get_table_c( ).
lt_dt4 = get_table_d( ).
re_dt1 = combine_data( i_dt1 = lt_dt1
i_dt2 = lt_dt2
i_dt3 = lt_dt3
i_dt4 = lt_dt4 ).
endmethod.
*- implementation of private methods
method get_table_a.
endmethod.
method get_table_b.
endmethod.
method get_table_c.
endmethod.
method get_table_d.
endmethod.
method combine_data.
endmethod.
Regards
Dirk -
How to call a method from a separate class using IBAction
I can't work out how to call a method form an external class with IBAction.
//This Works 1
-(void)addCard:(MyiCards *)card{
[card insertNewCardIntoDatabase];
//This works 2
-(IBAction) addNewCard:(id)sender{
//stuff -- I want to call [card insertNewCardIntoDatabase];
I have tried tons of stuff here, but nothing is working. When i build this I get no errors or warnings, but trying to call the method in anyway other that what is there, i get errors.Can you explain more about what you are trying to do? IBAction is just a 'hint' to Interface Builder. It's just a void method return. And it's unclear what method is where from your code snippet below. is addNewCard: in another class? And if so, does it have a reference to the 'card' object you are sending the 'insertNewCardIntoDatabase' message? Some more details would help.
Cheers,
George
Maybe you are looking for
-
SSO with ITS & Webenabling WEBGui
Hello, We have configured SSO with R/3 system. It works fine. The requirement is, we have to webenable R/3 system thru SAP GUI For Windows and SAP GUI For HTML. We are able to do both on developement environment where both R/3 and portal has got the
-
Hi, I'm executing my query in report desiner but as per the requirement i need to delete some of the columns in the report designer of the selected query. when i'm selecting the column and click on delete colum it is not deleting the column. Please a
-
Installation problem with January 2014 iTunes update
I have tried repeatedly to install the January 2014 update but have not been successful. All previous updates have gone smoothly, so don't know why this update is so troublesome. Right now, I cannot access iTunes due to these difficulties. I am ru
-
Odd number of non-english characters get broken in windows-chrome and ff
I developed jnlp applet which prints out the user input. When I put odd number of non-english characters(eg: chinese), chrome and firefox browser prints out the last character as question mark. input : 가 output : 가�� I checked on java console that th
-
Call of Duty problem!,HELP..??
Just got call of duty(normal version,not expansion) and can play the first 2 levels fine,when it comes for the next level to load about half way through loading i get a error message saying "max number of disconnected paths excedded",has anyone any i