You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EierUhrView.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package EierUhrKomponente;
  7. import java.awt.BasicStroke;
  8. import java.awt.Color;
  9. import java.awt.Graphics;
  10. import java.awt.Graphics2D;
  11. import java.awt.RenderingHints;
  12. import java.awt.geom.Ellipse2D;
  13. import java.util.logging.Logger;
  14. import javax.swing.JComponent;
  15. import ohmlogger.OhmLogger;
  16. /**
  17. *
  18. * @author chris
  19. */
  20. public class EierUhrView extends JComponent
  21. {
  22. private static Logger lg = OhmLogger.getLogger();
  23. private int zahl;
  24. private Ellipse2D.Float rand;
  25. private int DICKE;
  26. private BasicStroke pinsel;
  27. private EierUhr eierUhr;
  28. public EierUhrView(EierUhr eierUhr)
  29. {
  30. zahl = 99;
  31. rand = new Ellipse2D.Float();
  32. DICKE = 4;
  33. pinsel = new BasicStroke(DICKE);
  34. this.eierUhr = eierUhr;
  35. }
  36. @Override
  37. public void paintComponent(Graphics g)
  38. {
  39. super.paintComponents(g);
  40. Graphics2D g2 = (Graphics2D) g;
  41. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  42. RenderingHints.VALUE_ANTIALIAS_ON);
  43. int breite = eierUhr.getWidth() -1;
  44. int hoehe = eierUhr.getHeight() -1;
  45. int radius = -DICKE/2 + Math.min(breite, hoehe) / 2;
  46. float x = breite/2 - radius;
  47. float y = hoehe/2 - radius;
  48. rand.setFrame(x, y, 1.5*radius, 2*radius);
  49. g2.setStroke(pinsel);
  50. // g2.setPaint(eierUhr.getParent().getBackground());
  51. // g2.fill(rand);
  52. float font = (g2.getFont().getSize()*DICKE);
  53. g2.setPaint(Color.BLACK);
  54. g2.setFont(g2.getFont().deriveFont(font));
  55. g2.drawString(Integer.toString(zahl), (float) (x+radius*0.75-font/2), y+radius+font/2);
  56. g2.draw(rand);
  57. lg.info("paint" + Integer.toString(zahl));
  58. }
  59. public int getZahl()
  60. {
  61. return this.zahl;
  62. }
  63. public void setZahl(int zahl)
  64. {
  65. this.zahl = zahl;
  66. eierUhr.repaint();
  67. }
  68. }