Created
August 21, 2011 11:41
-
-
Save iamgreaser/1160500 to your computer and use it in GitHub Desktop.
quick template for java gfx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import javax.swing.*; | |
public class GameCanvas extends JComponent | |
{ | |
public static final int WIDTH = 640; | |
public static final int HEIGHT = 480; | |
public GameCanvas() | |
{ | |
Dimension d = new Dimension(WIDTH, HEIGHT); | |
setPreferredSize(d); | |
setMinimumSize(d); | |
setMaximumSize(d); | |
repaint(); | |
} | |
public void paintComponent(Graphics g) | |
{ | |
g.setColor(Color.BLACK); | |
g.fillRect(0, 0, getWidth(), getHeight()); | |
g.setColor(Color.RED); | |
g.fillRect(30, 40, 10, 5); | |
g.setColor(Color.WHITE); | |
g.drawString("Hello World!", 100, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment