MenuButton.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package model.objects;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics2D;
  5. import java.util.ArrayList;
  6. import main.Window;
  7. import audio.Song;
  8. public class MenuButton {
  9. private ArrayList<Color> colors;
  10. private int x, y;
  11. private int xx,yy;
  12. private boolean selected;
  13. private Song song;
  14. Color color;
  15. public MenuButton(int x, int y, Color color, Song song){
  16. this.x = x;
  17. this.y = y;
  18. this.color = color;
  19. setSong(song);
  20. }
  21. public MenuButton(int x, int y, int xx, int yy, Color color, Song song){
  22. this.x = x;
  23. this.y = y;
  24. this.color = color;
  25. this.yy = yy;
  26. this.xx = xx;
  27. setSong(song);
  28. }
  29. public void draw(Graphics2D g2d){
  30. if(selected){
  31. g2d.setColor(color.darker().darker().darker().darker());
  32. g2d.fillRect(x-10, y-10,xx+20,yy+20);
  33. g2d.setColor(color.darker().darker());
  34. g2d.fillRect(x-5, y-5,xx+10,yy+10);
  35. g2d.setColor(color);
  36. g2d.fillRect(x,y,xx,yy);
  37. g2d.setColor(Color.BLACK);
  38. g2d.drawRect(x-10, y-10, xx+20, yy+20);
  39. g2d.drawRect(x-5, y-5, xx+10, yy+10);
  40. g2d.drawRect(x, y, xx, yy);
  41. }
  42. else{
  43. g2d.setColor(color.darker().darker());
  44. g2d.fillRect(x-5, y-5,990,80);
  45. g2d.setColor(color);
  46. g2d.fillRect(x,y,980,70);
  47. }
  48. //draw text
  49. g2d.setColor(Color.BLACK);
  50. Font textFont = new Font("OCR A Extended", Font.BOLD,60);
  51. g2d.setFont(textFont);
  52. if(selected)
  53. {
  54. g2d.drawString(song.getTitle(), x+50, y+63);
  55. Font textFont2 = new Font("OCR A Extended", Font.PLAIN,30);
  56. g2d.setFont(textFont2);
  57. g2d.drawString("# Played: " + song.getTimesPlayed(), Window.WIDTH - 450 - Math.min(song.getAuthor().length()*16, 570), y+yy+45);
  58. g2d.drawString("Author: " + song.getAuthor(), Window.WIDTH - 200 - Math.min(song.getAuthor().length()*16, 570) , y+yy+45);
  59. }
  60. else
  61. g2d.drawString(song.getTitle(), x+50, y+57);
  62. }
  63. public void setSelected(boolean selected) {
  64. this.selected = selected;
  65. }
  66. public boolean isSelected(){
  67. return selected;
  68. }
  69. public void setX(int x){
  70. this.x = x;
  71. }
  72. public int getX() {
  73. return x;
  74. }
  75. public Song getSong() {
  76. return song;
  77. }
  78. public void setSong(Song song) {
  79. this.song = song;
  80. }
  81. }