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.

Gerademitsincos.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.Ellipse2D;
  17. import java.awt.geom.Line2D;
  18. import java.util.logging.Logger;
  19. import javax.swing.JComponent;
  20. /**
  21. *
  22. * @author le
  23. */
  24. public class Gerademitsincos extends JComponent implements Runnable
  25. {
  26. private Ellipse2D.Float Kreis;
  27. private Line2D.Float Gerade;
  28. private BasicStroke pinsel;
  29. private float radius;
  30. private Thread thd;
  31. private long schlafzeit;
  32. private static final float DICKE = 2f;
  33. private static Logger lg = Logger.getLogger("grafik");
  34. private static float xmittel,ymittel;
  35. private float deltax, deltay;
  36. public Gerademitsincos(long schlafzeit, int zeit)
  37. {
  38. this.schlafzeit = schlafzeit;
  39. Kreis = new Ellipse2D.Float();
  40. pinsel = new BasicStroke(DICKE);
  41. radius = 100;
  42. Gerade = new Line2D.Float();
  43. deltax = 0;
  44. deltay = 0;
  45. thd = null;
  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. Kreis.setFrame(x, y, radius*2, radius*2);
  70. Gerade.setLine(xmittel, ymittel, xmittel -deltax, ymittel -deltay);
  71. g2.setStroke(pinsel);
  72. g2.setPaint(Color.BLACK);
  73. g2.draw(Kreis);
  74. g2.draw(Gerade);
  75. }
  76. @Override
  77. public void run()
  78. {
  79. float delta = 0f;
  80. while (true)
  81. {
  82. deltax = (float) (radius * Math.sin(Math.toRadians(delta)));
  83. deltay = (float) (radius * Math.cos(Math.toRadians(delta)));
  84. delta -= 6f;
  85. System.out.println(delta);
  86. this.repaint();
  87. try
  88. {
  89. Thread.sleep(schlafzeit);
  90. }
  91. catch (InterruptedException iex)
  92. {
  93. lg.warning(iex.toString());
  94. }
  95. }
  96. }
  97. }