Results 1 to 6 of 6
- 04-10-2012, 05:43 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
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); } }
- 04-10-2012, 01:37 PM #2
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.
- 04-10-2012, 06:20 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
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...
- 04-10-2012, 06:40 PM #4
Re: Need Help with storing and displaying data
Are you asking how to write a String to a disk file and how to read a String from a file?it should stores the information of JTextfield in certain file and should restored when neededIf you don't understand my response, don't ignore it, ask a question.
- 04-10-2012, 11:15 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Re: Need Help with storing and displaying data
HOw to store data and restore it in program
- 04-10-2012, 11:20 PM #6
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
-
Storing previous errors and displaying
By shivam0101 in forum Advanced JavaReplies: 21Last Post: 03-13-2012, 04:58 PM -
Storing local data?
By DennisMadsen in forum Advanced JavaReplies: 1Last Post: 11-01-2010, 08:27 PM -
Storing data?
By Syntax in forum New To JavaReplies: 4Last Post: 01-23-2010, 01:17 AM -
need help. problems storing and displaying multiple user input
By dDarko in forum New To JavaReplies: 3Last Post: 10-28-2009, 01:45 AM -
Storing Data
By Khorod in forum New To JavaReplies: 1Last Post: 08-03-2007, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks