(1)图画:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class Game extends Applet {
private int xpos=100,ypos=0;
private SquareShape currShape;
private Image bu%er;//画布对象
private Graphics bg;
//private Image image;
public void init() {
bu%er=this.createImage(200,400);//创建画布大小
bg=bu%er.getGraphics();
bg.+llRect(0,0,200,400);
currShape=new Ding();
currShape.setPlace(xpos,ypos);
//image=new ImageIcon("01.jpg").getImage();
}
public void paint(Graphics g) {//图画由两部分组成,一部分为背景,另一部分为图形
g.drawImage(bu%er,0,0,null);//背景
//g.drawImage(image,0,0);
currShape.drawShape(g);//图形
}
}
(2)位置:
import java.awt.*;
//是所有图形的基类
abstract class SquareShape
{
private int rotateFlag=0;//旋转到第几下
protected int position[][]=new int[4][2];//每个图形由四个方格所组成
protected int xpos=100,ypos=0;//基点的位置,默认时其位置为第一行的中间
protected Color color;//画方格的颜色
public SquareShape()
{
defaultRotate();
}
//设置图形的位置
public void setPlace(int x,int y)
{
xpos=x;
ypos=y;
switch(rotateFlag)
评论1