谁有实现棋盘的代码给我发过来 跪求 我的东西有点问题运行不出来 谁帮我看看
第一个java类:Chessboard.javapackage edu.liubaowen.LifeGame;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class Chessboard extends View
{
private final Paint paint = new Paint();
private int maxX;
private int pointSize=20;
private int maxY;
private int xOffset;
private int yOffset;
public Chessboard(Context context)
{
super(context);
setFocusable(true);
paint.setColor(Color.LTGRAY);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
maxX = (int) Math.floor(w / pointSize);
maxY = (int) Math.floor(h / pointSize);
//设置X、Y座标微调值,目的整个框居中
xOffset = ((w - (pointSize * maxX)) / 2);
yOffset = ((h - (pointSize * maxY)) / 2);
//创建棋盘上的线条
createLines();
//初始化棋盘上所有空白点
}
private void createLines()
{
for (int i = 0; i <= maxX; i++) {//竖线
lines.add(new Line(xOffset+i*pointSize-pointSize/2, yOffset, xOffset+i*pointSize-pointSize/2, yOffset+maxY*pointSize));
}
for (int i = 0; i <= maxY; i++) {//横线
lines.add(new Line(xOffset, yOffset+i*pointSize-pointSize/2, xOffset+maxX*pointSize, yOffset+i*pointSize-pointSize/2));
}
}
private List<Line> lines = new ArrayList<Line>();
private void drawChssboardLines(Canvas canvas)
{
for (Line line : lines)
{
canvas.drawLine(line.xStart, line.yStart, line.xStop, line.yStop, paint);
}
}
//线类
class Line
{
float xStart,yStart,xStop,yStop;
public Line(float xStart, float yStart, float xStop, float yStop)
{
this.xStart = xStart;
this.yStart = yStart;
this.xStop = xStop;
this.yStop = yStop;
}
}
}
第二个java类:LifeGame.java
package edu.liubaowen.LifeGame;
import android.app.Activity;
import android.os.Bundle;
public class LifeGame extends Activity {
/** Called when the activity is first created. */
private Chessboard gameView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gameView = (Chessboard) findViewById(R.id.snake);
}
}
布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white">
<edu.liubaowen.LifeGame.Chessboard android:layout_width="fill_parent" android:id="@+id/snake" android:layout_height="fill_parent"></edu.liubaowen.LifeGame.Chessboard>
</FrameLayout>
3.
补充:移动开发 , Android