Henrik Persson

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

Recent posts by Henrik Persson

Paul Clapham wrote:I think you made things a lot harder for yourself by implementing the array of cells as a one-dimensional array.


I wrote this program while reading the Head First Java book, and it wasn't until I finished the program that I found out about multi-dimensional arrays in the appendix, and it crossed my mind that I could have used one of those instead, but I fail to see how that would improve my code. Can you be more specific? Keep in mind that I am a total newbie to programming!

Unnar Björnsson wrote:I made this with javascript once, small project that was fun to do. You can take a look at it here it allows you to initialize the board and then press start, stop or reset. Just select view source in the browser to see the code. Since it is javascript that is similar to java syntax wise and since these kind of problem solving are language independent you might get some ideas from it.
Note: This is probably not the best or fastest way to implement this, it was just some pet project of mine I did for fun there is probably something that could be written better, also the code is not commented.


Thanks a lot! Google Chrome freezes when I try to view your code however, I'll try it in a different browser.
12 years ago
Hello!

I'm new to Java, and this is my first "real" project that I'm actually satisfied with, so I thought I'd share it with you. Took a few days to write.
It's a version of the famous Game Of Life by John Conway, where the cells are represented by checkboxes (only because making some other graphic version would be too advanced for me).
It looks alright, you can choose three different sizes and four different speeds. The layout might not be correct for all systems (it's optimized for OSX), but just a simple resize of the window so the checkboxes form a square pattern will do the trick.

Some questions:

-The checkCell()-method seems extremely clunky and awkward, and I guess there must be a better way to do it, any tips? Algorithms?
-The reason I put an infinite loop in the startGame()-method is because I kept getting exceptions when trying to stop and start the game, something about how threads work. Is there a better way to do this (without making a complete rewrite of the entire program)?
-Is there any way to make the gui platform independent?

Have fun! Code below:

GameOfLifeCell-class:



GameOfLife-class:


12 years ago

Campbell Ritchie wrote:Welcome to the Ranch again.

If you are that new I would suggest you try something simpler than the beat box exercise at first.


Well I am new, but I've worked my way through the book and done all the exercises so I'm definitely ready for it. It just so happened that I created a class with the same name as one that already existed in the API and was needed in the BeatBox exercise, and had it in the same folder.
12 years ago
I found out what was wrong. Last week I wrote a class that drew boxes based on user input, and of course I named it "Box". Renamed it, and BeatBox compiles just fine now. Can't hear any sound though... back to work.

Thank you all for replying!
12 years ago
Hi all!

I am totally new to programming in every way, shape or form, and I'm working my way through the Head First Java book (2nd ed). I have just finished copying the code for the initial BeatBox app, the one starting on page 420.
When I try to compile it, I get these errors:



There's obviously something wrong with the Box class but I can't seem to figure out just what it is. I checked the API and the Box constructor is supposed to take an int argument for its axis, but the compiler doesn't seem to identify BorderLayout.Y_AXIS as an int. Later on it thinks that BorderLayout.EAST and BorderLayout.WEST are Strings, and I don't know maybe they are, but it looks weird...

Here is my code for the buildGui() method, where all the errors live:


I doubt that this is relevant, but I'm running Mac OS X, coding in TextWrangler and compiling with Terminal. Java version is 1.6.0_24.

I apologize in advance if I've made an obvious mistake, but I've checked the code quite a few times and it looks right to me at least...
12 years ago