• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to make this code able to write to file and read then

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I would like to make this code to be written in file, but it is impossible for me to do it. I tried several solutions and I just couldnt figuered it out.  I deleted actionlistener and bufferwriter so that you have just clean code. You press button "Imenik" and it opens table and this table i want to save with all data and if you can add button add new line I will be even more happy. Thanks for help.





Filename: Nova-slika-(6).bmp
Description: C:\Users\Gregor\Pictures\Nova slika (6)
File size: 898 Kbytes
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you need to fix numerous problems.

1. By convention, class names should begin with a capital letter. So name it something like "MyPanel", or some other name that better describes what the class is supposed to do, instead of just "panel".

2. In createAndShowGui, you call setVisible(true) before you add anything to your frame. Don't do that - it is possible that nothing will ever be displayed.
  The setVisible() should be the last statement in createAndShowGui.

3. You are calling content.setLayout after you add stuff to content. You need to specify the layout before you add anything to it.

4. You have a JButton named "b3a" and a method named "b3a". This is not a good thing; what do you think the compiler will thing hyou mean if you type "this.b3a" ?
 
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

That GUI code shou‍ldnot write anything to a file. You sh6‍ld have a separate class which does the reading and writing. I presume you are familiar with the general IO capabilities of Java®. Can you write code which does the writing separately from the GUI? Start with that and show us it, then consider how to control such code from the GUI.
Don't make the GUI classes into action listeners. Don't use == on Strings (but that is probably not the real problem).
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okey. I will explain little bit.

1. Class b3a is because it is part of a much bigger code and I have only here problems to make writer.
2. code is work perfectly for now (no mistake), but this I can fix so that it will be.
3. Yes I have button b3a  because this is part of original code and I wanted that it looks like if it would be actually entire code shown here. That is why it is looking so confusing
4. I hope you can see my attachment, I put printscreen to see the table how it looks like.

Sorry for confusion and mess ( I am not professional) .
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

That GUI code shou‍ldnot write anything to a file. You sh6‍ld have a separate class which does the reading and writing. I presume you are familiar with the general IO capabilities of Java®. Can you write code which does the writing separately from the GUI? Start with that and show us it, then consider how to control such code from the GUI.
Don't make the GUI classes into action listeners. Don't use == on Strings (but that is probably not the real problem).




Thanks. Yes this code doesnt write anything, because it wont help if I would put "normal text" writer, because it doesnt save. I attached again a table which I want to write to file. I litterally tried everything to write it in file but I am too st...... to do it. If you know hot to add a button like add new line it would be great too.
Filename: Nova-slika-(6).bmp
File size: 898 Kbytes
 
Marshal
Posts: 8957
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apart from the GUI part, I'm totally puzzled what you are trying to achieve. Please explain in simple words what the app is supposed to do. Please don't mention any technical terminology how you're going to do.
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Apart from the GUI part, I'm totally puzzled what you are trying to achieve. Please explain in simple words what the app is supposed to do. Please don't mention any technical terminology how you're going to do.




Ok. When I fill table or put some data (look attachment for table) then I want this to save to file and read it.
 
Liutauras Vilda
Marshal
Posts: 8957
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gregor Kunc wrote:When I fill table or put some data (look attachment for table) then I want this to save to file and read it.

So you'll need I think to get text from the cells and write them to file.

Campbell suggested I see already to go through tutorial and learn how to write data to the file. Have you checked it?
To get text from the cell I think is the easier part.
 
Liutauras Vilda
Marshal
Posts: 8957
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it going to be a text file?

Consider what kind of delimiter you want to use to delimit data written to file. What formatting?

Create some dummy String "vienas du trys keturi penki sesi septyni astuoni devyni desimt" and try to pass it to method and write to a file in the way you want it.
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Gregor Kunc wrote:When I fill table or put some data (look attachment for table) then I want this to save to file and read it.

So you'll need I think to get text from the cells and write them to file.

Campbell suggested I see already to go through tutorial and learn how to write data to the file. Have you checked it?
To get text from the cell I think is the easier part.



Problem is I dont know how to get data from this cells. That is problem. Text from textfield etc it is easy to write to file (like data.txt), but this is impossible for me to make it read. If I tell the truth I dont even have any idea how to begin with reading cells. I will go trough tutorial. But I saw so many examples which didnt work. Thanks.
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Is it going to be a text file?

Consider what kind of delimiter you want to use to delimit data written to file. What formatting?

Create some dummy String "vienas du trys keturi penki sesi septyni astuoni devyni desimt" and try to pass it to method and write to a file in the way you want it.



At least I want that data in row is written in same line and another  row in another line... I really dont care if it is txt or any format just that is work.
 
Campbell Ritchie
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best solution at present is probably beer. Sit down, drink some beer and take it easy. Then divide the problem into tiny little parts. Start by writing Liutauras' little dummy String to a file. Try doing that with a Formatter (more details in the link I gave you earlier) if it is a text file. Once you have that working, work out how to write multiple Strings as multiple lines to the same file. Then try writing each String in a List<String>
 
Liutauras Vilda
Marshal
Posts: 8957
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gregor Kunc wrote:Problem is I dont know how to get data from this cells.

This tutorial. Below there are paragraphs with examples how to get text from tables.

I'm not proficient with Swing, but I'd start there.
 
Campbell Ritchie
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have just suggested he start at the other end of the process. My post is better because it mentions beer

It doesn't really matter which part you do first, but only do one part at a time, otherwise you will become all confused. If you get the details from text fields first, you can start by using System.out.println to show what the text you have read is.
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I have just suggested he start at the other end of the process. My post is better because it mentions beer

It doesn't really matter which part you do first, but only do one part at a time, otherwise you will become all confused. If you get the details from text fields first, you can start by using System.out.println to show what the text you have read is.



Jah men. I will try, but this is going to kill me. I thought somebody will be so nice and write this for me . So then I have to use if  , else and other son of a .................
Thanks. I will report how it is going and if I would drink beer then I dont think that....... ah who cares I am going to drink it. Thanks for good idea.
 
Campbell Ritchie
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need any if‑elses? We believe you will learn better if you find out the information for yourself, so we do all we can to avoid simply giving out solutions. How far have you got with it?
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Do you need any if‑elses? We believe you will learn better if you find out the information for yourself, so we do all we can to avoid simply giving out solutions. How far have you got with it?



thanks, i found some post which i modified and make it work for my program. I know it is better to find it byyourself, but this code was less complicated and it was easier to work on. Of course I would like to learn but I need good teacher -
 
Gregor Kunc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it possible to give  a color to double and to "" in ta.setText(ta.getText() + "Datum: " + datum +...)
 
I've never won anything before. Not even a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic