Results 1 to 6 of 6
  1. #1
    Mitho is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Need Help with storing and displaying data

    Please help me ...

    I had attached three java file passenger, construct passenger and viewer.
    In viewer class there is textfield where i can write the passenger name.
    My problem and question is that
    when i write the passenger name and click on Add Passenger button it should add passenger to certain data file. and it should add some passengers. Finally when i click on Display passenger it should display all passengers name. when i close the program it should save the passenger list.
    I had tried to some extend but am unable

    Please Help


    The viewer classs is
    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.BorderLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    
    public class Viewer
    {
    
       public static void main(String[] args)
       {
       
          final JFrame frame = new JFrame();
          final int FRAME_WIDTH  = 500;
          final int FRAME_HEIGHT =100;
          frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
          frame.setTitle("SuperEllipse Viewer");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setLayout(new BorderLayout());
          final ConsPass pass = new ConsPass();
    
          final JTextField passenger = new JTextField(15);
          JPanel panel = new JPanel();
          frame.add(panel,BorderLayout.NORTH);
          panel.add(passenger);
    
          JButton addP = new JButton("Add Passenger");
          JButton printP = new JButton("Display Passenger");
         
          class SuperEllipseListener implements ActionListener
          {
             public void actionPerformed(ActionEvent event)
             {
           
            String p = passenger.getText();
            pass.addPassenger(p);
            passenger.setText(null);
             }            
          }
          ActionListener listener = new SuperEllipseListener();
          addP.addActionListener(listener);
          panel.add(addP);
    
          class PrintB implements ActionListener
          {
             public void actionPerformed(ActionEvent event)
             {
    
            	 pass.printP();
             }            
          }
          ActionListener listeners = new PrintB();
          printP.addActionListener(listeners);
          panel.add(printP);
          frame.setVisible(true);
       }
    }


    The passenger class is
    Java Code:
    public class Passenger 
    {
    private String name;
    
    
    	public Passenger(String sname)
    	{
    		name=sname;
    	}
    
    	public String getName()
    	{
    		return name;
    	}
        
    
    		
    }

    The constructor class is
    Java Code:
    import java.util.ArrayList;
    
    
    public class ConsPass {
    	ArrayList<Passenger> passList = new ArrayList<Passenger>();
    	Passenger passenger;
    	Passenger displaying;
    	public ConsPass(){
    		
    	}
    	public void addPassenger(String name)
    	{
    		for(int i =1; i< passList.size(); i++)
    		{
    		passenger = new Passenger(name);
    		passList.add(passenger);
    		}
    	}
    	public Passenger getPassenger(){
    	
    		for(int i =1; i< passList.size(); i++)
    		{
    	       displaying = passList.get(i);
    		}
    		return displaying;
    }
    	
    	
    	public void printP()
    	{
    		System.out.println(displaying);
    	}
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,590
    Rep Power
    23

    Default Re: Need Help with storing and displaying data

    Can you describe what the program does do?

    Where is it not doing what "it should"? Are you missing the code or is the code not doing what you want it to do?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Mitho is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need Help with storing and displaying data

    Program displays textfield and buttons in a JFrame but when i click on add passenger it should stores the information of JTextfield in certain file and should restored when needed....So please help...

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,590
    Rep Power
    23

    Default Re: Need Help with storing and displaying data

    it should stores the information of JTextfield in certain file and should restored when needed
    Are you asking how to write a String to a disk file and how to read a String from a file?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Mitho is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need Help with storing and displaying data

    HOw to store data and restore it in program

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,590
    Rep Power
    23

    Default Re: Need Help with storing and displaying data

    One way to store data and restore it would be to write the data to a disk file where you can later read it.

    See the FileWriter class and BufferedReader classes. Do a Search here for those class names for some code samples.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Storing previous errors and displaying
    By shivam0101 in forum Advanced Java
    Replies: 21
    Last Post: 03-13-2012, 04:58 PM
  2. Storing local data?
    By DennisMadsen in forum Advanced Java
    Replies: 1
    Last Post: 11-01-2010, 08:27 PM
  3. Storing data?
    By Syntax in forum New To Java
    Replies: 4
    Last Post: 01-23-2010, 01:17 AM
  4. Replies: 3
    Last Post: 10-28-2009, 01:45 AM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 05:48 AM

Posting Permissions

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