/    Sign up×
Community /Pin to ProfileBookmark

saving in java

this is my following code:
class SaveButtonListener implements ActionListener {

public void actionPerformed (ActionEvent event) {

try {
FileWriter writer = new FileWriter (“Salary.txt”);
PrintWriter out = new PrintWriter (writer);

Object AddcurrentChoice = employeeChoice.getSelectedItem();
out.println (AddcurrentChoice);

String AddFName = FNametextfield.getText();
String AddSName = SNametextfield.getText();
String AddDOB = DOBtextfield.getText();
String AddSSN = SSNtextfield.getText();
out.println (AddFName);
out.println (AddSName);
out.println (AddDO?;
out.println (AddSSN);

String AddBasicSalary = BasicSalarytextfield.getText();
String AddLunchAllow = LunchAllowtextfield.getText();
String AddHousingAllow = HousingAllowtextfield.getText();
String AddTravelAllow = TravelAllowtextfield.getText();
String AddBonus = Bonustextfield.getText();
String AddOvertime = Overtimetextfield.getText();
String AddGrossSalary = GrossSalarytextfield.getText();
out.println (AddBasicSalary);
out.println (AddLunchAllow);
out.println (AddHousingAllow);
out.println (AddTravelAllow);
out.println (AddBonus);
out.println (AddOvertime);
out.println (AddGrossSalary);

String AddAdvance = Advancetextfield.getText();
String AddLoan = Loantextfield.getText();
String AddPAYE = PAYEtextfield.getText();
String AddNAPSA = NAPSAtextfield.getText();
String AddMed = Medtextfield.getText();
String AddTDeductions = TDeductionstextfield.getText();
out.println (AddAdvance);
out.println (AddLoan);
out.println (AddPAYE);
out.println (AddNAPSA);
out.println (AddMed);
out.println (AddTDeductions);

String AddNetSalary = NetSalarytextfield.getText();
out.println (AddNetSalary);

String AddAmount = Amounttextfield.getText();
out.println (AddAmount);

out.close();

}
catch (IOException exception) {

System.out.println (“can’t write to file”);
}
}
};
ActionListener listener = new SaveButtonListener ();
Savebutton.addActionListener (listener);

The problem is whenever i wanna add new data and save it it all saves in the same place (Salary.txt). How do i do it so that when i press save a window opens asking you where to save what iv just done and what name to give it??
Does anyone have sample code or can tell me how to do it???

to post a comment
Java

4 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliFeb 25.2006 — I gave a you a working example of filechooser code...?????
Copy linkTweet thisAlerts:
@The_OneauthorFeb 25.2006 — ya but i dont know how to put it in so whatever iv got is saved? can u show me?
Copy linkTweet thisAlerts:
@The_OneauthorFeb 25.2006 — example pls
Copy linkTweet thisAlerts:
@The_OneauthorFeb 26.2006 — how do i put it on the code above
×

Success!

Help @The_One spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...