Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java swing jtextfield jbutton using serialization and deserialization

 
sanjeet kunal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone help me to complete this program. I want to store data in this form using serialization and deserialization.


public class College_Form extends JFrame implements ActionListener {
JTextField tf1, tf2, tf3, tf4;
JButton b1, b2, b3;
JLabel l1, l2, l3, l4, l5;

College_Form() {

l5 = new JLabel("NETAJI SUBHAS INSTITUTE OF TECHNOLOGY");
l5.setForeground(Color.red);
l5.setFont(new Font("Arial", Font.BOLD, 25));
l5.setAlignmentX(TOP_ALIGNMENT);

l1 = new JLabel("Name:");
l2 = new JLabel("Department:");
l3 = new JLabel("Dues:");
l4 = new JLabel("Roll:");

tf1 = new JTextField(20);
tf2 = new JTextField(20);
tf3 = new JTextField(10);
tf4 = new JTextField(10);

b1 = new JButton("Save");
b2 = new JButton("Clear");
b3 = new JButton("Cancel");



add(l5);
add(l1);
add(tf1);
add(l2);
add(tf2);
add(l3);
add(tf3);
add(l4);
add(tf4);
add(b1);
add(b2);
add(b3);

setLayout(null);
l5.setBounds(100, 10, 700, 100);
l1.setBounds(250,140,100,50);
l2.setBounds(250,190,100,50);
l3.setBounds(250,250,100,50);
l4.setBounds(250,300,100,50);
tf1.setBounds(350, 150, 300, 20);
tf2.setBounds(350, 200, 200, 20);
tf3.setBounds(350, 260, 100, 20);
tf4.setBounds(350, 310, 100, 20);
b1.setBounds(200, 400, 100, 30);
b2.setBounds(350, 400, 100, 30);
b3.setBounds(500, 400, 100, 30);

setVisible(true);
setSize(800, 600);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the code you posted, there could be (at a minimum) 3 problem areas
1) Listening to button click
2) Obtaining all data and wrapping it up in an object
3) Actually storing the data

Which area are you facing problems? What have you tried so far? Please TellTheDetails
 
sanjeet kunal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't no how to fetch data in file by clicking on save button using serialization.So, can you write code for this.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sanjeet kunal wrote:I don't no how to fetch data in file by clicking on save button using serialization.So, can you write code for this.

Can I? Sure. Will I. Nope.
Thats not how things work here at the Ranch.
Show us what you have tried, tell us where you are stuck and we will help point you in the right direction.

Lets break down your problem into smaller problems and tackle them one at a time
You say your data is in a file. Do you know how to write code to read a file?
If not, recommended reading: https://docs.oracle.com/javase/tutorial/essential/io/

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!