Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Object saving problem

    Hey guys i am trying to make a project on ATM .I have very basic knowledge of JAVA . I made Jframe and added some JText to it .. but i want is this when i click button , all text in JTextField and JPasswordField should be saved in a file . I am trying to use Serializable method to save object . Heres my code ...can you tell me where i am going wrong ?

    import javax.swing.*;

    import java.awt.*;
    import java.awt.event.*;
    import java.util.Calendar;
    import java.io.*;
    public class Page3_NewUser implements Serializable{
    transient JFrame p3f3 = new JFrame("AKS Online ATM");
    transient JTextField p3t1,p3t2,p3t3;
    transient JPasswordField p3pp1,p3pp2;
    String Name,UserID;
    String Pass1 , Pass2 ;
    String Pin;


    public void StartF3(){
    JPanel p3p1 = new JPanel();
    JPanel p3p2 = new JPanel();
    JPanel p3p3 = new JPanel();
    JPanel p3p4 = new JPanel();

    JPanel p3p5 = new JPanel();
    JPanel p3p6 = new JPanel();
    JPanel p3p7 = new JPanel();
    JPanel p3p8 = new JPanel();
    JPanel p3p9 = new JPanel();

    JLabel p3l1 = new JLabel();// for 1st image
    JLabel p3l2 = new JLabel("Full Name:");
    JLabel p3l3 = new JLabel("User ID:");
    JLabel p3l4 = new JLabel("Password:");
    JLabel p3l5 = new JLabel("Retype Password:");
    JLabel p3l6 = new JLabel("Pin Code:");
    JLabel p3l7 = new JLabel();// for 2nd img
    //JLabel p3l9 = new JLabel("This is testing");



    p3t1 = new JTextField(15);
    p3t2 = new JTextField(15);
    p3t3 = new JTextField(15);

    p3pp1 = new JPasswordField(5);
    p3pp2 = new JPasswordField(5);

    JButton p3b1 = new JButton("Previous");
    JButton p3b2 = new JButton("Continue");
    JButton p3b3 = new JButton("Reset");
    JButton p3b4 = new JButton("Cancel");
    // Action listener

    P3_Previous a = new P3_Previous();
    p3_Continue b = new p3_Continue();
    p3b1.addActionListener(a);
    p3b2.addActionListener(b);
    //--------
    p3t1.setText("Enter your name");
    p3t2.setText("Choose unique User ID");
    p3t3.setText("Enter 4 digit Pin Code");
    p3pp1.setText("1234");
    p3pp2.setText("1234");
    p3t1.setRequestFocusEnabled(true);
    p3t1.selectAll();
    p3t2.selectAll();
    p3t3.selectAll();
    p3pp1.selectAll();
    p3pp2.selectAll();


    p3f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ImageIcon img1 = new ImageIcon("atm_banner.jpg");
    p3l1.setIcon(img1);
    p3p1.add(p3l1);
    p3p1.setBackground(Color.WHITE);

    p3p5.add(p3l2);
    p3p5.add(p3t1);

    p3p6.add(p3l3);
    p3p6.add(p3t2);

    p3p7.add(p3l4);
    p3p7.add(p3pp1);

    p3p8.add(p3l5);
    p3p8.add(p3pp2);

    p3p9.add(p3l6);
    p3p9.add(p3t3);

    p3p2.setLayout(new BoxLayout(p3p2,BoxLayout.Y_AXIS));
    p3p2.add(p3p5);
    p3p2.add(p3p6);
    p3p2.add(p3p7);
    p3p2.add(p3p8);
    p3p2.add(p3p9);

    //---- temp

    ImageIcon img2 = new ImageIcon("ID.jpg");
    p3l7.setIcon(img2);
    p3p3.add(p3l7);
    p3p3.setBackground(Color.WHITE);


    p3p4.setBackground(Color.GRAY);
    p3p4.add(new JLabel(Calendar.getInstance().getTime().toString()));
    p3p4.add(p3b1);
    p3p4.add(p3b2);
    p3p4.add(p3b3);
    p3p4.add(p3b4);

    p3f3.getContentPane().add(BorderLayout.NORTH , p3p1);
    p3f3.getContentPane().add(BorderLayout.CENTER , p3p2);
    p3f3.getContentPane().add(BorderLayout.EAST , p3p3);
    p3f3.getContentPane().add(BorderLayout.SOUTH , p3p4);



    p3f3.setSize(700,600);
    p3f3.setVisible(true);








    }// StartF3()
    //previous button handler
    class P3_Previous implements ActionListener{
    public void actionPerformed(ActionEvent e){
    p3f3.setVisible(false);
    Page1 p1 = new Page1();
    p1.StartF1();
    p1.p1f1.setVisible(true);

    }
    }


    // continue button handler
    class p3_Continue implements ActionListener{
    public void actionPerformed(ActionEvent e){
    /*
    Name = p3t1.getText();
    UserID = p3t2.getText();
    Pass1 = p3pp1.getText();
    Pass2 = p3pp2.getText();
    Pin = p3t3.getText();
    */
    Page3_NewUser nu = new Page3_NewUser();
    // setting





    Saving s = new Saving();
    s.Save(nu);
    p3f3.setVisible(false);
    Page1 p1 = new Page1();
    p1.StartF1();
    p1.p1f1.setVisible(true);
    }
    }



    }// close Page2_NewUser class

    and here is my Saving class

    import java.io.*;
    public class Saving {

    public void Save(Object obb){

    try{
    FileOutputStream f = new FileOutputStream("foo.ser");
    ObjectOutputStream ob = new ObjectOutputStream(f);
    ob.writeObject(obb);
    ob.close();
    }
    catch(Exception e){
    e.printStackTrace();
    }
    }//method

    }// class

    Even if serializable method does not suits here can anyone get me an idea how to write text file saving method for this .I know all the method like BufferedWriter and all but i want to make it work by getting text from JTextField . ---- plz help
    Last edited by aakansha; 02-22-2008 at 06:34 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •