by adding a setter, I assume
public String getFieldValue(){
return field.getText();
}
stultuske
Industrious Poster
4,379 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
well, duh .. I don't know what your variables are called, so I can't use the correct name, now can I? neither do I know how your classes are related. I just assume your main class instantiates a JFrame of which you want to get the value of the field. but then, how do you think of triggering that? well, sure, tons of way to do that, anyway..
String theValue = instantiatedJFrame.getFieldValue();
and just like that, I've given you the code for both classes. how to implement it correctly, and how to use it correctly, that's up to you to decide/find out
stultuske
Industrious Poster
4,379 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
it didn't work...
Post the full text of the error message and the code that is causing the error.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Why did the code you tried not work? Please explain.
The methods in one class can call the methods in another class if they have a reference to the other class object. For example:
AClass aClassRef =new AClass(); // one way to get a reference to an AClass object
aClassRef.someMethod(); // call someMethod in the AClass
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Please post code for a small simple program that shows what you are trying to do.
What is a "d clear" class? d is a poor name for a class. Try to find a name that has some meaning when you see it used. Class names should start with an uppercase letter.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Sorry I don't care to visit other sites.
Please post code here for a small simple program that shows what you are trying to do.
Not the full project, just a small program for the specific problem.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
delete d numbers from the JTextField with variable name ans in the calculator class
To do something like deleteing d numbers from a textfield, you should have a method in the Calculator class that you pass d and have it do the deletion.
Define the methodToRemoveNbrs() in the Calculator class.
aRefToCalcatorCls.methodToRemoveNbrs(d);
The Clear class needs to get the reference (aRefToCalcatorCls) to the Calculator class. Many ways to do this. A common one is to pass a reference to the Calculator class to the Clear class's construtor.
access ans variable
Define a method: getAns() in the Calculator class that returns the value of ans when called.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16