fork download
  1. import java.applet.Applet;
  2. import java.awt.Graphics;
  3. import java.awt.Color;
  4. import java.awt.Image;
  5. import java.awt.Dimension;
  6.  
  7. /* <applet code="houbutsu.class" width="800" height="500"></applet> */
  8.  
  9. public class houbutsu extends Applet implements Runnable {
  10. final static double grav = 9.81; // 重力加速度
  11. final static double x_start = 20.0; // スタート位置 x
  12. final static double y_start = 220.0; // スタート位置 y
  13. final static double vx_start = 50.0; // 初速 x
  14. final static double vy_start = 30.0; // 初速 y
  15. final static double delta = 0.12; // 時間間隔(調整可能)
  16. final static int hosei = 30;
  17. final static int speed = 100; // 画面表示のスピード(調整可能)
  18.  
  19. double x, y, prev1_x, prev1_y, prev2_x, prev2_y, stop_y;
  20. double t;
  21. double dim_y;
  22.  
  23. Thread th;
  24. Image buff;
  25. Dimension dim;
  26.  
  27. public void init() {
  28. t = 0.0;
  29.  
  30. th = new Thread(this);
  31. th.start();
  32. dim = getSize();
  33. buff = createImage(dim.width, dim.height);
  34. dim_y = (double)dim.height;
  35. }
  36.  
  37. public void run() {
  38. try {
  39. while (true) {
  40.  
  41. /* 描画関係 */
  42. prev2_x = prev1_x;
  43. prev2_y = prev1_y;
  44. prev1_x = x;
  45. prev1_y = y;
  46.  
  47. /* 以下、運動の記述 */
  48. x = x_start + t * vx_start;
  49. y = dim_y - (stop_y = y_start + t * vy_start - 0.5 * grav * t * t) - hosei;
  50. t += delta;
  51.  
  52. /* 停止条件 */
  53. if (stop_y < 0)
  54. break;
  55.  
  56. repaint();
  57. Thread.sleep(speed);
  58. }
  59. } catch (InterruptedException e) { };
  60. }
  61.  
  62.  
  63. public void update(Graphics g) {
  64. paint(g);
  65. }
  66.  
  67. public void paint(Graphics g) {
  68. if (ct == null) ct = buff.getGraphics();
  69. ct.setColor(Color.white);
  70. ct.fillRect((int)prev2_x, (int)prev2_y, 20, 20);
  71. ct.fillRect((int)prev1_x, (int)prev1_y, 20, 20);
  72. // ct.fillRect(0, 0, dim.width, dim.height);
  73. ct.setColor(Color.red);
  74. ct.fillOval((int)x, (int)y, 20, 20);
  75. g.drawImage(buff, 0, 0, this);
  76. }
  77. }
  78. /* end */
  79.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: class houbutsu is public, should be declared in a file named houbutsu.java
public class houbutsu extends Applet implements Runnable {
       ^
1 error
stdout
Standard output is empty