The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

-- answer is wrong !

Posted by venkat on April 26, 2001 at 10:40 AM


In a java program, we can't hold two public classes. Craig Snowbarger wants to share between two public classes that variable.


> Here is what I understand from your posting:
> You have a textfield where user will enter some text. This text should be available inside another class. Let the another class name be C2. Create a static string field in class C2 and then set that field value reading text from textfiled.

> class C2 {
> private static String text ;
> public setText ( String text ) {
> this.text = text ;
> }
> }

> // This is the class where you read from textfield
> class C1 {
> // Read text from text field
> String text = ...;
> //Set this text in C2 class
> C2.setText ( text ) ;
> }

>
> This way your textfield text is stored in C2 and you can use it whenever you want.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us