zoukankan      html  css  js  c++  java
  • Java_Swing实现小球沿正弦曲线运动的代码


    1
    package zuidaimapack_1; 2 import java.awt.*; 3 import javax.swing.*; 4 /** 5 *Java_Swing实现小球沿正弦曲线运动的代码 6 * @author Visec·Dana 7 */ 8 public class SinRun extends JFrame implements Runnable { 9 private static final long serialVersionUID = 1L; 10 static int i = 0; 11 static int j = 250; 12 static double x = 0; 13 static double v = 5;// 速度 14 static double w = 2 * Math.PI; 15 static double A = 50;// 振幅 16 static double t = 0;// 时间 17 18 public SinRun() { 19 this.setSize(500, 500); 20 this.setVisible(true); 21 } 22 23 public void paint(Graphics g) { 24 super.paint(g); 25 g.setColor(Color.black); 26 g.fillOval(i, j + (int) x, 10, 10); 27 } 28 public void run() { 29 while (true) { 30 try { 31 Thread.sleep(100); 32 } catch (InterruptedException e) { 33 // e.printStackTrace(); 34 } 35 i += v; 36 x = A * Math.sin(w * t); 37 t += 0.1; 38 this.repaint(); 39 if (i > 500) 40 i = 0; 41 } 42 } 43 public static void main(String args[]) { 44 new Thread(new SinRun()).start(); 45 } 46 }
  • 相关阅读:
    423. Reconstruct Original Digits from English
    400. Nth Digit
    397. Integer Replacement
    396. Rotate Function
    365. Water and Jug Problem
    335. Self Crossing
    319. Bulb Switcher
    线段树-hdu2795 Billboard(贴海报)
    线段树---求逆序数
    线段树——单点替换区间最值
  • 原文地址:https://www.cnblogs.com/visec479/p/3770376.html
Copyright © 2011-2022 走看看