Solved

Saving in Objects

Posted on 2002-04-02
2
156 Views
Last Modified: 2011-09-20
I have a AWT Frame which consists 3 text fields
namely for ex:  emp Name,dept and salary . in addition the frame consists 2 buttons, save and exit.

When i enter the data in the Text Fields and click save
the data should be saved into an object and not inside a database table nor inside a .dat file.

Again I shud retrive back the data from the object and display the contents onto another Screen.

0
Comment
Question by:yrrm
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
msterjev earned 70 total points
Comment Utility
You can create this object.

public class Credentals implements Serializable
{
     String name;
     String dept;
     String salary;
}

You store variables from text fields as data members of this class.

For example:

credentals.name=nameField.getText();
credentals.dept=deptField.getText();
credentals.salary=salaryField.getText();

The persistance is achieved using ObjectInputStream and ObjectOutputStream.

ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("credentals"));
out.writeObject(credentals);

At the start of the program you can retrieve the credentals with:

ObjectInputStream in=new ObjectInputStream(new FileInputStream("credentals"));
Credentals credentals=(Credentals) in.readObject();
0
 
LVL 3

Expert Comment

by:msterjev
Comment Utility
The points....
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now