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.

Gerade.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 grafik2d;
  7. /**
  8. *
  9. * @author nobody
  10. */
  11. import java.awt.BasicStroke;
  12. import java.awt.Color;
  13. import java.awt.Graphics;
  14. import java.awt.Graphics2D;
  15. import java.awt.RenderingHints;
  16. import java.awt.geom.AffineTransform;
  17. import java.awt.geom.Ellipse2D;
  18. import java.awt.geom.Line2D;
  19. import java.util.logging.Logger;
  20. import javax.swing.JComponent;
  21. /**
  22. *
  23. * @author le
  24. */
  25. public class Gerade extends JComponent implements Runnable
  26. {
  27. private Ellipse2D.Float Kreis;
  28. private Line2D.Float Gerade;
  29. private BasicStroke pinsel;
  30. private float radius;
  31. private Thread thd;
  32. private long schlafzeit;
  33. private static final float DICKE = 2f;
  34. private static Logger lg = Logger.getLogger("grafik");
  35. private static float xmittel,ymittel;
  36. private AffineTransform at;
  37. public Gerade(long schlafzeit, int zeit)
  38. {
  39. this.schlafzeit = schlafzeit;
  40. Kreis = new Ellipse2D.Float();
  41. pinsel = new BasicStroke(DICKE);
  42. radius = 100;
  43. Gerade = new Line2D.Float();
  44. thd = null;
  45. this.at = new AffineTransform();
  46. }
  47. public void start()
  48. {
  49. if (thd == null)
  50. {
  51. thd = new Thread(this);
  52. thd.start();
  53. }
  54. }
  55. @Override
  56. public void paintComponent(Graphics g)
  57. {
  58. super.paintComponent(g);
  59. Graphics2D g2 = (Graphics2D)g;
  60. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  61. RenderingHints.VALUE_ANTIALIAS_ON);
  62. int breite = this.getWidth() - 1;
  63. int hoehe = this.getHeight() - 1;
  64. //maxRadius = -DICKE/2f + Math.min(breite/2f, hoehe/2f);
  65. float x = breite/2f - radius;
  66. float y = hoehe/2f - radius;
  67. xmittel = x+radius;
  68. ymittel = y+radius;
  69. g2.setTransform(this.at);
  70. Kreis.setFrame(x, y, radius*2, radius*2);
  71. Gerade.setLine(xmittel, ymittel, xmittel -radius, ymittel);
  72. g2.setStroke(pinsel);
  73. g2.setPaint(Color.BLACK);
  74. g2.draw(Kreis);
  75. g2.draw(Gerade);
  76. }
  77. @Override
  78. public void run()
  79. {
  80. float delta = 0f;
  81. while (true)
  82. {
  83. this.at.rotate(Math.toRadians(0.06),xmittel, ymittel);
  84. System.out.println(delta);
  85. this.repaint();
  86. try
  87. {
  88. Thread.sleep(schlafzeit);
  89. }
  90. catch (InterruptedException iex)
  91. {
  92. lg.warning(iex.toString());
  93. }
  94. }
  95. }
  96. }