鉴于我有以下决赛:
private static final char CLIPPING_LOWER = 'c';
private static final char CLIPPING_UPPER = 'C';
private static final char RESET_LOWER = 'r';
private static final char RESET_UPPER = 'R';
private static final char LOAD_LOWER = 'l';
private static final char LOAD_UPPER = 'L';
private static final char QUIT_LOWER = 'q';
private static final char QUIT_UPPER = 'Q';
并考虑开关盒:
public void keyPressed(KeyEvent e)
{
char usersChoice = e.getKeyChar(); // get the user's choice
switch(usersChoice)
{
case LOAD_UPPER:
{
userPressedLoad();
break;
}
case LOAD_LOWER:
{
userPressedLoad();
break;
}
case RESET_LOWER:
{
userPressedReset();
break;
}
case RESET_UPPER:
{
userPressedReset();
break;
}
case CLIPPING_LOWER:
{
userPressedClipping();
break;
}
case CLIPPING_UPPER:
{
userPressedClipping();
break;
}
case QUIT_UPPER:
{
userPressedQuit();
break;
}
case QUIT_LOWER:
{
userPressedQuit();
break;
}
default:
break;
}
}
是否可以在一个块中(以及c
和...等)编写一个案例,而不是为一个单独的案例和另一个案例编写一个案例?C
r
R
c
C