Skip to content

Instantly share code, notes, and snippets.

@erikcox
Created November 5, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikcox/11873cbef2837ac821ca to your computer and use it in GitHub Desktop.
Save erikcox/11873cbef2837ac821ca to your computer and use it in GitHub Desktop.
A grid to help line things up when using graphics in Java
// Paste inside public void paint()
g.setColor(Color.black);
g.setFont(new Font(null));
for ( int X=0; X<800; X += 50 )
g.drawString( String.valueOf(X), X, 50 );
for ( int Y=100; Y<600; Y += 50 )
g.drawString( String.valueOf(Y), 28, Y );
// lines
g.setColor(Color.lightGray);
for ( int X=0; X<800; X += 50 )
g.drawLine(X,0,X,599); // horizontal
for ( int Y=0; Y<600; Y += 50 )
g.drawLine(0,Y,799,Y); // vertical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment