Help coderanch get a
new server
by contributing to the fundraiser

Joe Degler

+ Follow
since Oct 10, 2011
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joe Degler

Steve Luke wrote: [...]

Thank you for giving me the probably most understandable answer ever. I took some looks at the API to figure out what which commands mean, there are still some things I dont know, but I think I'll find out their use while I program.

Even still, Thank you thousand times!
12 years ago
Hello everybody,

first of all, there is no Code existing yet, I am only imagining how I'm going to write the code when I'll start doing it.
I've planned to do a very little Game with Java, which leaves me at a Question:

If I do a Loading Screen, I'll need one thread caring for the GUI itself, and then one thread loading everything into ArrayList out of data and turning boolean's to 'true' in Thread1. Imagine it a bit like this:

Thread1 = Set JLabel to 'Loading Level', while-loop to check if Load1 is true
Thread2 = loaded the Level, put everything needed into the ArrayList (in this case the tiles), set Load1 in Thread1 to true
Thread1 = Load1 is true, change JLabel to 'Loading People', while-loop to check if Load2 is true
Thread2 = loaded the People, put everything needed into the ArrayList (in this case the peopleentinitys), set Load2 in Thread1 to true
Thread1 = Load 2 is true, Go through the ArrayList of Level and get the corresponding Tile.png(or whatever) and row them after each other [...]

This is probably not very efficient, but for a beginner it's what I need. I've been thinking of this various possibilities:
1. Let Thread2 write False/False in a text data and Thread1 reads the data every 0,5 seconds to see if it is True/False or True/True and set the boolean
2. Let Thread2 go back into the main() class on the bottom of the stack and change the Data there and let Thread1 check the main() aswell, both Threads beeing started from there.

I've not yet tested both of them, but I'm sure there must be a better way to do this.
I hope I've clearly written what I meant to do, if there are any questions left, just post them!
Oh, and yeah, I've already googled, but I did not quite understand what I found there...

Best Regards,

Joe Degler
12 years ago

Paul Clapham wrote:The "return in 5 minutes" is the part of the design I don't understand either. What's the point of that? Why not just ask the next question immediately? Let the user decide if he wants to answer immediately or not.

And this idea of GUIs appearing and disappearing is completely non-standard too. You're designing your application as if you never saw any other applications, which surely isn't the case. As a beginner you should design your applications to work in a standard way, because it's a lot easier to do that. When you have more experience, then you can try writing applications which do weird things.

Now, here is the thing:

I want them to appear over the day, not to guess them nonstop as it's non-fun in that way. Letting it like reappear every 5 minute's is not gonna annoy you.

I'm not sure why it's that hard to understand, either....
12 years ago
I'll try to explain it for a user:

First off, you open the "Vocabulary.txt" file, and then you write your words insite of that like this: German$Spanish and do a new line after that.
Now you open the "Random.txt" file and insert all Vocabulary that you want, only the Spanish ones and all seperated by $, like this: Spanish1$Spanish2$Spanish3...
After you're finished, you open the program. It will open a GUI which shows your German word and it wants that you type in the Spanish word in the field underneath it, then press the Check button to check it. If it's right, it will dissappear, and reappear after 5 minutes giving you a new word. (Everything after this is not yet in the code, due to failure to solve the problem yet) If you however been wrong, it will show you 3 words, one of them is right, two of them are out of the Random.txt. You choose one by clicking the RadioButton and it gets checked again. If its right, it'll dissappear for 5 minutes again. If it's wrong, it will show you the right translation and you're supposed to type it in right then send it off. Now it will (finally) dissappear and return in 5 minutes.

The "return in 5 minutes" is the part where I got the Idea to use "sleep()", to put the thread to sleep and let the loop finish after 5 minutes, instantly starting it again.

But thats the point where my logic failed. Even if I program everything like I described and even if it's working, the thread finishes itself before I'm able to do anything, as the ActionListener are not valid anymore as there is nothing there to stop the thread to finish.

It's at this part:

After the addActionListener has been registered, "haupt()" which was on top of the stack, is finished and all other methods are finishing itself, not giving any chance for the ActionListener and the user to even have a Chance to do something.

Now the thing that I need is something like this:

Now a Idea I just got to put the whole GUI and actionlistener into a different class and a different thread, but first I want to know if there is any shorter solution.

Still thanks for everyone yet,

Joe Degler
12 years ago
Not sure if it's allowed, but.. push?
12 years ago

Ralph Cook wrote:The first thing I asked for was a one-paragraph summary of the program. I still have very little idea what the program is about, and none about how it goes about it. Appearing and disappearing panels? "Got to sleep for 5 minutes"?

I realize it's almost a lost art in software engineering, but what we need here is a functional description. How would you describe to a user what the program does?


Start the program. The program will start a new Thread and then it will read the Vocabulary Data out of your Text data. Then it starts a loop. Inside of the loop there will be 3 random numbers generated, that will choose which Vocabulary will be tested. r1 beeing the tested one and r2 and r3 beeing random ones out of another data. Now create a GUI, Put the german word as a Label in one panel and create another panel with a TextField with a button next to it. Now you type the right Translation into the Textfield. If the translation is right, the program will close the GUI, put the Thread into sleep mode for 5 minutes, wake up, close the current loop and then get reopened. If not, the Panel with the TextField and the Button will be removed from the Frame, and a new Panel will instead be added, having the 2 random words and the 1 right word, each with its own JRadioButton. If the User chooses the right option, see above. If its wrong, remove the JPanel with the JRadioButton and add a Panel which shows a JLabel with the right Translation, a JTextField where you have to type the word into again and a Button to check the typed in.

I tryed to make it as detailed as I could... is it enough?
12 years ago

Ralph Cook wrote:

Try taking a step back and telling us, in one paragraph, what your program is supposed to do and what it does now. Specific things that puzzle me about the explanation you've written so far:

* Program starts, creates thread, starts run of the main class...

You normally create a thread other than the one you are running in when you want two things to proceed in parallel. You state that the main class loads array lists with data from text files, and I guess that's in the thread you create. What is the other thread doing?

The other does simply nothing. I just made a new one because I wasn't sure if laying the main thread to sleep would cause problems.

* for-loop starts

I gather you wanted something to loop -- what is it? Do you loop once per word the user enters? Once per panel? Once per month?

After all Actions have been done, the programm shall go to sleep for 5 minutes, when it wakes up again it finishes the method's and the loop starts from new.

* it continues with the whole thing, opening the same gui over and over

Now I'm lost -- what is 'the whole thing' you are referring to? Is opening a new gui at all something the program is supposed to do,you just want to control it?

It keeps reopening the same GUI because the loop finishes itself as there is no "Close gui when method is finished"

And the logical guess doesn't make any sense to me either; why would you get rid of a panel and open a neven under your control?

First I want a JTextField Panel which checks if the word is written right, if it's written wrong, the JTextField panel closes and a Panel with JRadioButton is where the other used to be before and more, but all depending on the same princip.

I'm sorry, but trying to read incomplete code in German is something I'm only liable to do if I think I can tell, from your description, the general sort of things I'm looking for.

No problem.


Answers in Italic under the questions.
12 years ago
Hello anybody!

Today I've completly written my Vocabulary program from scratch, dividing things into different classes instead of just two.
That worked fine, but now I'm stuck at a part:
Let me describe what happens.

Program starts, creates a new thread, starts the run() of the main class, main class loads data out of textfiles into ArrayLists, for-loop starts, the gui opens and now the thing happens:

The GUI opens, but, it continues with the whole thing, opening the same gui over and over until it reaches the maximum of X that I told him to be the max before.
Now, I want the program to WAIT at the point where it is, until the user typed the text and then pushed the button to activate the ActionEvent telling the frame to either close or the panel to close and open another panel.
Here is the code, but the gui is not 100% finished. Oh and please mind that most of the words are german.

Do not forget the main problem, I want the thread to stop at the point after the GUI is set to visible and then continue after the button is pressed.
And as a side-note: Do you see places where I could improve the code? Make it smaller?
12 years ago
Thank you, changing


solved the problem.
12 years ago
Okay, here is the updated code, still with the same problem:

Now, the problem seems to be this line here:

...and the same for every other line that uses that command.

I still cant see what I'm doing wrong
Wort1[0] which has the first String out of the text data (before the first $) sends his word into the deutsche ArrayList which has Strings. Or is something wrong?
12 years ago

Paul Clapham wrote:I think your line counting might be off by one. However the easiest thing to do is to put some debugging statements into your code to see what's happening. Like

for example.

Also, "String" is one of the worst possible variable names you could ever choose in Java. Whenever I see that I think of the type "String" and I have to force myself to realize that it's actually a variable name. Very confusing.

I'll try that tomorrow...
And sorry for calling it string, I just wanted to be 100% sure it's working like its in the book...
12 years ago

Rob Spoor wrote:Although it's not the cause of the NullPointerException, your call to linie.split("$") is wrong. The split method takes a regular expression, and $ has a special meaning in regular expressions. You must escape it:

Thank you, didn't know that, instantly corrected it!
12 years ago

So with other words the highlighted line is the problem. But I still dont get it, String linie gets the line out of the data through zeilegeben(zeile); , which starts zeilegeben(String linie). So String Linie should get the text of "zeile", lets just say "Test$This", which then gets seperated into a String array of the type String, String[0] representing Test and String[1] representing This. Or am I wrong about this?
12 years ago
Hello Guys,

I am currently writing a Vocabulary learn program for myself, and beeing done with all the Random choosing and so on the biggest part of the code is done.
You can see the code here:

(Sorry if it's messed up a bit)
The code gets started through a main in another class, the first thing runnin' is the "run()".

Now however, I keep getting a NullPointerException, together with my "Couldn't find the Vocabulary File!" and "Couldn't find the Random File!".

Konnte die Vokabel Datei nicht lesen.
at Vocabularymain.zeilegeben(
at Vocabularymain.dateiladen(
at Vocabularymain.gui(
Konnte die Random Datei nicht lesen.
at Vocabularymain.zeilegeben2(
at Vocabularymain.randladen(
at Vocabularymain.dateiladen(
at Vocabularymain.gui(
Exception in thread "Thread-1" java.lang.NullPointerException
at Vocabularymain.getRandom(
at Vocabularymain.gui(

I've checked twice, the data are there, and using a small testing program I copied out of Head first it worked:

In that case I get the both inputs I've made into the file MeinText.txt

I'd be very grateful if someone was able to help me, because I'm at the end with my knowledge right now. Eclipse didnt show me any error. The Compiler didnt show me any error (well, thats logical to be honest.)
Please note that the code is not 100% finished, so there may be some weird things.

Oh, and can you see potential where I could have saved some writing?

Thanks in advance for your help,

Joe Degler

(Please note that this is my first serious... "program", so dont be too harsh if you spot something )
12 years ago
Thank you for your effort Stefan, but I've got a German version, and the page 200 wasnt 100% correct, it was acutally 209, and while I was reading about .equal() I made myself the little challenge to create the simple code shown above, to be sure I understood it right.
12 years ago