GameView.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package view;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.JPanel;
  8. import javax.swing.Timer;
  9. import main.Window;
  10. import control.LedHandler;
  11. public class GameView extends JPanel implements ActionListener{
  12. Timer t;
  13. Color c;
  14. String str;
  15. LedHandler led;
  16. public GameView(LedHandler led)
  17. {
  18. this.led=led;
  19. t = new Timer(1000/30, this);
  20. t.start();
  21. c = new Color(100,100,100);
  22. str = "CENTER";
  23. }
  24. public void actionPerformed(ActionEvent arg0) {
  25. repaint();
  26. }
  27. @Override
  28. public void paintComponent(Graphics g)
  29. {
  30. super.paintComponent(g);
  31. Graphics2D g2d = (Graphics2D) g;
  32. g2d.setPaint(c);
  33. g2d.fillRect(0, 0, getWidth(), getHeight());
  34. g2d.setPaint(Color.WHITE);
  35. g2d.drawString(str, 100, 100);
  36. }
  37. public void setColor(Color c)
  38. {
  39. this.c = c;
  40. if(Window.ON_RASP)
  41. {
  42. for(int i =6; i < 55; i++){
  43. led.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
  44. }
  45. led.show();
  46. }
  47. }
  48. public void setString(String str) {
  49. this.str = str;
  50. }
  51. }