I am trying to create an easy swing program, but have run into some issues. I have a for loop that displays images based on an array of case numbers. Either way, each time it ends up on case 4 (which displays instructions) I need the program to stop and wait for the user to hit 'space' before it moves on. I have tried to figure this out, but I am stuck.. appreciate any guidance..
for(int i = 0;i <= displayIndex.length;i++){
//reset to zero each time so we can get the first input from the user
keyInputCount = 0;
if(indexNumber == displayIndex.length){
CSVData.updateAll(Data.getDataList());
JOptionPane.showMessageDialog(
null,
"ALL DONE",
"TASK FINISHED",
JOptionPane.OK_OPTION);
setVisible(false);
dispose();
}
//start count for response time
start = System.currentTimeMillis();
switch(displayIndex[indexNumber]) {
case 0:
middle.setText(null);
right.setIcon(heart);
left.setIcon(null);
inputCount = inputCount + 2;
try {
Thread.sleep(DISPLAY_TIME);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
break;
case 1:
middle.setText(null);
right.setIcon(null);
left.setIcon(heart);
inputCount = inputCount + 2;
try {
Thread.sleep(DISPLAY_TIME);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
break;
case 2:
right.setIcon(flower);
left.setIcon(null);
inputCount = inputCount + 2;
try {
Thread.sleep(DISPLAY_TIME);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
break;
case 3:
right.setIcon(null);
left.setIcon(flower);
inputCount = inputCount + 2;
try {
Thread.sleep(DISPLAY_TIME);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
break;
case 4:
//need to wait for user input (space bar) to move on
right.setIcon(null);
left.setIcon(null);
middle.setText(HeartsFlowersInst.getInstructions().get(instIndex));
instIndex++;
addKeyListener(
new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
middle.setText(null);
}
}
});
break;
}
indexNumber++;
right.setIcon(null);
left.setIcon(null);
middle.setText("+");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}

New Topic/Question
Reply




MultiQuote








|