DifficultyButton.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, 300, 75);
  25. g2.setColor(Color.ORANGE);
  26. // g2.drawRect(0, 0, 300, 75);
  27. // g2.drawRect(0-2, 0-2, 304, 79);
  28. g2.drawRect(0, 0, 304, 79);
  29. g2.drawRect(2, 2, 300, 75);
  30. g2.setColor(color);
  31. Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
  32. g2.setFont(textFont2);
  33. g2.drawString(str, 0+5, 0+50);
  34. g2.dispose();
  35. button.createGraphics();
  36. }
  37. public void draw(Graphics2D g2) {
  38. g2.drawImage(button, x, y, 305, 80, null);
  39. }
  40. }