Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,331 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,806 people online right now. Registration is fast and FREE... Join Now!




textField to textField

 

textField to textField

Rating  4
dkheartsag

16 Mar, 2009 - 09:53 PM
Post #1

New D.I.C Head
*

Joined: 18 Feb, 2009
Posts: 30

Hii all,

In my application i have two frame in which one frame work as chat box and other frame work playing board. i want to cut -past the score from playing board to chat box. The class of both frame are in same package.
Can u tell me how i can cut,past, any printed data from one jtextfield of one frame to another jtextfield on other frame........plz suggest me or give me sample code..

User is offlineProfile CardPM
+Quote Post


Locke

RE: TextField To TextField

16 Mar, 2009 - 09:57 PM
Post #2

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
You can make the text an instance variable of the object that you want to take the text from, and then access it later in the program by accessing that variable.

This post has been edited by Locke: 16 Mar, 2009 - 09:58 PM
User is online!Profile CardPM
+Quote Post

dkheartsag

RE: TextField To TextField

16 Mar, 2009 - 10:10 PM
Post #3

New D.I.C Head
*

Joined: 18 Feb, 2009
Posts: 30

QUOTE(Locke @ 16 Mar, 2009 - 09:57 PM) *

You can make the text an instance variable of the object that you want to take the text from, and then access it later in the program by accessing that variable.

Thx buddy,
can i have sample code i am confused how i implement the code ???

User is offlineProfile CardPM
+Quote Post

Locke

RE: TextField To TextField

16 Mar, 2009 - 10:18 PM
Post #4

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
Well, you would have something relative to the following.

Java
FirstFrame first = new FirstFrame();
SecondFrame second = new SecondFrame();

// The FirstFrame class is your chat window, which
// will receive the text that you copied.

// The SecondFrame class has a textfield that you want to
// copy from eventually, correct? Look at the next codebox
// to see a very basic sample of a SecondFrame class.


Java
class SecondFrame extends JFrame
{
String textToCopy;
JTextField text;

//...constructors, other methods, etc.

public void setText()
{
textToCopy = text.getText(); //get the TextField text
}

public String getCopiedText()
{
return textToCopy;
}
}


Then, later in the program, when you want to copy the text over...

Java
// recall back to the first codebox

// TEXTFIELD is the place you want to set your text in.

first.TEXTFIELD.setText( second.getCopiedText() );


Hope this helps! smile.gif

This post has been edited by Locke: 16 Mar, 2009 - 10:19 PM
User is online!Profile CardPM
+Quote Post

dkheartsag

RE: TextField To TextField

17 Mar, 2009 - 10:16 AM
Post #5

New D.I.C Head
*

Joined: 18 Feb, 2009
Posts: 30

QUOTE(Locke @ 16 Mar, 2009 - 10:18 PM) *

Well, you would have something relative to the following.

Java
FirstFrame first = new FirstFrame();
SecondFrame second = new SecondFrame();

// The FirstFrame class is your chat window, which
// will receive the text that you copied.

// The SecondFrame class has a textfield that you want to
// copy from eventually, correct? Look at the next codebox
// to see a very basic sample of a SecondFrame class.


Java
class SecondFrame extends JFrame
{
String textToCopy;
JTextField text;

//...constructors, other methods, etc.

public void setText()
{
textToCopy = text.getText(); //get the TextField text
}

public String getCopiedText()
{
return textToCopy;
}
}


Then, later in the program, when you want to copy the text over...

Java
// recall back to the first codebox

// TEXTFIELD is the place you want to set your text in.

first.TEXTFIELD.setText( second.getCopiedText() );


Hope this helps! smile.gif

I also used serverFile in b/t these to frame so ..i thing the code should be modified .. can u tell me sample code for that so i can access the server and the data is jtextfile can print into server .
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 04:21PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month