Eric Larsen

Ranch Hand
+ Follow
since Mar 28, 2009
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 Eric Larsen

Why does my my JLabel appear all the way on the right-hand side of my GUI?

The source code for the class:

Attached is a screenshot of the GUI output.

13 years ago
Sorry, I forgot to change it before I hit "submit." I'll do better next time.
13 years ago
Thank you, Ryan!

I revised the code to:

1. flush the buffers before switching I/O tasks, either by closing the stream, or flushing it manually.
2. create a new BufferedWriter for the second .txt file and assigning it to the old reference.

It now works exactly as intended. Thanks for the help!

Revised source:

13 years ago
I wrote this program to:

1. Write "Text to be hashed." to unhashed.txt
2. Read it back from unhashed.txt with a FileInputStream chained to a BufferedInputStream
3. Print the result to the screen.
4. Create a SHA-1 digest of it.
5. Print the digest to the screen.
6. Write the digest to hashed.txt

The class compiles and runs without any errors, but I do not get the desired output. unhashed.txt is created, but is empty, hashed.txt is not created, and the result of step two is not printed. The digest is printed to the screen, however. Any help would be very much appreciated.

The class source:

The screen output:

13 years ago
Okay, I'm writing a program that has to be able to verify a username and password to log on a user. I plan on doing this with a .txt file and some sort of system to encrypt the password or the password and the username.

1. Is this the right/best/most secure way to go about this?
2. How would I design this? I have a feeling I'll need to use either javax.crypto or

NOTE: I don't have much knowledge or experience with this kind of thing, so a link to a tutorial or a detailed explanation of what all is involved would be VERY much appreciated.

Thanks in advance for the help!

The code for the server so far (without the file I/O) :

13 years ago
Hey, everybody. I'm writing a chat server and client, and I've noticed that whenever I just shut down the client, the server throws an error, but no functionality is affected. In fact, if it weren't for the fact that I have the CLI for the server open whenever I'm running it, I wouldn't have noticed this at all. Is this even worth the time to fix? If so, how would I do that? I'm using plain Sockets, by the way.

Client source code:

The server source code:

13 years ago
Awesome, thanks guys!!!

It works very well now! I took Rob and Pete's advice and it helped quite a bit. Thanks!
I also put in some other code to check for the presence of text in JTextField outgoing before sending.

Here's the final code:

13 years ago
Thanks, Michael.

I'm still having problems, though. When I try to compile my code now, it give's me an error:

My revised code to bind the Enter key to my JTextField outgoing:

13 years ago
From what I can see, you are currently in the same directory as your .class file. Instead of running the class from here, you should run it from the /classes directory, like this:

C:\MyProject\classes\>java com.wickedlysmart.CmdArgs

That is, assuming that the class includes a package statement at the beginning of the file:

13 years ago
Hey everybody, I've been writing a simple chat program, and I was wondering about a few features that I haven't been able to figure out just yet.

1. How do I set the scroll bar's position manually, via code.
2. How do I call a method from a keystroke?

I plan on putting a method call to whatever method number 1 entails at the end of the while loop in IncomingReader's run() method, and I'd also like the program to be able to send the user's message when they press ENTER.

The code for the client class:

13 years ago
Thanks! I had a feeling it was something simple like that, but I had no idea where to look (as far as resources go) to find out what was wrong. The API only includes information specific to classes.
13 years ago
The following app is designed to play music using javax.sound.midi. It has three menu items, new, save, and load. New and save work as expected, but load does not. The load menu item has an ActionListener, LoadMenuListener. LoadMenuListener's actionPerformed() method opens the JFileChooser and passes the selected file to loadFile(File file). In loadFile(File file), a BufferedReader is chained to a FileReader(file). Then, the BufferedReader reads the only line in the file. This line contains 0's and 1's separated by commas. String.split(",") is called on the line and the result is stored as an array of Strings. Then, the program steps through each element and does an if/else/if:

based on the results, it sets the element of checkBoxList in question (a JCheckBox) to either true or false.

That is what SHOULD happen. What REALLY happens however, is that it does not change the state of any JCheckBox in checkBoxList. It give's no run-time errors.

Thanks in advance for the help!

Here is the complete code:

Attached is a picture of the gui.
13 years ago
Hi guys, I've got an app (an excercise from Chapter 13 of Head First Java) to make a drum/percussion instruments machine and I need a little help with the GUI. The JLabels on the left are in a Box component , and I need some way to get them to match up with each row of JCheckBoxes in the center (in another Box.) Thanks in advance for the help!

13 years ago
I'm having pretty much the same problem with MIDI messages. Please see this thread if you think you can help.
13 years ago

So obvious I couldn't see it.... I hate logic errors.
Anyway thanks for the help!!!

EDIT - Nevermind, it didn't work I'll download the code from the site now.
13 years ago