Question: GUI SWAMP OR BOGGLE Using your Swamp or Boggle Solution, write a GUI ( like the SimpleCalc ) that displays the board or swamp prominently.
GUI SWAMP OR BOGGLE
Using your Swamp or Boggle Solution, write a GUI ( like the SimpleCalc ) that displays the board or swamp prominently. Place text fields and labels as needed to allow the user to type in the name of the input file or files. The Boggle will have to allow the user to specify both a dictionary file and a boggle board file. The swamp only needs one input file. Both GUIs must have a TesxtArea ( bigger multi line version of a TextField) to display the results of the algorithm. The boggle TextArea should display the set of read dictionary words found in the grid. You should just print them out one after another separated by a space and let them wrap around. Don't print any newlines anywhere between boggle hits. For the Swamp you will print lines of output just like you did for the actual assignment where each line has a newline.
You will be graded on correctness of output but significant weight will be on aesthetics. You may surf the web to see images of elegant layouts and such but you may not use their code. If you see an aesthetic board graphics you must write your own code to produce that layout and look. YOu will have to do web research to learn about controls that we did not cover in the course -s so there is some self directed research you must do.
EXTRA CREDIT: if you can find a way to animate the algorithm you get extra credit. For the Swamp you might change the background color of all the cells that are currently part of an active path and as you retreat you change the color of the cell back. This way it is obvious to the user what path is being grown or retreated from. Likewise the Boggle game could do the same thing and maybe blink all the cells of a word that just got found in the dictionary.
Another valuable feature would be the sue of a Timer object or thread in combination with some kind of control to adjust the delay between each step of the calculation so that the GUI does not fly faster than the eye can keep up with.
Handin a file named SwampGUI.java -or- BoggleGUI.java
Exceptional programs will be used to teach/illustrate the behaviour of recursion and backtracking to future classes. You will be credited as the author.
import java.io.*;
import java.util.*;
// DO NOT!! IMPORT JAVA.LANG
public class Swamp
{
private static int[][] loadSwamp( String infileName, int[] dropInPt ) throws Exception
{
Scanner infile = new Scanner(new File(infileName));
int rows = infile.nextInt();
int cols = rows;
dropInPt[0] = infile.nextInt();
dropInPt[1] = infile.nextInt();
int[][] swamp = new int[rows][cols];
for (int r = 0; r < rows; r++)
for(int c = 0; c < cols; c++)
swamp[r][c] = infile.nextInt();
infile.close();
return swamp;
}
public static void main(String[] args) throws Exception
{
int[] dropInPt = new int[2]; // row and col will be on the 2nd line of input file;
int[][] swamp = loadSwamp( args[0], dropInPt );
int row=dropInPt[0], col = dropInPt[1];
printPath(swamp, dropInPt);
} // END MAIN
private static void printPath(int[][] swamp, int[] dropInPt)
{
int[] point = new int[2];
point[0]=dropInPt[0];
point[1]=dropInPt[1];
if (point[0]==0 || point[0]==swamp.length-1 || point[1]==0 || point[1]==swamp[1].length-1)
System.out.println("["+ point[0] +","+ point[1] +"]");
else
{
ArrayList
String path = "["+ point[0] +","+ point[1] +"]";
pathes.add(path);
for (int i=0; i< pathes.size(); i++)
go(swamp, pathes, pathes.get(i));
}
}
private static void go(int[][] swamp, ArrayList
{
int point[] = new int[2];
point[0]=Character.getNumericValue(path.charAt(path.length()-4));
point[1]=Character.getNumericValue(path.charAt(path.length()-2));
if (point[0]==0 || point[0]==swamp.length-1 || point[1]==0 || point[1]==swamp[1].length-1)
System.out.println(path);
else
{
if (nextStep(swamp, point, pathes, path))
{
if (!path.contains("["+ point[0] +","+ point[1] +"]"))
path= path+"["+ point[0] +","+ point[1] +"]";
if (point[0]==0 || point[0]==swamp.length-1 || point[1]==0 || point[1]==swamp[1].length-1)
System.out.println(path);
else
go(swamp, pathes, path);
}
}
}
private static boolean nextStep(int[][] swamp, int[] point, ArrayList
{
boolean next = false;
int count = 0;
int row = point[0];
int col = point[1];
for (int i=row-1; i<=row+1; i++)
{
for (int j=col-1; j<=col+1; j++)
{
if ((i!= row||j!=col) && swamp[i][j]==1)
{
if (!path.contains("["+ i +","+ j +"]"))
{
next= true;
count++;
if (count>1)
{
String pathNew = new String(path);
pathNew = pathNew+"["+ i +","+ j +"]";
pathes.add(pathNew);
}
else
{
point[0]=i;
point[1]=j;
}
}
}
}
}
count= 0;
return next;
}
}
input0.txt
10 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
input1.txt
10 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
input2.txt
9 4 4 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0
input3.txt
8 1 1 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
