VOTG
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

A newbie got stuck !

Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44


I am trying to write a small java applications. I created my 1st JPanel, and added a JTextBox and a button to it, in a 2nd JPanel I added a JTextBox only, now I added this 2 JPanel to a JFrame, I want to want to put up the text in JtextBox of Panel1 to JtextBox of Panel2 on hitting the button of JPanel1. I am adding an image for clarification , this small piece of code is done except the event-handling (the most important part).



If someone clears my doubts, and provides some code/link how to write codes for this kind of event handling, then it would be very helpful.
Please help, thanks in Advance.
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Messages: 13666



Panel 1 needs a reference to panel 2 and panel 2 needs a getter for your text area for this to work.

"Fookin Prawns"
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44

Thank you ... it really helped me ...
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44

ok , I did exactly the same, it works but there is a problem. When I try to get my Text (with SOP statements), of JtextArea2, I get what is expected, but in the UI it remains the same doesnot update.
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8776

Can you show us the exact code you are using to update it?

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44



Panel2 is an instance variable, instantiated at the Constructor of Panel1



this is in my pannel2

Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8776

And Panel2 is the exact same instance you added to your GUI? You haven't created another, invisible panel?

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44

MynewPannel.java






I know the full code with "system genereted one" .. its pretty bad ... even I dislike it ... but please help
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44



This is my NetBeans Project file

My NetBeans Project
Michael Dunn
Rancher

Joined: Jun 09, 2003
Messages: 3090

creating a new MyNewPanel() is not passing a reference of the one on the screen.

some changes



and


Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8776

Just what I though. Your MyPanel instance has its own copy of MyNewPanel that is not added to the GUI.

You should give it a reference to the actual panel:




Heh, Michael beat me to it

This message was edited 1 time. Last update was at by Rob Prime


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Tirthankar Mukherjee
Ranch Hand

Joined: Apr 08, 2006
Messages: 44

Oh my GOD !!! Swing is swing pretty fast but I will hang on ... JavaRanch rocks !!

Most importantly many many thanks Rob and all of the above contributors.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic

.