Add UI to the project #29
No files matched your search
@@ -6,3 +6,4 @@ EEEWWWWW
|
||||
EWWWWAWW
|
||||
EWWEEEWW
|
||||
EEEEWWWW
|
||||
EEEEWWWW
|
||||
+2
-4
@@ -1,5 +1,5 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
import model.MazeAppModel;
|
||||
import dijkstra.*;
|
||||
import maze.*;
|
||||
import ui.*;
|
||||
@@ -18,9 +18,7 @@ public class MainTest {
|
||||
System.out.println(vertex);
|
||||
}
|
||||
|
||||
mazeTest.saveToTextFile("data/labyOutput.txt");
|
||||
|
||||
new MazeApp();
|
||||
MazeApp app = new MazeApp();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import dijkstra.VertexInterface;
|
||||
import dijkstra.Dijkstra;
|
||||
import dijkstra.Previous;
|
||||
|
||||
public class MazeAppModel extends Observable {
|
||||
|
||||
@@ -15,12 +17,13 @@ public class MazeAppModel extends Observable {
|
||||
private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
|
||||
private ArrayList<VertexInterface> boxList = maze.getVertexes();
|
||||
private Boolean modified = false;
|
||||
private ArrayList<Observer> listObserver = new ArrayList<Observer>();
|
||||
|
||||
public void setMaze(Maze maze) {
|
||||
this.maze = maze;
|
||||
modified = true;
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
notifyObservers(maze);
|
||||
}
|
||||
|
||||
public Maze getMaze() {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import dijkstra.VertexInterface;
|
||||
|
||||
public class Previous extends dijkstra.Previous {
|
||||
|
||||
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious, ArrayList<VertexInterface> shortestPath) {
|
||||
super(hashPrevious, shortestPath);
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,4 @@ public class ArrivalDrawingBox extends DrawingBox {
|
||||
public ArrivalDrawingBox(MazeApp mazeApp, Color color) {
|
||||
super(mazeApp, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void paintComponent(Graphics g) {
|
||||
|
||||
super.paintComponent(g);
|
||||
setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,4 @@ public class DepartureDrawingBox extends DrawingBox {
|
||||
public DepartureDrawingBox(MazeApp mazeApp, Color color) {
|
||||
super(mazeApp, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void paintComponent(Graphics g) {
|
||||
|
||||
super.paintComponent(g);
|
||||
setBackground(Color.GREEN);
|
||||
}
|
||||
}
|
||||
@@ -17,20 +17,23 @@ public abstract class DrawingBox extends JPanel {
|
||||
this.mazeApp = mazeApp;
|
||||
this.color = color;
|
||||
|
||||
setBackground(color);
|
||||
setPreferredSize(new Dimension(40,40));
|
||||
setBorder(BorderFactory.createLineBorder(Color.orange));
|
||||
setOpaque(true);
|
||||
setPreferredSize(new Dimension(50,50));
|
||||
setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
setBackground(color);
|
||||
}
|
||||
|
||||
public void notifyForUpdates(Object param) {
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
repaint();
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
@@ -22,57 +22,57 @@ public class DrawingPanelGrid extends JPanel {
|
||||
this.dimensionY = maze.getDimensionY();
|
||||
this.drawingBoxMatrix = new DrawingBox[dimensionX][dimensionY];
|
||||
|
||||
setLayout(new GridLayout(this.dimensionX, this.dimensionY));
|
||||
setLayout(new GridLayout(this.dimensionY, this.dimensionX)); //inverted coordinates
|
||||
initFromMaze(maze);
|
||||
|
||||
setPreferredSize(new Dimension(256, 256));
|
||||
}
|
||||
|
||||
private void initFromMaze(Maze maze) {
|
||||
|
||||
for (int i = 0; i < dimensionX; i++) {
|
||||
for (int j = 0; j < dimensionY; j++) {
|
||||
for (int i = 0; i < dimensionY; i++) {
|
||||
for (int j = 0; j < dimensionX; j++) {
|
||||
if (maze.getMaze()[j][i].isWalkable()) {
|
||||
if (maze.getMaze()[j][i].isDeparture()) {
|
||||
add(new DepartureDrawingBox(mazeApp, Color.GREEN));
|
||||
drawingBoxMatrix[j][i] = new DepartureDrawingBox(mazeApp, Color.GREEN);
|
||||
}
|
||||
else if (maze.getMaze()[j][i].isArrival()) {
|
||||
add(new ArrivalDrawingBox(mazeApp, Color.RED));
|
||||
drawingBoxMatrix[j][i] = new ArrivalDrawingBox(mazeApp, Color.RED);
|
||||
}
|
||||
else {
|
||||
add(new EmptyDrawingBox(mazeApp, Color.BLACK));
|
||||
drawingBoxMatrix[j][i] = new EmptyDrawingBox(mazeApp, Color.BLACK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
add(new WallDrawingBox(mazeApp, Color.WHITE));
|
||||
drawingBoxMatrix[j][i] = new WallDrawingBox(mazeApp, Color.WHITE);
|
||||
}
|
||||
|
||||
add(drawingBoxMatrix[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyForUpdates(Object param) {
|
||||
if (param instanceof Maze) {
|
||||
maze = (Maze) param;
|
||||
|
||||
for (int i = 0; i < dimensionX; i++) {
|
||||
for (int j = 0; j < dimensionY; j++) {
|
||||
for (int j = 0; j < dimensionX; j++) {
|
||||
for (int i = 0; i < dimensionY; i++) {
|
||||
if (maze.getMaze()[j][i].isWalkable()) {
|
||||
if (maze.getMaze()[j][i].isDeparture()) {
|
||||
drawingBoxMatrix[j][i].notifyForUpdates();
|
||||
drawingBoxMatrix[j][i].setColor(Color.GREEN);
|
||||
}
|
||||
else if (maze.getMaze()[j][i].isArrival()) {
|
||||
drawingBoxMatrix[j][i].notifyForUpdates();
|
||||
drawingBoxMatrix[j][i].setColor(Color.RED);
|
||||
}
|
||||
else {
|
||||
drawingBoxMatrix[j][i].notifyForUpdates();
|
||||
drawingBoxMatrix[j][i].setColor(Color.BLACK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawingBoxMatrix[j][i].notifyForUpdates();
|
||||
drawingBoxMatrix[j][i].setColor(Color.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,4 @@ public class EmptyDrawingBox extends DrawingBox {
|
||||
public EmptyDrawingBox(MazeApp mazeApp, Color color) {
|
||||
super(mazeApp, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void paintComponent(Graphics g) {
|
||||
|
||||
super.paintComponent(g);
|
||||
setBackground(Color.WHITE);
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -12,12 +12,15 @@ public class MazeApp extends JFrame
|
||||
|
||||
private final MazeMenuBar mazeMenuBar;
|
||||
private final WindowPanel windowPanel;
|
||||
private MazeAppModel mazeAppModel = new MazeAppModel();
|
||||
private MazeAppModel mazeAppModel;
|
||||
|
||||
public MazeApp() {
|
||||
|
||||
super("Maze Solving Application");
|
||||
|
||||
this.mazeAppModel = new MazeAppModel();
|
||||
mazeAppModel.addObserver(this);
|
||||
|
||||
setJMenuBar(mazeMenuBar = new MazeMenuBar(this));
|
||||
setContentPane(windowPanel = new WindowPanel(this));
|
||||
|
||||
@@ -34,6 +37,7 @@ public class MazeApp extends JFrame
|
||||
@Override
|
||||
public void update(Observable obs, Object param) {
|
||||
|
||||
System.out.println("New maze detected");
|
||||
windowPanel.notifyForUpdates(param);
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,4 @@ public class WallDrawingBox extends DrawingBox {
|
||||
public WallDrawingBox(MazeApp mazeApp, Color color) {
|
||||
super(mazeApp, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void paintComponent(Graphics g) {
|
||||
|
||||
super.paintComponent(g);
|
||||
setBackground(Color.BLACK);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ public class WindowPanel extends JPanel
|
||||
}
|
||||
|
||||
public void notifyForUpdates(Object param) {
|
||||
|
||||
drawingPanelGrid.notifyForUpdates(param);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user