594 Color Bars
Spring 2007, David Matuszek
You are given a set of
N "color bars," each bar containing
3 <= N <= 12)
be rotated to
Your task is to:
Ask the user for a file, then read in the initial color bars from that file.
One line of the file will represent one color bar, and each line will contain
numbers representing the colors on that color bar. For example, for
N = 5,
the input might be:
3 4 1 0 2 3 1 2 4 0 4 0 3 2 1 3 1 2 4 0 3 1 0 2 4
(You can assign colors to the numbers any way you like.)
Hint: The easy way to read in these numbers is to use the String methods
split("\\s+") and the Integer method
Display these colors in a grid. For example,
Your task is to rotate each color bar until no column contains more than one of any color. Display your work as you go.
This is a simple (yes, simple!) backtracking program. Starting from the top, rotate each color bar until there no conflicts (duplicate colors) with any of the color bars above it. If that isn't possible, backtrack to the color bar above, and rotate it some more. Continue until all color bars are in the correct place.
If no solution is possible, display a message dialog to say so.
After each problem, allow the user to either read in another data file, or quit.
returns a JPanel containing buttons of those colors, arranged horizontally.
resetColors()method uses the same array as was previously given in the constructor, and changes the button colors and text to match the new arrangement of colors. A separate Thread is used to provide a one-second delay between color changes.
mainmethod simply displays a single
ColorBarin a JFrame, then shuffles the colors and calls
resetColors()several times. This is a throwaway class whose only purpose is to give an example of the use of the
Wednesday, February 28, before midnight. This is another individual assignment; you are expected to do your own work.