Skip to content
Snippets Groups Projects
Commit ff479be4 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

As a temporary workaround for rendering problems under VMware Fusion, switched...

As a temporary workaround for rendering problems under VMware Fusion, switched to the thread-unsafe usage of `paintImmediately`.
parent 6a475024
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import java.awt.Font; ...@@ -7,6 +7,7 @@ import java.awt.Font;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
...@@ -184,7 +185,8 @@ public class Tetris extends JFrame { ...@@ -184,7 +185,8 @@ public class Tetris extends JFrame {
protected void placeShape() { protected void placeShape() {
drawShape(COLORS[shape]); drawShape(COLORS[shape]);
repaint(); JPanel panel = (JPanel)getContentPane();
panel.paintImmediately(0, 0, panel.getWidth(), panel.getHeight());
} }
protected void unplaceShape() { protected void unplaceShape() {
...@@ -271,13 +273,18 @@ public class Tetris extends JFrame { ...@@ -271,13 +273,18 @@ public class Tetris extends JFrame {
maybeAdjustShape(0, 1, 0); maybeAdjustShape(0, 1, 0);
} }
public Tetris(int width, int height) {
super("Tetris");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(width, height);
setContentPane(new JPanel() {
@Override @Override
public void paint(Graphics graphics) { public void paint(Graphics graphics) {
super.paint(graphics); super.paint(graphics);
int xScale = getWidth() / WIDTH; int xScale = getWidth() / Tetris.WIDTH;
int yScale = getHeight() / HEIGHT; int yScale = getHeight() / Tetris.HEIGHT;
for (int x = 0; x < WIDTH; ++x) { for (int x = 0; x < Tetris.WIDTH; ++x) {
for (int y = 0; y < HEIGHT; ++y) { for (int y = 0; y < Tetris.HEIGHT; ++y) {
graphics.setColor(board[x][y]); graphics.setColor(board[x][y]);
graphics.fillRect(xScale * x, yScale * y, xScale, yScale); graphics.fillRect(xScale * x, yScale * y, xScale, yScale);
} }
...@@ -288,11 +295,7 @@ public class Tetris extends JFrame { ...@@ -288,11 +295,7 @@ public class Tetris extends JFrame {
graphics.drawString(scoreString, (getWidth() - graphics.getFontMetrics().stringWidth(scoreString)) / 2, graphics.drawString(scoreString, (getWidth() - graphics.getFontMetrics().stringWidth(scoreString)) / 2,
(getHeight() / 2 - graphics.getFontMetrics().getHeight()) / 2); (getHeight() / 2 - graphics.getFontMetrics().getHeight()) / 2);
} }
});
public Tetris(int width, int height) {
super("Tetris");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(width, height);
addKeyListener(new KeyListener() { addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) { public void keyPressed(KeyEvent event) {
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment