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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 grafik;
  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.awt.geom.Line2D;
  14. import java.util.logging.Logger;
  15. import javax.swing.JComponent;
  16. /**
  17. *
  18. * @author le
  19. */
  20. public class Gerade extends JComponent implements Runnable
  21. {
  22. private Line2D.Double line;
  23. private BasicStroke pinsel;
  24. private float angle;
  25. private float radius;
  26. private Thread thd;
  27. private long sleepTime;
  28. private static final float DICKE = 8f;
  29. private static Logger lg = Logger.getLogger("grafik");
  30. public Gerade(long sleepTime)
  31. {
  32. this.sleepTime = sleepTime;
  33. line = new Line2D.Double();
  34. angle = 0;
  35. radius = 100;
  36. pinsel = new BasicStroke(DICKE);
  37. thd = null;
  38. }
  39. public void start()
  40. {
  41. if (thd == null)
  42. {
  43. thd = new Thread(this);
  44. thd.start();
  45. }
  46. }
  47. @Override
  48. public void paintComponent(Graphics g)
  49. {
  50. super.paintComponent(g);
  51. Graphics2D g2 = (Graphics2D)g;
  52. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  53. RenderingHints.VALUE_ANTIALIAS_ON);
  54. int breite = this.getWidth() - 1;
  55. int hoehe = this.getHeight() - 1;
  56. float x1 = breite/2f;
  57. float y1 = hoehe/2f;
  58. float x2 = (float) Math.sin(angle);
  59. float y2 = 2;
  60. line.setLine(x1, y1, x2, y2);
  61. g2.setStroke(pinsel);
  62. g2.setPaint(Color.RED);
  63. g2.fill(line);
  64. g2.setPaint(Color.BLACK);
  65. g2.draw(line);
  66. }
  67. @Override
  68. public void run()
  69. {
  70. while (true)
  71. {
  72. if(angle >= 360){
  73. angle = 0;
  74. } else {
  75. angle += 1;
  76. }
  77. // if (radius > maxRadius) delta = -1f;
  78. // if (radius < minRadius) delta = +1f;
  79. // radius += delta;
  80. this.repaint();
  81. try
  82. {
  83. Thread.sleep(sleepTime);
  84. }
  85. catch (InterruptedException iex)
  86. {
  87. lg.warning(iex.toString());
  88. }
  89. }
  90. }
  91. }