java程序:编写一个程序,让一个小球在JFrame中滚动,当碰边缘时则选择一个角度返回.

来源:百度知道 编辑:UC知道 时间:2024/06/02 02:29:33

05年写的,你修改一下吧

/*
* 一个在窗体中来回运动的圆.java
*
* Created on 2005年10月5日, 下午1:02
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/

package javaapplication1;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.applet.*;
import java.awt.*;
import java.math.*;
/**
*
* @author Bachelorlrz
*/
public class 在窗体中来回运动的圆 extends java.applet.Applet implements java.lang.Runnable {
int cx,cy,c1x,c1y; //圆的坐标
int cw,ch; //圆的宽高
int bx,by,bw,bh; //背景的坐标和宽高
int dx,dx1; //圆的运动
int r,rx,ry; //圆的半径和位置
int r1,r1x,r1y;
Thread u_thread;