Taylor Thibodeaux

Greenhorn
+ Follow
since Dec 02, 2012
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 Taylor Thibodeaux

So I have a program for a project that permutes a random series of numbers using Java's Rand function. Basically I use a seed and a number of items I want in the arrangement of numbers, and the program makes a permutation with no two numbers being repeated. Only arrays can be applied to it, so I've been hard at work finding a solution. Here's the code so far:



So basically I'm wanting the program to make a randomized list of numbers from the number of items I pass to the Permute method with no duplicates. I'm having some level of success with what I have written, as it gives me a randomized list when printing the output, but for some reason the first for statement in code never terminates fully, but instead runs indefinitely when generating the last integer. For example, if I want to put 10 with a seed of 0 into it and make a list from 0-9, it will print 74283510, which is only 8 different integers. permutation[0] is manually set at the beginning of the method, which accounts for one more, but that's still only a list of 9, so I'm just wondering why the last integer is not being generated and why the program keeps looping and not terminating? I'm know for sure it's something I'm overlooking. Sorry for being so verbose, but I can clarify something if needed. Thanks!
10 years ago
Thanks for the reply. Very informative. Really my only problem right now is that the game freezes when I run it sometimes. I really just wish I knew where the problem is. I've double checked everything.
10 years ago
Alright here is a modified version of the panel to include the paintComponent(). It still freezes sometimes, but I think it's not as often. I havnt put in double buffering yet

panel.java:
10 years ago
So let me clear this up. The paintComponent() method will completely replace the render() that I currently have now? And the repaint() would be used to call that in the run()? Sorry if I didn't understand it. I'm just trying to wrap my head around this.
10 years ago

Phil Freihofner wrote:Lots of improvements in the code!

The "normal" way to do graphics is to override paintComponent(Graphics g). Then, in the game loop call repaint(). When this is done, the redrawing is placed on the EDT (event dispatch thread) and handled in an orderly fashion.

I don't know enough about the internals of Java to say why what you are doing does not work consistently. It could be that the drawing events you are attempting are getting "collapsed". Sometimes Java decides that two events on the EDT are similar enough that the second one is sufficient and it ignores the first. However, this can lead to situations where new events keep coming in and nothing ever gets displayed.

I've had this happen when the JPanel calls its own repaint via a Timer. When I put the Timer in a separate Object, and had that call the JPanel's repaint(), the collapsing stopped occurring. A similar thing could happen with a game loop residing on the very JPanel that is to be redisplayed. Placing your game loop in a separate object might be needed. (I've always used the Timer, not a game loop, so I can't say for sure.)

There are also many other mysteries (to me) as to how Swing and AWT schedule events. So I recommend, as a start, go with the normal method (using repaint() for displaying a JPanel, in conjunction with using paintComponent(Graphics g) and the Graphics object it provides) and see if the problem persists.


Thank you for such a thorough answer! I'm going to go try to implement the common method and I'll update on my progress later if I'm having trouble. Thanks again!
10 years ago
Everything is now functioning as it should, except for one thing. Whenever I compile and run my code, it only runs properly about 50% of the time. The other 50% of the time it immediately freezes when the program is started. Does anyone know how I can fix this? Thanks!
10 years ago
Hi thanks for the answer! I actually have figured it out since I posted this. I'll post my heavily modified panel class.

I am only adding one Panel to the JFrame. Is it recommended to add more than one? Because I've gotten the game to properly function. Yeah 75x75 was stupidly small, but I've changed it to fit my tile size.

I'm actually doing this as a project for a java class, but this is my first time experimenting with Graphics at all. My render and draw methods were what I was able to produce from the research I did on them. Does paintComponent() work better?

The each tile is represented by a image, which is drawn in the draw method().

I apologize if I didn't answer your questions thoroughly. I'm trying as best as I can from my understanding of Java terms, but I'm still amateurish.

Here's my new panel.java class.

10 years ago
I'm trying to make my first little java game here and I want to make it tiled-based. I'm trying to tile a block image on a JFrame and have put together some code to fit my circumstances. Unfortunately, it's not really working as it won't draw any of the test sprites I want, which is where I need the help. I'll post my code:

frame.java: I want to say that this is all correct...



panel.java:



map.java: This is where I attempt to assign the sprites...not sure what I'm doing wrong. BTW the test text file that I use in the constructor for the map is just a file that has the width,height, and then a bunch of random 0s and 1s. The 0s and 1s were used to show where certain blocks should go.

10 years ago
One more small problem, sorry heheh. I made a separate "Sorting" class that gets input from a txt file and outputs it onto another. In this class, it stores the height values in an array list. When I look at the new text file it generates, all the values are 0, even though the original text file had distinct single digit height numbers. I'm not even sure why an exception is not being thrown that was written in the original height class when both values are zero either. The feet and inches variables are correctly using the values, but its not making a height object correctly, and im not sure why.
11 years ago
Oh wow. Such a simple and overlooked fix. Thanks to both of you for the lightning fast reply! I was starting to get worried.
11 years ago
Hi, I'm making a program comparing heights using a compareTo() method and using comparable interface for the first time. I keep getting the error message "Height is not abstract and does not override abstract method compareTo(Height) in Comparable" and I just don't know why! Here's my code, and I would love help!


thanks!
11 years ago