School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,960 people online right now. Registration is fast and FREE... Join Now!



textField to textField

textField to textField Rate Topic: ****- 1 Votes

#1 dkheartsag  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 34
  • Joined: 18-February 09


Dream Kudos: 0

Posted 16 March 2009 - 09:53 PM

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..
Was This Post Helpful? 0
  • +
  • -


#2 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 16 March 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.

This post has been edited by Locke: 16 March 2009 - 09:58 PM

Was This Post Helpful? 0
  • +
  • -

#3 dkheartsag  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 34
  • Joined: 18-February 09


Dream Kudos: 0

Posted 16 March 2009 - 10:10 PM

View PostLocke, on 16 Mar, 2009 - 09:57 PM, said:

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 ???
Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 16 March 2009 - 10:18 PM

Well, you would have something relative to the following.

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.


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...

// 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! :)

This post has been edited by Locke: 16 March 2009 - 10:19 PM

Was This Post Helpful? 1
  • +
  • -

#5 dkheartsag  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 34
  • Joined: 18-February 09


Dream Kudos: 0

Posted 17 March 2009 - 10:16 AM

View PostLocke, on 16 Mar, 2009 - 10:18 PM, said:

Well, you would have something relative to the following.

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.


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...

// 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! :)

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 .
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month