• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to update my data.. why is that so..?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)
Also how can i hightlight impt dates in a JList (as i'm doin a Calendar schedule) i want to have those date with appointment saved to be bold & in red colour..

Is there any kind soul out there that would help me.. I urgently need a reply.. Thanks.. Anxiously waiting 4 a reply..

Regards..
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to try and explain something to you and I hope you understand that I am trying to help you here...
You need to stop asking so many questions in a single thread. The first part of this post...
i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)
...has nothing to do with Swing/AWT/JFC. Just because you are reading and writing to files from a Swing application doesn't make it a Swing problem. So this part of the question should really be seperated into a different post in the I/O and Streams forum. Now that doesn't mean repost this entire thread in that forum. That means, seperate your problems. You have 2 problems in this question.
Now your second problem is fine here in the Swing forum. So that one we can deal with. Here is a tutorial on JList. There is a link in that tutorial that talks about a Custom Cell Renderer. This is what you need to change the color of the items in your JList. I will let you find the link. That way I know you read the tutorial a little bit anyway.
Once you have started working on that part of your code, and are having problems, let's see what the problems are and go from there.
Again, concentrate on 1 issue at a time. It will make things easier for you. Especially since you are new to Java.
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr Gregg,
I understand what u mean.. i would separate my problem the next time..
Now i need to know if anyone can reply me abt:


i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)


(becos u were saying i shouldn't post again in I/O & Stream)
So i'm not sure where i should post it now.. And i need to know what is the problem with my program asap.. Really sorry in creating so much troubles for u.. And a big Thanks..
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is because you are creating a new file everytime instead of appending to the current file. You need to take a look at the API for FileOutputStream.
public FileOutputStream(File file, boolean append) throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

Hope that begins to help.
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry.. i dun quite understand.. can u show me an example..?
Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Freya Tan:
Sorry.. i dun quite understand.. can u show me an example..?
Thanks


Using your code...

That tells the OutputStream to write to the end of the outputFile instead of overwriting what is already there.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since this is turning into an IO thread, I am going to move it to the I/O and Streams forum..
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(that's in my code)


FileOutputStream out = new FileOutputStream(outputFile); PrintStream fileOutput = new PrintStream(out);
for (int x = 0; x < AppList.size(); x++) {
aObjt = (FindDay)AppList.get(x);
fileOutput.println(aObjt.getDate() + ";" + aObjt.getMonth() + ";" + aObjt.getYear() + ";" + aObjt.getTime() + ";" + aObjt.getAm() + ";" + aObjt.getApp());
}



if that is inside my code already, then how cum i'm still overwriting it..?? pls point out the sentence that i have mistake in.. Thank u
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D:\Java Project\AppointmentPage.java:401: FileOutputStream(java.io.File,boolean) has private access in java.io.FileOutputStream
FileOutputStream out = new FileOutputStream(outputFile,true);
^
i have this error after adding the " (outputFile,True) ".. what is this error..?? i have nv seen it be.. any way to slove it..

Regards..
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you looked at the java documentation for java.io.FileOutputStream, you'd see that the constructor you are using is available only in SDK's 1.4 and later. Are you using an older SDK/JDK?
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying..

Yes, i'm using a JDK 1.3.1 . anyway that i can change my coding to suit JDK 1.3.1 ... i have been trying for a few days and my deadline is tomorrow.. pls help me.. a big thanks to u..

Regards
 
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic