关于JAVA枚举类使用的错误
之前一直用C语言,在C语言中实现一个enum或struct很方便,而且整个工程都可以随便用。现在学习JAVA,也需要一个类似enum的枚举类型值。看到书上说,编写enum类,照着写了,可是在使用过程中报错,编译时通过了的,但是使用时就报错弹出了。工程刚开始写,只写了一下几个类:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CheckChessPieces_t.java:
public enum CheckChessPieces_t {
DO_CHECK, NO_CHECK;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ChessPieces_t.java:
public enum ChessPieces_t {
BLACK_CHESS_PIECES, WHITE_CHESS_PIECES, EMPTY_CHESS_PIECES, DEAD_CHESS_PIECES, BOUNDARY;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ambitus.java:
//
public class Ambitus {
// 自定义变量
// 该点左侧点存在形式
private ChessPieces_t mLftPt;
// 该点右侧点存在形式
private ChessPieces_t mRgtPt;
// 该点上侧点存在形式
private ChessPieces_t mTopPt;
// 该点下侧点存在形式
private ChessPieces_t mBtmPt;
// 自定义函数
public Ambitus() {
mLftPt = ChessPieces_t.EMPTY_CHESS_PIECES;
mRgtPt = ChessPieces_t.EMPTY_CHESS_PIECES;
mTopPt = ChessPieces_t.EMPTY_CHESS_PIECES;
mBtmPt = ChessPieces_t.EMPTY_CHESS_PIECES;
};
public ChessPieces_t getmLftPt() {
return mLftPt;
}
public void setmLftPt(ChessPieces_t mLftPt) {
this.mLftPt = mLftPt;
}
public ChessPieces_t getmRgtPt() {
return mRgtPt;
}
public void setmRgtPt(ChessPieces_t mRgtPt) {
this.mRgtPt = mRgtPt;
}
public ChessPieces_t getmTopPt() {
return mTopPt;
}
public void setmTopPt(ChessPieces_t mTopPt) {
this.mTopPt = mTopPt;
}
public ChessPieces_t getmBtmPt() {
return mBtmPt;
}
public void setmBtmPt(ChessPieces_t mBtmPt) {
this.mBtmPt = mBtmPt;
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ChessPieces.java:
public class ChessPieces {
// 自定义变量
// 该点存在形式
private ChessPieces_t mLocal;
// 该点四周处存在形式
private Ambitus mAmbitus;
// 该点是否是检查点
private CheckChessPieces_t mSta;
// 自定义函数
public ChessPieces() {
mLocal = ChessPieces_t.EMPTY_CHESS_PIECES;
mAmbitus = new Ambitus();
mSta = CheckChessPieces_t.NO_CHECK;
}
public ChessPieces_t getmLocal() {
return mLocal;
}
public void setmLocal(ChessPieces_t mLocal) {
this.mLocal = mLocal;
}
public Ambitus getmAmbitus() {
return mAmbitus;
}
public void setmAmbitus(Ambitus mAmbitus) {
this.mAmbitus = mAmbitus;
}
public CheckChessPieces_t getmSta() {
return mSta;
}
public void setmSta(CheckChessPieces_t mSta) {
this.mSta = mSta;
};
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BasicChessboard.java:
public class BasicChessboard {
// 自定义变量
private ChessPieces[] mCP;
// 自定义函数
public BasicChessboard() {
mCP = new ChessPieces[100];