Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stuck with some code!! 1

Status
Not open for further replies.

badbhoy

Programmer
Apr 11, 2002
12
GB
i have writen a program to act as a recorder and another program to store the details entered and a gui interface for the information to be entered. but when i enter the details into the textfield the information isn't stored

i am using my getter methods in my Recorder class to take the information from the textfield by using this code


if(source == dtextfield)
{afine.getCarColour();
etextfield.requestFocus();
}
else
if(source == etextfield)
{
afine.getCarType();
book.requestFocus();
}
if(source == save)
{
Record.recordticket(afine);
Record.save();
Record.load();
}

and i want to save it to a txt file by using my methods save and load and recorderticket from the program i have to store the information

but it keeps saying on the dos screen the qoutes i have set foe no information entered
if u can understand this any help would be great
 
well, i dont think i understand that too well, but from a purely syntactical point of view, aren't you missing an
Code:
else[\code].

isn't the format

if(boolean){
   //code
}
else if{
   //code
}
else{
   //code
}

probably that has little to do with the problem, just something i noticed. [COLOR=blue]Avendeval[/color]
 
Well the provided code (which is syntactical correct) is not enough to really help anwser the question. I would like to help, but I would need to see all the source. However it sounds like the source is to much to post in a message. If you can post a link to a jar or zip file of the source to download. Also if you could give me the steps to reproduce the error you are getting. I can run the program and try to debug/iscolate your issue for you.

Let me know...

Rodney
 
rodney

i uploaded the zip file to my friends site

just add the link below to your browser to download my zip file


i am trying to design a car park ticket recorder to simulate issuing tickets the files needed are DataRecorder.java;
Booking.java;(this file is to save a booking to a txt file)
DRGui.java ; (is my interface where i have linked the files and DRGuiClose".java; (is to run the program)

when i enter information to the textfields and i press the save button i want to save that information to the txt file.
but it isn't saving my methods save(),load() and recordticket() are in the booking.java and my getter and setter method are in my DataRecorder file there is other file in the zip but they are for trying different option.
all i need to do is to get the information of the textfields saved into the tickets.txt file which i have declared in my booking.java file any help would be great as i am stuck at this. to get the ticket recorder finished.

thanx
 
Well I have downloaded and ran you code. You are serializing your DataRecorder object to a file. The reason this you are save an object with out any data, is because you are not setting the DataRecorder "afine" members via it's setters, except for the fine. For some reason you are just calling the get methods for each text field in the action performed. I do not understand by you have your action listener added to all your textfields. In your case you only need the action listener to be added to your buttons. When your save button is clicked an it your actionPerformed method is called, in your if block:
Code:
if(source == save)
{
    Record.recordticket(afine);
    Record.save();
    Record.load();
}
Before you call your Booking object "Record" methods, you need to set all the fields in the DataRecorder object "afine" with the information from the text fields like so:
Code:
if(source == save)
{
  afine.setBadgeNo(ctextfield.getText());
  afine.setCarColour(dtextfield.getText());
  afine.setCarRego(gtextfield.getText());
  afine.setCarType(etextfield.getText());
  afine.setLocated(ftextfield.getText());

  /*
   * You do not have setters for the
   * Date, Time, and Fine, text fields.
   *
   * atextfield, btextfield, htextfield
   */

  Record.recordticket(afine);
  Record.save();
  Record.load();
}
Also do not add action listeners to your text fields. Remove the if else statements for them, leaving you with only a if/else if statements for save and book.

I test this and it works with the code I downloaded.

I hope this helps you out...

Rodney
 
hi rodney i've changed my program and some of it doesn't work i was wondering if u could post the changes u done to it as a link so i could have a look at ur changes and to see where i am going wrong.

thanx
gary
 
The only changes I made were above. I will check to see if I still have the source code this evening, and if I do I will pak it up and give you a link. But the only changes I made I posted above, and they should work, "IF" you did not make any changes to the code since I downloaded it :) hehe

Anyways.. I will check for the files...

Rodney
 
Sorry it took so long, but I did not have the files any longer, however, I downed them again from the link above, and I reimplemented the changes I stated above, and it compiles, runs and works. Below is a link to the only file that I changed. I will leave it on my site for a few days or until I see a reply stating you got the file, which ever comes first.


I hope this helps, if it still not working, download your assignment.zip file from your link above, then replace the DRGui.java in it with the modified one above. Then run DRGuiClose2 class. (There was no DRGuiClose.java file as you stated I am assuming you ment the one just stated)

Let me know...
Rodney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top