Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FontMetrics fm = b.getFontMetrics(font1);
- b.setFont(font1);
- String s = "Level 1";
- int panelHeight= 90;
- int panelWidth = 540;
- java.awt.geom.Rectangle2D rect = fm.getStringBounds(s, b);
- int textHeight = (int)(rect.getHeight());
- int textWidth = (int)(rect.getWidth());
- // Center text horizontally and vertically
- int x = (panelWidth - textWidth) / 2;
- int y = (panelHeight - textHeight) / 2 + fm.getAscent();
- b.setStroke(stroke1);
- b.setColor(new Color(r,g,bb,15));
- b.fillRect(100, 100, 600, 390);
- b.fillRect(100 + 30, 100 + 30 , 540, 90);
- b.fillRect(100 + 30, 100 + 150 , 540, 90);
- b.fillRect(100 + 30, 100 + 270 , 540, 90);
- b.setColor(new Color(r,g,bb,255));
- b.drawRect(100, 100, 600, 390);
- b.drawRect(100 + 30, 100 + 30 , 540, 90);
- b.drawRect(100 + 30, 100 + 150 , 540, 90);
- b.drawRect(100 + 30, 100 + 270 , 540, 90);
- b.drawString("Level 1", x + 100 + 30, y + 100 + 30); // Draw the string.
- b.drawString("Level 2", x + 100 + 30, y + 100 + 150); // Draw the string.
- b.drawString("Level 3", x + 100 + 30, y + 100 + 270); // Draw the string.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement