Skip to content

Instantly share code, notes, and snippets.

@iamgreaser
Created August 21, 2011 11:41
Show Gist options
  • Save iamgreaser/1160500 to your computer and use it in GitHub Desktop.
Save iamgreaser/1160500 to your computer and use it in GitHub Desktop.
quick template for java gfx
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