画光盘:
圆的平移:
运行的结果:
正弦移动:
源代码:
package MoveComponent;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class
MoveComponent extends JApplet implements Runnable{
private Thread t;
boolean dstatus=true;
public static final double PI=Math.PI/180;
Image offScreenImage=null;
Graphics offScreenBuffer=null;
int width=600;
int height=600;
double R=35;
public void init(){
t=new Thread(this);
t.start();
//创建缓冲区内的图形
offScreenImage=this.createImage(width,height);
//得到g
offScreenBuffer=offScreenImage.getGraphics();
}
public void run(){
while(true){
repaint(); //重画
}
}
public void paint(Graphics g){
//绘制的起点坐标
int
cx=240, cy=170;
//实现图形的放大与缩小
if(dstatus){
R+=1.0;
if(R>=150.0){
dstatus=false;
}
}
else{
R-=1.0;
if(R<=35.0){
dstatus=true;
}
}
offScreenBuffer.clearRect(0,0,600,600);
for(int i=0;i<=360;i++){
drawCircle(g,cx,cy,R,i);
}
}
public void drawCircle(Graphics g,double x,double y,double R,double a){
double x1,y1,x2,y2;
x1=x+R*Math.cos(a*PI);
y1=y+R*Math.sin(a*PI);
x2=x+R*Math.cos((a+1)*PI);
y2=y+R*Math.sin((a+1)*PI);
g.setColor(Color.blue);
g.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
}
}
运行的结果:

不断变大缩小的圆环:
源代码:
package MoveComponent;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class
MoveComponent extends JApplet implements Runnable{
private Thread t;
boolean dstatus=true;
public static final double PI=Math.PI/180;
Image offScreenImage=null;
Graphics offScreenBuffer=null;
int width=600;
int height=600;
double R=35;
public void init(){
t=new Thread(this);
t.start();
offScreenImage=this.createImage(width,height);
offScreenBuffer=offScreenImage.getGraphics();
}
public void run(){
while(true){
repaint();
}
}
public void paint(Graphics g){
int
cx=220, cy=170;
if(dstatus){
R+=1.0;
if(R>=130.0){
dstatus=false;
}
g.drawImage(offScreenImage,0,0,this);
}
else{
R-=1.0;
if(R<=1.0){
dstatus=true;
}
g.drawImage(offScreenImage,0,0,this);
}
offScreenBuffer.clearRect(0,0,600,600);
for(int i=0;i<=360;i++){
drawCircle(g,cx,cy,R,i);
}
}
public void drawCircle(Graphics g,double x,double y,double R,double a){
double x1,y1,x2,y2;
x1=x+R*Math.cos(a*PI);
y1=y+R*Math.sin(a*PI);
x2=x+R*Math.cos((a+1)*PI);
y2=y+R*Math.sin((a+1)*PI);
g.setColor(Color.blue);
g.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
}
}
运行的结果:

源代码:
package MoveComponent;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class
MoveComponent extends JApplet implements Runnable{
private Thread t;
boolean dstatus=true;
public static final double PI=Math.PI/180;
Image offScreenImage=null;
Graphics offScreenBuffer=null;
int width=600;
int height=600;
double R=35;
int
cx=30, cy=70;
public void init(){
t=new Thread(this);
t.start();
offScreenImage=this.createImage(width,height);
offScreenBuffer=offScreenImage.getGraphics();
}
public void run(){
while(true){
repaint();
}
}
public void paint(Graphics g){
if(dstatus){
cx+=1;
if(cx>=250){
dstatus=false;
}
g.drawImage(offScreenImage,0,0,this);
}
else{
cx-=1;
if(cx<=30){
dstatus=true;
}
g.drawImage(offScreenImage,0,0,this);
}
offScreenBuffer.clearRect(0,0,600,600);
drawCircle(g,cx,cy);
}
public void drawCircle(Graphics g,double x,double y){
g.setColor(Color.blue);
g.drawOval((int)x, (int)y, (int)50, (int)50);
}
}

源代码:
package MoveComponent;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class
MoveComponent extends JApplet implements Runnable{
private Thread t;
boolean dstatus=true;
public static final double PI=Math.PI/180;
Image offScreenImage=null;
Graphics offScreenBuffer=null;
int width=600;
int height=600;
double h=50;
double
cx=30, cy;
public void init(){
t=new Thread(this);
t.start();
offScreenImage=this.createImage(width,height);
offScreenBuffer=offScreenImage.getGraphics();
}
public void run(){
while(true){
repaint();
}
}
public void paint(Graphics g){
if(dstatus){
cx+=0.1;
cy=90-h*Math.sin((cx-30)*PI);
if(cx>=390){
dstatus=false;
}
g.drawImage(offScreenImage,0,0,this);
}
else{
cx-=0.1;
cy=90-h*Math.sin((cx-30)*PI);
if(cx<=30){
dstatus=true;
}
g.drawImage(offScreenImage,0,0,this);
}
drawCircle(g,cx,cy);
}
public void drawCircle(Graphics g,double x,double y){
g.setColor(Color.blue);
g.fillOval((int)x, (int)y, (int)20, (int)20);
}
}
运行的结果:
