• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Passing values between two JPanels

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 jPanels: Data1 and Data2. These jPanels contains jTextFields and jComboBoxes. The purpose of program to input data to jTextFields and save it in text file.
Every jPanel have a saveButton. When the saveButton1 of Data1 jPanel is hit it will save in Data1.txt file.
When saveButton2 of Data2 is pressed it will save to Data2.txt file.
Fot this moment, I can get data from jTextFields and save them to Data1.txt and Data2.txt files.
The contents of Data1.txt file is: Name, Affiliation, Phone;
Data2.txt file is: Birth, Address, Title.

The question is: how can I get inputted value of Data2 jPanel and save it to Data1.txt file?
For example, when the saveButton2 of Data2 is pressed, then the value of "Address" must appear in Data1.txt file after "Affiliation", i.e. Data1.txt->Name, Affiliation, Address, Phone.

Thank you for help.
 
Marshal
Posts: 73962
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can your app save information passed via the command line? You ought to design the app like that, rather than having logic in the display classes. You might have getText methods for each of the text fields which can be used to provide the data to the actual app.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In pseudo code
1) Create 2 panels with required controls
2) Add the panels to the JFrame
3) Add the Save button to the JFRAME
4) When the save button is clicked, it can access the data from inside the JPanels
5) Save data as required.

This way, the panels can exist without being aware of the data saving or the parent JFrame. They just display given data or accept user input.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic