Here is the image of my application:
When the new button is pressed the question will be displayed and timer starts.
But after the 'New' button is pressed neither timer runs nor text is displayed and the default close operation does not work. When i comment out the checkTimer() then it is working fine.
Here is the code:
if(buttonEvent.getActionCommand().equals("New")){
String store = buttonEvent.getActionCommand();
startGame();
checkTimer();
panelOne.remove(buttonNew);
panelOne.revalidate();
panelOne.repaint();
}
public void startGame(){
// TODO Auto-generated method stub
String line = null;
try{
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\myPc\\Documents\\myFile.txt"));
while((line = reader.readLine()) != null){
System.out.println(line);
queue.add(line);
}
reader.close();
}
catch(IOException exception){
exception.printStackTrace();
}
// flag = true;
String display = queue.remove();
textArea.setText(display);
//checkTimer();
}
public void checkTimer() {
// TODO Auto-generated method stub
int sec = 59;
int min = Integer.parseInt(timerField1.getText());
while(min >= 0){
min--;
if(min >= 0){
for(int i = 0; i < 60; i++){
try{
Thread.sleep(1000);
}
catch(InterruptedException ie){
Thread.currentThread().interrupt();
}
timerField1.setText(Integer.toString(min));
timerField2.setText(Integer.toString(sec));
if(sec > 0){
sec--;
}
else{
break;
}
}
}
//textArea1.setText(Integer.toString(num));
sec = 59;
}
}
Please guide me that why its not working.