As a follow up to an earlier post on double braces in Java, came up with a short, but ugly way of filling an ArrayList…
As a follow up to an earlier post on double braces in Java, came up with a short, but ugly way of filling an ArrayList…
This is one of those that I never remember, but use a lot whenever I want to pull an entire file into a String quickly.…
Came across this the other day on Stack Overflow. Turns out there is a way to one line create an ArrayList and fill it all…
This comes from needing a quick and easy way to rotate a String in Java.
It’s a pretty common task to get the distance between 2 points. Maybe you’re wanting to see if two points are close enough to have…
There are two ways to measure angles. You probably learned to measure angles in degrees early in school. A circle has 360 degrees, a perfect…
Creating the next great side scroller? Well, you’ll need a scrolling background. And if you’re programming in Java, here’s an easy way to do it.
Here’s a little demo of what we’re going to create. What’s happening is that there are two copies of the same image scrolling from the right to left. As one copy gets all the way off the left edge it leapfrogs back over to the right side. Normally they’d be the same, but it makes more sense on the demo for the two copies to be different colors.
The black box is the screen. Everything to the right or left of the box is happening off screen.
Click to start and click to stop.
Earlier this week I Googled for how to find the dimensions of an image using Java, and most of the solutions were way more complicated…
Want to create a random color in Java? With a bit of math, plus Math.random(), it’s pretty easy.
Colors on the computer are made up of a red, green, blue triplet; typically called RGB. And each of the 3 pieces can be in the range from 0 to 255. Java also allows us to create a color using floats for the values in the range of 0.0 to 1.0, or from 0% to 100% of that color. We’re going to use the floats.
As an example, pure red will have an R value of 1.0, a G value of 0.0, and a B value of 0.0.
So we know what numbers we need, but we want ’em random.
There really are some things that don’t need to be copyrighted. Take the following example for, well, example. Oracle wanted to protect their IP. Sure,…