We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have saved three lines in a text file and three Glabel, how to save every life in Glabel ??? That is: line 1 in Glabel 1 line 2 in Glabel 2 line 3 in Glabel3
the easiest it will cycle through "for", but as a change in the cycle variable name Glabel?
for(int i=0; i<+2;i++) { ['label'+і].setText(reader.readLine());} So not working
Answers
"reader.readLine()"? ['label'+i]? What are those? Preferably give your full code, if you don't have any smaller working sample.
How to write a line in the variable GLabel tn1, tn2, tn3 and so on, tn1.setText(line);, through the cycle? How can the loop to create unique objects such GLabel?
@gada94 --
Please format your code (do not use >, instead highlight and CTRL-o to indent four spaces). https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
You appear to be using @quark 's G4P library and the GLabel obect -- is that correct?
Can you provide a small working sketch that demonstrates the problem? We cannot run / test this code to help you.
Yes,G4P library and the GLabel obect. Here's a sample window!! Pressing the button should be set up facility + 3 "GTextField" and "GLabel"
I believe there is no way to access a variable with a String equal to its name in Java, and that is what you're trying to do.
You will need to shift from G4P's GUI builder and write a lot of code yourself, using Arrays (or maybe ArrayList),if you want what you said.
I understand, I ask and how it will be easier to write because arrays or lists?
Remove the semicolon right after the for bracket. You effectively finish the loop right there. The next part of it has no knowledge of the variable i.
Deleted, no errors and does not work, hangs on startup
Give us your full code - else we couldn't possibly guess the problem.
For one, you need to add an event handler to each of the buttons.
"For one, you need to add an event handler to each of the buttons." How to do it?
You already did that on line 37 of your full code.
In any case, the line 31 will put the labels at nearly the same position (differ by 1 pixel).
Change
192 + i
to192 + (i * 105)
. You may later fine tune your values to get the best look.As to the error, does it show some error message when it crashes?
Is so, post it here, and format it just like code.
in this line stops:
label[i]= new GLabel(this, 192+i, 227, 80, 20);
NullPointerExceptionCould not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.
No, not like that. You need to copy the message in the console (hopefully you know what that is) and paste it in the forum, and then format it like code.
Why don't you use loadStrings and saveStrings methods to load and save a String array to a file instead of BufferedReader. After that the rest should be easy.
The program hangs. That's all writes to the console
That's funny. Then I have no idea.
Did it work! Error here!-
GLabel[] label;
, Right toGLabel[] label= new GLabel [10];
Does your code run now without the JVM error message?
Yes, it works well. try use loadStrings and saveStrings methods to load and save a String array to a file instead of BufferedReader.
Some things about about GUI Builder that will make your code better.
1) When a control is added it provides default variable name and a default event handler name. You should change these to make it clearer what they are used for.
2) If a control doesn't need an event handler e.g. a GTextField then delete the handler name in GUI Builder.
Sometimes it is useful to be able to have arrays of controls but GUI Builder does not support that. What you can do is create your own arrays AFTER the GUI has been created. I have done this in the code below.
Main sketch tab
gui.pde tab
Damn it, I should have noticed something so trivial.
Though I've never seen something like that cause a crash without a proper error message.
@quark Excellent idea. G4P is your library, right?
Yes, I used the library G4P. @Lord_of_the_Galaxy and @quark thank you for helping me without you I would not be able to do their thesis project.
Yes I created G4P.
@gada94 good luck with your theses.
@quark Another question, "saveString" stores each array element with a new line. If redo "saveString" is pre-line again overwritten. How to store the text in the last line and did not remove the previous line?
I assume you want to append the new lines to lines previously saved. Using the code I gave above modify the btnSaveClick function. It loads the existing file contents then adds the new lines before saving hem.