HighscoreLetter.java 717 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package model.objects.highscore;
  2. import java.awt.Graphics2D;
  3. public class HighscoreLetter {
  4. public static int charLength = 46;
  5. private char[] letters;
  6. private int x,y,index = 0;
  7. public HighscoreLetter(char[] letters, int x, int y) {
  8. super();
  9. this.letters = letters;
  10. this.x = x;
  11. this.y = y;
  12. }
  13. public void draw(Graphics2D g2){
  14. charLength = g2.getFontMetrics().stringWidth(letters[index]+"");
  15. g2.drawString(letters[index]+"", x, y);
  16. g2.drawLine(x, y, x+charLength, y);
  17. }
  18. public void up(){
  19. index++;
  20. index %= letters.length;
  21. }
  22. public void down(){
  23. index--;
  24. if(index < 0){
  25. index = letters.length-1;
  26. }
  27. }
  28. public String getCurrentString(){
  29. return letters[index]+"";
  30. }
  31. }