Refactored main gui
This commit is contained in:
44
src/ch/bfh/sevennotseven/NextMovesCanvas.java
Normal file
44
src/ch/bfh/sevennotseven/NextMovesCanvas.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package ch.bfh.sevennotseven;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class NextMovesCanvas extends JPanel {
|
||||
private Game game;
|
||||
|
||||
static final int borderLeft = 1;
|
||||
static final int borderRight = 1;
|
||||
static final int borderTop = 1;
|
||||
static final int borderBottom = 1;
|
||||
|
||||
public NextMovesCanvas(Game g) {
|
||||
this.game = g;
|
||||
g.addUpdateListener(new Game.UpdateListener() {
|
||||
@Override
|
||||
public void gameUpdate() {
|
||||
NextMovesCanvas.this.repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
|
||||
g.setColor(Color.lightGray);
|
||||
int height = getHeight() - borderTop-borderBottom;
|
||||
|
||||
List<Integer> nextBlocks = game.getNextBlocks();
|
||||
for(int i=0; i< nextBlocks.size(); i++) {
|
||||
g.setColor(FieldCanvas.colors[nextBlocks.get(i)-1]);
|
||||
g.fillRect(borderLeft + height *i, borderTop, height,height);
|
||||
g.setColor(Color.white);
|
||||
g.drawRect(borderLeft + height *i, borderTop, height,height);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user