I'm not even sure how to title this problem.
But basically this is a maze program, it generates a maze with specified parameters and it works pretty well for what it is. The problem is when it gets done creating the maze and setting all path tiles to white it refreshes and the grid stays there, but the path tiles disappear.
This is it when it has finished generated calling reDrawPath:
And this is it immediately after it finishes calling reDrawPath:
also not calling reDrawPath at all doesn't help, same outcome.
static final int border = 0;
static final int path = 1;
static final int wall = 2;
static final int cellSize = 15; // min 3
static final int cellSizeMask = (cellSize-1)/2;
static final int gridSizeh = 52; //grid gridSize (max 52)
static final int gridSizev = 52;
static final int choice = 1; // choice of algorithm (1-3)
public static int tx =1; //starting coords
public static int ty = 1;
public static int var;
public static int varP;
public static Point[][] cords = new Point [gridSizeh][gridSizev]; // cords for each cells
public static int tile[][] = new int [gridSizeh][gridSizev]; // if the cell will be a path, wall, or border
public static int Record[][] = new int [gridSizeh][gridSizev];
public void paint(Graphics g)
{
setCells(); //assigns starting grid values
drawGrid(g); //draws the grid
drawPath(g,tx,ty); //initial starting cord
while(var != 16) //if the maze isnt finished then keep creating it
{
Checks();
setTile(g);
}
if(var == 16) //when the maze is finished set all path cells to white and print done
{
reDrawPath(g); //redraws all path tiles to white (originally green)
System.out.println("Done");
}
}
public static void drawGrid(Graphics g) //draws grid
{
Expo.setBackground(g, Expo.gray);
for(int p = 0; p<gridSizeh; p++)
for(int k = 0; k<gridSizev; k++)
{
if(tile[p][k] == border) // If the cell is a border, set to dark red
Expo.setColor(g,Expo.darkRed);
else // if not a border set all cells to black by default
Expo.setColor(g,Expo.black);
Expo.fillRectangle(g,(int)cords[p][k].getX()-cellSizeMask,(int)cords[p][k].getY()-cellSizeMask, (int)cords[p][k].getX()+cellSizeMask, (int)cords[p][k].getY()+cellSizeMask);
}
}
public static void setCells() // set initial values for grid
{
for(int p = 0; p<gridSizeh; p++)
for(int k = 0; k<gridSizev; k++) // set all cells to walls by default
{
cords[p][k] = new Point((p+1)*cellSize,(k+1)*cellSize);
tile[p][k] = wall;
}
for(int p = 0; p<gridSizeh; p++)
for(int k = 0; k<gridSizev; k++) // if a cell is on the outer edge, set it to a border cell
{
tile[p][0] = border;
tile[p][gridSizev-1] = border;
tile[0][k] = border;
tile[gridSizeh-1][k] = border;
}
}
public static void reDrawPath(Graphics g) //set all path cells to white
{
for(int p = 1; p<gridSizeh-1; p++)
for(int k = 1; k<gridSizev-1; k++)
{
if(tile[p][k] == path)
{
drawRecursed(g, p, k);
}
Expo.delay(1);
}
}
public static void drawPath(Graphics g, int x, int y) //sets tile path and color green
{
Expo.setColor(g,Expo.green);
tile[x][y] = path;
Expo.fillRectangle(g,(int)cords[x][y].getX()-cellSizeMask,(int)cords[x][y].getY()-cellSizeMask, (int)cords[x][y].getX()+cellSizeMask, (int)cords[x][y].getY()+cellSizeMask);
}
public static void drawRecursed(Graphics g, int x, int y) // sets tile to white
{
Expo.setColor(g,Expo.white);
Expo.fillRectangle(g,(int)cords[x][y].getX()-cellSizeMask,(int)cords[x][y].getY()-cellSizeMask, (int)cords[x][y].getX()+cellSizeMask, (int)cords[x][y].getY()+cellSizeMask);
}
Related
i tried to generate bar chart from input
i would like have my code to get out put like this
enter image description here
this is my code but i have some error
i have some error in label that say should make method label and in main
can you guys help me fix this things
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
public class baronly
{
//Establish the placement of the fields for user entry
// get some error in this
Label LabelA = addLabel("A", 1,1,1,1);
IntegerField FieldA = addIntegerField(0,1,2,1,1);
Label LabelB = addLabel("B", 1,3,1,1);
IntegerField FieldB = addIntegerField(0,1,4,1,1);
Label LabelC = addLabel("C", 1,5,1,1);
IntegerField FieldC = addIntegerField(0,1,6,1,1);
Label LabelD = addLabel("D", 1,7,1,1);
IntegerField FieldD = addIntegerField(0,1,8,1,1);
Label LabelF = addLabel("F", 1,9,1,1);
IntegerField FieldF = addIntegerField(0,1,10,1,1);
//Establish a drop down menu for the drawing
//Right now we only have one choice -- Bar
//Establish variables for this program
int numberOfScores = 5;
int Xleft = 100;
int Xright = 300;
int Ytop = 100;
int Ybottom = 250; // y value entries can be up to 150
int BarWidth = 10;
int totalX , totalY;
int[ ] scores;
char graphChoice;
//Constructor to establish the initial values in the program
public baronly()
{
scores = new int[numberOfScores];
for (int i = 0; i < scores.length; i++)
scores[ i ] = 0;
totalX = Xright - Xleft + 1;
totalY = Ybottom - Ytop + 1;
}
//Allow for the menu choices
//Remember, we only have one choice right now
public void paint (Graphics g)
{
getInputData();
g.setColor (Color.red); //set color of the graph
g.drawString("Java Grades",170,290); //title
drawBarGraph(g);
}
//Get input from the screen
public void getInputData()
{
scores[0] = FieldA.getNumber();
scores[1] = FieldB.getNumber();
scores[2] = FieldC.getNumber();
scores[3] = FieldD.getNumber();
scores[4] = FieldF.getNumber();
}
//Draw the bar graph
public void drawBarGraph(Graphics g)
{
drawAxes(g);
int i, x, y, height, largestNumber, xIncrement, yIncrement;
//Compute the x and y increments
largestNumber = findLargest (scores);
xIncrement = totalX /numberOfScores;
if (largestNumber ==0)
yIncrement = 0;
else
yIncrement = totalY / largestNumber;
//Draw the bars
for(i=0; i < numberOfScores; i++)
{
x = getXCoordinate(i+1, xIncrement);
y = getYCoordinate(scores[i], yIncrement);
x = x - BarWidth / 2;
height = Ybottom - y + 1;
g.fillRect(x, y, BarWidth, height);
}
//Label x - axes with grade choices
String [ ] label = {"A", "B", "C", "D", "F"};
for(i=1; i<= numberOfScores; i++)
g.drawString(label[i-1], 100+ i*xIncrement, 270);
//Label y - axes with quantity of each grade
int topy;
if(largestNumber%10==0)
topy=largestNumber;
else
topy=(largestNumber/10+1)*10;
//i=i+5 controls y value label -- adjust for size of data
for (i=0; i<=topy; i=i+5)
{
g.drawString(String.valueOf(i), 70, Ybottom-i*yIncrement+5);
}
}
//Draw the axes for the graph
public void drawAxes (Graphics g)
{
g.drawLine(Xleft, Ytop, Xleft, Ybottom);
g.drawLine(Xleft, Ybottom, Xright, Ybottom);
}
//Determining x coordinate
public int getXCoordinate(int i, int xIncrement)
{
return Xleft + xIncrement *i;
}
//Determining y coordinate
public int getYCoordinate(int numStudents, int yIncrement)
{
return Ybottom - yIncrement * numStudents;
}
//Finding the largest value in the array
public int findLargest(int [ ] a)
{
int i;
int loc = 0;
for(i=1; i<a.length; i++)
if(a[i]>a[loc])
loc = i;
return a[loc];
}
//Main
public static void main(String[ ] args)
{
baronly frm = new baronly();
frm.setSize(400,300);
frm.setVisible(true);
}
}
that error gave says i should give method in label what that suppose to mean
I wrote the following code, but the photographs must be in the form of a matrix, not side by side.
My goal is not to leave any empty space at the end of the canvas.
import java.awt.Color;
public class aaa {
public static Color karstr ( Color x,Color y,double lambda ){
int r= (int)((1-lambda)*x.getRed()+lambda*y.getRed());
int g= (int)((1-lambda)*x.getGreen()+lambda*y.getGreen());
int b= (int)((1-lambda)*x.getBlue()+lambda*y.getBlue());
return new Color (r,g,b);
}
public static void main(String[] args) {
int genilik =50;
int ykseklik=100;
Picture p=new Picture("c:/data/a.jpg");
Picture q=new Picture("c:/data/b.jpg");
Picture r= new Picture(p.width()+400,p.height()+10);
for (int i = 0; i < p.width(); i++)
for (int j = 0; j < p.height(); j++) {
Color x=p.get(i, j);
Color y=q.get(i,j);
r.set(i*genilik/p.width(),j*ykseklik/p.height(), x);
Color c=karstr(x,y,(double)1/5);
r.set(i*genilik/p.width()+50,j*ykseklik/p.height(), c);
Color a=karstr(x,y,(double)1/4);
r.set(i*genilik/p.width()+100,j*ykseklik/p.height(),a);
Color b=karstr(x,y,(double)1/3);
r.set(i*genilik/p.width()+150,j*ykseklik/p.height(),b);
Color f=karstr(x,y,(double)1/2);
r.set(i*genilik/p.width()+200,j*ykseklik/p.height(),f);
Color g=karstr(x,y,(double)1/1.2);
r.set(i*genilik/p.width()+250,j*ykseklik/p.height(),g);
r.set(i*genilik/p.width()+300,j*ykseklik/p.height(), y);
}
r.show();
}
}
import java.awt.Color;
public class PhotoTransformation {
private Picture source;
private Picture dest;
public PhotoTransformation(Picture source, Picture dest) {
source = source;
dest = dest;
}
public static void main(String[] args) {
Picture p=new Picture("c:/data/a.jpg");
Picture q=new Picture("c:/data/b.jpg");
PhotoTransformation photoTransformation = new PhotoTransformation(p, q);
Picture[] photoSeries = photoTransformation.produceTransformationPhotos(8);
// Show the photos
}
public Picture[] produceTransformationPhotos(int transitionPhotoNumber) {
int photoNumber = transitionPhotoNumber + 2;
Picture[] photos = new Picture[photoNumber];
int width = source.width();
int height = source.height();
for (int p = 0; p < photoNumber; p++) {
Picture newPhoto = new Picture(width, height);
photos[p] = newPhoto;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Color sourceColor = source.get(i, j);
Color destColor = dest.get(i, j);
double weight = (double) p / (double) (photoNumber - 1);
Color transformationColor = produceWeightedMeanColor(sourceColor, destColor, weight);
newPhoto.set(i, j, transformationColor);
}
}
}
return photos;
}
private static Color produceWeightedMeanColor(Color x, Color y, double weight) {
int r = (int)((1-weight) * x.getRed() + weight * y.getRed());
int g = (int)((1-weight) * x.getGreen() + weight * y.getGreen());
int b = (int)((1-weight) * x.getBlue() + weight * y.getBlue());
return new Color(r,g,b);
}
}
I'm writing the drawing system for a roguelike game based on ascii characters (graphics similar to dwarf fortress). I'm using the AsciiPanel from here. My problem is that when I draw entities on my map, they seem to blink, when they should be solid.
In this gif, the r characters in the top row are the entities.
This is the map's draw method that is called every frame.
public void draw(final Display display) {
for (int x = getViewportX(); x < getViewportX() + viewportWidthInTiles; x++) {
for (int y = viewportY; y < viewportY + viewportHeightInTiles; y++) {
final char character = background[x][y].getCharacter();
final Color foreground = background[x][y].getForeground();
final Color backgroundColor = background[x][y].getBackground();
final AsciiCharacterData data = new AsciiCharacterData(
character, foreground, backgroundColor);
display.setCharacterAt(x - getViewportX(), y - viewportY,
background[x][y].getDrawingLayer(), data);
}
}
display.clearLayer(DrawingLayer.PRIMARY);
for (int i = 0; i < entities.size(); i++) {
final Entity e = entities.get(i);
final char character = e.getCharacter();
final Color foreground = e.getForeground();
final Color backgroundColor = e.getBackground();
final AsciiCharacterData data = new AsciiCharacterData(character,
foreground, backgroundColor);
display.setCharacterAt(e.getX() - getViewportX(), e.getY()
- viewportY, e.getDrawingLayer(), data);
}
}
I think I know what causes the problem, because if I write display.clearLayer(DrawingLayer.BACKGROUND); (the layer the tiles are drawn to) before I draw the background tiles, it creates something even more ridiculous.
This is the Display class, where I think I am making some mistake.
public class Display {
private static final char TRANSPARENT_CHARACTER = ' ';
private final AsciiPanel displayPanel;
private final int widthInCharacters, heightInCharacters;
private final static int Z_LEVELS = DrawingLayer.values().length;
private final AsciiCharacterData[][][] characterMap;
public Display(final AsciiPanel panel) {
displayPanel = panel;
widthInCharacters = panel.getWidthInCharacters();
heightInCharacters = panel.getHeightInCharacters();
characterMap = new AsciiCharacterData[widthInCharacters][heightInCharacters][Z_LEVELS];
for (int x = 0; x < widthInCharacters; x++) {
for (int y = 0; y < heightInCharacters; y++) {
for (int z = 0; z < Z_LEVELS; z++) {
characterMap[x][y][z] = new AsciiCharacterData(
TRANSPARENT_CHARACTER,
displayPanel.getDefaultForegroundColor(),
displayPanel.getDefaultBackgroundColor());
}
}
}
}
public void setCharacterAt(final int x, final int y, final DrawingLayer z,
final AsciiCharacterData c) {
if (x < 0 || x >= widthInCharacters || y < 0 || y >= heightInCharacters)
return;
characterMap[x][y][z.layer] = c;
// if z is not the top level
if (z.layer != Z_LEVELS - 1) {
// check all levels above
for (int i = z.layer + 1; i < Z_LEVELS; i++) {
// if there is an opaque character
if (characterMap[x][y][i].character != TRANSPARENT_CHARACTER)
// we dont need to draw anything
return;
}
}
if (c.character == TRANSPARENT_CHARACTER) {
// loop through all characters under the transparent character
for (int i = z.layer - 1; i >= 0; i--) {
// if we find a non transparent character
if (characterMap[x][y][i].character != TRANSPARENT_CHARACTER) {
// display that one instead
displayPanel.write(characterMap[x][y][i].character, x, y,
characterMap[x][y][i].foregroundColor,
characterMap[x][y][i].backgroundColor);
return;
}
}
// if there were no non trasparent characters
displayPanel.write(TRANSPARENT_CHARACTER, x, y);
// if we are a highlighter, we draw the below character and then
// just draw on top
} else {
displayPanel.write(c.character, x, y, c.foregroundColor,
c.backgroundColor);
}
displayPanel.repaint();
}
public AsciiCharacterData getCharacterAt(final int x, final int y,
final DrawingLayer z) {
return characterMap[x][y][z.layer];
}
public int getWidth() {
return widthInCharacters;
}
public int getHeight() {
return heightInCharacters;
}
public void clearLayer(final DrawingLayer layer) {
for (int x = 0; x < widthInCharacters; x++) {
for (int y = 0; y < heightInCharacters; y++) {
setCharacterAt(x, y, layer,
new AsciiCharacterData(TRANSPARENT_CHARACTER,
displayPanel.getDefaultForegroundColor(),
displayPanel.getDefaultBackgroundColor()));
}
}
}
}
Solved! It was one line in the setCharacterAt method. I was repainting every time I set a character which (while inefficient) also creates that flicker.
I've made this code that successfully creates a 16x12 grid by 50x50 squares on a 800x600px board.
As you can see, the player moves to the coordinates of the players mouseclick.
Each square of the grid has an object of Felt (field) on it, which can be laast (locked). If a fields lock attribute is set to 1, the player should not be moved to that position.
How do i detect the field a player tries to move on to achieve this?
public class SimpleGame extends BasicGame{
private Image plane;
private float planeX;
private float planeY;
public SimpleGame()
{
super("SpilTest");
}
#Override
public void init(GameContainer gc) throws SlickException {
plane = new Image("figur.png");
}
#Override
public void update(GameContainer gc, int delta) throws SlickException {
Input input = gc.getInput();
if (input.isMousePressed(input.MOUSE_LEFT_BUTTON)) {
this.planeX = input.getMouseX() - 30;
this.planeY = input.getMouseY() - 50;
}
}
public void render(GameContainer gc, Graphics g) throws SlickException {
Felt board[][] = nytGrid();
int distancex = 0;
int distancey = 0;
int counter = 0;
for (int i=0; i < board.length ; i++) {
for (int j=0; j < board[i].length ; j++) {
if (board[i][j].getLaast() == 1) {
g.setColor(Color.red);
g.fillRect(distancex, distancey, 50, 50);
}
distancex += 50;
counter++;
if (counter == 16) {
distancey += 50;
distancex = 0;
counter = 0;
}
}
}
g.drawImage(plane, planeX, planeY);
}
public static void main(String[] args) throws SlickException {
AppGameContainer app = new AppGameContainer(new SimpleGame());
app.setDisplayMode(800, 600, false);
app.setTargetFrameRate(60);
app.start();
}
public Felt[][] nytGrid() {
Felt [][] board = new Felt[16][12];
for (int i=0; i < board.length ; i++) {
for (int j=0; j < board[i].length ; j++) {
int x = i;
int y = j;
board[i][j] = new Felt(x, y);
if (i == 5 && j == 5) {
board[i][j].setLaast(1);
}
}
}
return board;
}
}
First off, you should probably initialize the board in the init() method instead of render, so it doesn't have to do it every frame, and move the declaration for the grid next to the plane, planeX and planeY declarations in the class.
Now to disable movement into a locked square, first add a method to check if a square at certain coordinates is locked, so something along the lines of:
private boolean isLocked(int x, int y) {
int square = board[x/50][y/50];
if (square == 1) return true;
else return false;
}
Next modify the part of your update() method where you update the plane coordinates, so vaguely something like:
if (input.isMousePressed(input.MOUSE_LEFT_BUTTON)) {
int destX = input.getMouseX() - 30;
int destY = input.getMouseY() - 50;
if (!isLocked(destX, destY)) {
this.planeX = destX;
this.planeY = destY;
}
}
It's easy!
int mx = Mouse.getX();
int my = Mouse.getY();
But, it gives you the world cordinates, and you have to translate it to pixels:
int mx = Mouse.getX();
int my = Mouse.getY() * -1 + (Window.WIDTH / 2) + 71;
Where do I put bounds checking so that program generates an entire maze?
The code should print a Grid with a maze drawn by breaking walls between Cells. However, much to my dismay, the Grid stops when it reaches index 0 or 24. I need the program to visit every cell before it stops (if it goes to a border, it moves back).
Here is the previous error that I'm getting:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Grid.genRand(Grid.java:73)
at Grid.main(Grid.java:35)
And here is the source code:
import java.awt.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.util.ArrayList;
public class Grid extends Canvas {
Cell[][] maze;
int size;
int pathSize;
double width, height;
ArrayList<int[]> coordinates = new ArrayList<int[]>();
public Grid(int size, int h, int w) {
this.size = size;
maze = new Cell[size][size];
for(int i = 0; i<size; i++){
for(int a =0; a<size; a++){
maze[i][a] = new Cell();
}
}
setPreferredSize(new Dimension(h, w));
}
public static void main(String[] args) {
Frame y = new Frame();
y.setLayout(new BorderLayout());
Panel r = new Panel();
r.setLayout(new BorderLayout());
Grid f = new Grid(25, 400, 400);
r.add(f, BorderLayout.CENTER);
y.add(r, BorderLayout.CENTER);
f.genRand();
f.repaint();
y.pack();
y.setPreferredSize(new Dimension(450, 450));
y.setVisible(true);
}
public void push(int[] xy){
coordinates.add(xy);
int i = coordinates.size();
coordinates.ensureCapacity(i++);
}
public int[] pop(){
int[] x = coordinates.get((coordinates.size())-1);
coordinates.remove((coordinates.size())-1);
return x;
}
public int[] top(){
return coordinates.get((coordinates.size())-1);
}
public void genRand(){
// create a CellStack (LIFO) to hold a list of cell locations [x]
// set TotalCells = number of cells in grid
int TotalCells = size*size;
// choose a cell at random and call it CurrentCell
int m = randomInt(size);
int n = randomInt(size);
while(m<1){
m = randomInt(size);
}
while(n<1){
n = randomInt(size);
}
Cell curCel = maze[m][n];
// set VisitedCells = 1
int visCel = 1;
int o = 0;
int p = 0;
int h;
int d;
int[] q;
// while VisitedCells < TotalCells
while( visCel < TotalCells){
d = 0;
// find all neighbors of CurrentCell with all walls intact
if(m!=0&&n!=0){
if(m<size&&n<size){
if(maze[m-1][n].countWalls() == 4)
{d++;}
if(maze[m+1][n].countWalls() == 4)
{d++;}
if(maze[m][n-1].countWalls() == 4)
{d++;}
if(maze[m][n+1].countWalls() == 4)
{d++;}
}
}
// if one or more found
if(d!=0){
Point[] ls = new Point[4];
ls[0] = new Point(m-1,n);
ls[1] = new Point(m+1,n);
ls[2] = new Point(m,n-1);
ls[3] = new Point(m,n+1);
// knock down the wall between it and CurrentCell
h = randomInt(3);
switch(h){
case 0: o = (int)(ls[0].getX());
p = (int)(ls[0].getY());
curCel.destroyWall(2);
maze[o][p].destroyWall(1);
break;
case 1: o = (int)(ls[1].getX());
p = (int)(ls[1].getY());
curCel.destroyWall(1);
maze[o][p].destroyWall(2);
break;
case 2: o = (int)(ls[2].getX());
p = (int)(ls[2].getY());
curCel.destroyWall(3);
maze[o][p].destroyWall(0);
break;
case 3: o = (int)(ls[3].getX());
p = (int)(ls[3].getY());
curCel.destroyWall(0);
maze[o][p].destroyWall(3);
break;
}
// push CurrentCell location on the CellStack
push(new int[] {m,n});
// make the new cell CurrentCell
m = o;
n = p;
curCel = maze[m][n];
// add 1 to VisitedCells
visCel++;
}
// else
else{
// pop the most recent cell entry off the CellStack
q = pop();
m = q[0];
n = q[1];
curCel = maze[m][n];
// make it CurrentCell
// endIf
}
// endWhile
}
}
public int randomInt(int s) { return (int)(s* Math.random());}
public void paint(Graphics g) {
int k, j;
width = getSize().width;
height = getSize().height;
double htOfRow = height / (size);
double wdOfRow = width / (size);
//checks verticals - destroys east border of cell
for (k = 0; k < size; k++) {
for (j = 0; j < size; j++) {
if(maze[k][j].checkWall(2)){
g.drawLine((int) (k * wdOfRow), (int) (j * htOfRow), (int) (k * wdOfRow), (int) ((j+1) * htOfRow));
}}
}
//checks horizontal - destroys north border of cell
for (k = 0; k < size; k++) {
for (j = 0; j < size; j++) {
if(maze[k][j].checkWall(3)){
g.drawLine((int) (k * wdOfRow), (int) (j * htOfRow), (int) ((k+1) * wdOfRow), (int) (j * htOfRow));
}}
}
}
}
class Cell {
private final static int NORTH = 0;
private final static int EAST = 1;
private final static int WEST = 2;
private final static int SOUTH = 3;
private final static int NO = 4;
private final static int START = 1;
private final static int END = 2;
boolean[] wall = new boolean[4];
boolean[] border = new boolean[4];
boolean[] backtrack = new boolean[4];
boolean[] solution = new boolean[4];
private boolean isVisited = false;
private int Key = 0;
public Cell(){
for(int i=0;i<4;i++){wall[i] = true;}
}
public int countWalls(){
int i, k =0;
for(i=0; i<4; i++) {
if (wall[i] == true)
{k++;}
}
return k;}
public boolean checkWall(int x){
switch(x){
case 0: return wall[0];
case 1: return wall[1];
case 2: return wall[2];
case 3: return wall[3];
}
return true;
}
public void destroyWall(int x){
switch(x){
case 0: wall[0] = false; break;
case 1: wall[1] = false; break;
case 2: wall[2] = false; break;
case 3: wall[3] = false; break;
}
}
public void setStart(int i){Key = i;}
public int getKey(){return Key;}
public boolean checkVisit(){return isVisited;}
public void visitCell(){isVisited = true;}
}
I overlooked you code very quickly:
you may got your exceptions while calling top() or pop() when coordinates is empty
--> coordinates.get(coordinates.size()-1) if size is 0 you try to adress index -1 -> BAM!
some methods do look very complex. you may split that functionallity in separate methods/functions
you do not mix AWT and SWING components because the do behave different
NEVER EVER do GUI stuff (showing, hiding, changing content, clicking, whatever in JFrame, JPanel etc.) out of the Event Dispatcher Thread (EDT) -> this may cause dead locks