Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. FontMetrics fm = b.getFontMetrics(font1);
  2. b.setFont(font1);
  3. String s = "Level 1";
  4. int panelHeight= 90;
  5. int panelWidth = 540;
  6. java.awt.geom.Rectangle2D rect = fm.getStringBounds(s, b);
  7.  
  8. int textHeight = (int)(rect.getHeight());
  9. int textWidth = (int)(rect.getWidth());
  10.  
  11. // Center text horizontally and vertically
  12. int x = (panelWidth - textWidth) / 2;
  13. int y = (panelHeight - textHeight) / 2 + fm.getAscent();
  14.  
  15.  
  16. b.setStroke(stroke1);
  17. b.setColor(new Color(r,g,bb,15));
  18. b.fillRect(100, 100, 600, 390);
  19. b.fillRect(100 + 30, 100 + 30 , 540, 90);
  20. b.fillRect(100 + 30, 100 + 150 , 540, 90);
  21. b.fillRect(100 + 30, 100 + 270 , 540, 90);
  22. b.setColor(new Color(r,g,bb,255));
  23. b.drawRect(100, 100, 600, 390);
  24. b.drawRect(100 + 30, 100 + 30 , 540, 90);
  25. b.drawRect(100 + 30, 100 + 150 , 540, 90);
  26. b.drawRect(100 + 30, 100 + 270 , 540, 90);
  27. b.drawString("Level 1", x + 100 + 30, y + 100 + 30); // Draw the string.
  28. b.drawString("Level 2", x + 100 + 30, y + 100 + 150); // Draw the string.
  29. b.drawString("Level 3", x + 100 + 30, y + 100 + 270); // Draw the string.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement