当前位置:我的异常网» J2SE»关于JAVA枚举类使用的异常
关于JAVA枚举类使用的异常
网友分享于:-01-24浏览:5次
关于JAVA枚举类使用的错误
之前一直用C语言,在C语言中实现一个enum或struct很方便,而且整个工程都可以随便用。现在学习JAVA,也需要一个类似enum的枚举类型值。看到书上说,编写enum类,照着写了,可是在使用过程中报错,编译时通过了的,但是使用时就报错弹出了。工程刚开始写,只写了一下几个类:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CheckChessPieces_t.java:
publicenumCheckChessPieces_t{
DO_CHECK,NO_CHECK;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ChessPieces_t.java:
publicenumChessPieces_t{
BLACK_CHESS_PIECES,WHITE_CHESS_PIECES,EMPTY_CHESS_PIECES,DEAD_CHESS_PIECES,BOUNDARY;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ambitus.java:
//
publicclassAmbitus{
//自定义变量
//该点左侧点存在形式
privateChessPieces_tmLftPt;
//该点右侧点存在形式
privateChessPieces_tmRgtPt;
//该点上侧点存在形式
privateChessPieces_tmTopPt;
//该点下侧点存在形式
privateChessPieces_tmBtmPt;
//自定义函数
publicAmbitus(){
mLftPt=ChessPieces_t.EMPTY_CHESS_PIECES;
mRgtPt=ChessPieces_t.EMPTY_CHESS_PIECES;
mTopPt=ChessPieces_t.EMPTY_CHESS_PIECES;
mBtmPt=ChessPieces_t.EMPTY_CHESS_PIECES;
};
publicChessPieces_tgetmLftPt(){
returnmLftPt;
}
publicvoidsetmLftPt(ChessPieces_tmLftPt){
this.mLftPt=mLftPt;
}
publicChessPieces_tgetmRgtPt(){
returnmRgtPt;
}
publicvoidsetmRgtPt(ChessPieces_tmRgtPt){
this.mRgtPt=mRgtPt;
}
publicChessPieces_tgetmTopPt(){
returnmTopPt;
}
publicvoidsetmTopPt(ChessPieces_tmTopPt){
this.mTopPt=mTopPt;
}
publicChessPieces_tgetmBtmPt(){
returnmBtmPt;
}
publicvoidsetmBtmPt(ChessPieces_tmBtmPt){
this.mBtmPt=mBtmPt;
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ChessPieces.java:
publicclassChessPieces{
//自定义变量
//该点存在形式
privateChessPieces_tmLocal;
//该点四周处存在形式
privateAmbitusmAmbitus;
//该点是否是检查点
privateCheckChessPieces_tmSta;
//自定义函数
publicChessPieces(){
mLocal=ChessPieces_t.EMPTY_CHESS_PIECES;
mAmbitus=newAmbitus();
mSta=CheckChessPieces_t.NO_CHECK;
}
publicChessPieces_tgetmLocal(){
returnmLocal;
}
publicvoidsetmLocal(ChessPieces_tmLocal){
this.mLocal=mLocal;
}
publicAmbitusgetmAmbitus(){
returnmAmbitus;
}
publicvoidsetmAmbitus(AmbitusmAmbitus){
this.mAmbitus=mAmbitus;
}
publicCheckChessPieces_tgetmSta(){
returnmSta;
}
publicvoidsetmSta(CheckChessPieces_tmSta){
this.mSta=mSta;
};
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BasicChessboard.java:
publicclassBasicChessboard{
//自定义变量
privateChessPieces[]mCP;
//自定义函数
publicBasicChessboard(){
mCP=newChessPieces[100];
文章评论