DifficultyButton.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model.objects;
  2. import image.Images;
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics2D;
  6. import java.awt.Transparency;
  7. import java.awt.image.VolatileImage;
  8. public class DifficultyButton {
  9. private int x = 900;
  10. private int y;
  11. private String str;
  12. private Color color;
  13. private VolatileImage button;
  14. public DifficultyButton(int y, String str, Color color) {
  15. this.y = y;
  16. this.str = str;
  17. this.color = color;
  18. generateButton();
  19. }
  20. public void generateButton(){
  21. button = Images.initVolatileImage(305, 80, Transparency.OPAQUE);
  22. Graphics2D g2 = button.createGraphics();
  23. g2.setColor(Color.WHITE);
  24. g2.fillRect(0, 0, 305, 80);
  25. g2.setColor(Color.ORANGE);
  26. g2.drawRect(0, 0, 304, 79);
  27. g2.drawRect(2, 2, 300, 75);
  28. //g2.drawRect(0-2, 0-2, 304, 79);
  29. g2.setColor(color);
  30. Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
  31. g2.setFont(textFont2);
  32. g2.drawString(str, 0+5, 0+50);
  33. g2.dispose();
  34. button.createGraphics();
  35. }
  36. public void draw(Graphics2D g2) {
  37. g2.drawImage(button, x, y, 305, 80, null);
  38. }
  39. }