Question about Java Enums

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
sgalland
Posts: 5
Joined: Fri Dec 08, 2006 3:32 am

Question about Java Enums

Post by sgalland »

I might be doing this wrong, but I am trying to enumate all the graphics mechanisms in Java with the enum operator:

enum GRAPHIC_MODES {
NULL=E_DRIVER_TYPE.EDT_NULL,
SOFTWARE=E_DRIVER_TYPE.EDT_SOFTWARE, OPENGL=E_DRIVER_TYPE.EDT_OPENGL, DX8=E_DRIVER_TYPE.EDT_DIRECTX8, DX9=E_DRIVER_TYPE.EDT_DIRECTX9 }

When compiling I keep getting error thats I am missing a brace and every enum example I see doesn't have a terminating operator and I am probably doing this all wrong. Any help is appreciated.
inno
Posts: 1
Joined: Fri Dec 08, 2006 9:02 am

Post by inno »

You can not do what you want with enums in Java.

enums are used for enumnarations(like the name Say) but imho intern they are alway count from zero.

public enum MyEnum
{
zero, one, two, three

}

public enum MyEnum2
{
green, red, blue

}

Internaly:

green = 0
red = 1
blue = 2

You could write a enum and a class that will do this

something like...

public enum GRAPHIC_MODES
{
NULL ,
SOFTWARE,
OPENGL,
DX8,
DX9
}

public class MyGRAPHIC_MODES
{

public static Object getMode(GRAPHIC_MODES mode)
{
Object retObj = null;

switch(mode)
{

case GRAPHIC_MODES.NULL:
retObj = E_DRIVER_TYPE.EDT_NULL;
break;

case GRAPHIC_MODES.SOFTWARE:
retObj = E_DRIVER_TYPE.EDT_SOFTWARE;
break;

case GRAPHIC_MODES.OPENGL
retObj = E_DRIVER_TYPE.EDT_OPENGL;
break;

case GRAPHIC_MODES.DX8:
retObj = E_DRIVER_TYPE.EDT_DIRECTX8;
break;

case GRAPHIC_MODES.DX9:
retObj = E_DRIVER_TYPE.EDT_DIRECTX9 ;
break;

return retObj;
}


then you can get your mode with
... = MyGRAPHIC_MODES.getMode(GRAPHIC_MODES.DX8);
sgalland
Posts: 5
Joined: Fri Dec 08, 2006 3:32 am

Post by sgalland »

Thanks for the reply, I had a sneaking feeling that I can't treat Java like C++ (or at least I seen a similar example in C++) :o
Post Reply