congdantoancau

Graphics 2D paintComponent Ruler

Apr 7th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. // PRINTING RULER
  2.         int x1, y1, x2, y2; int block = 40;
  3.         Line2D line;
  4.        
  5.         // Horizontal
  6.         x1 = y1 = 0;
  7.         x2 = 0; y2 = 5;
  8.         int center = 0;
  9.         for (int i = 0; i < 40; i++)
  10.         {
  11.             line = new Line2D.Double(x1, y1, x2, y2);
  12.             g2.draw(line);
  13.             if (i < 10)
  14.                 center = x1 - 3;
  15.             else
  16.                 center = x1 - 6;
  17.             g2.drawString(i+"", center, 20);
  18.             x1 += block;
  19.             x2 += block;
  20.         }
  21.        
  22.         // Vertical
  23.         x1 = y1 = 0;
  24.         x2 = 5; y2 = 0;
  25.         for (int i = 0; i < 20; i++)
  26.         {
  27.             line = new Line2D.Double(x1, y1, x2, y2);
  28.             g2.draw(line);
  29.             g2.drawString(i+"", 8, y1 + 5);
  30.             y1 += block;
  31.             y2 += block;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment