У меня есть следующий код, который запускается всякий раз, когда вы нажимаете кнопку «Пуск» в моей программе.Я обозначил в комментариях, где я хочу, чтобы таймер ушел, проблема в том, что когда я делаю thread.sleep(time)
, это останавливает мою программу!Итак, мне было интересно, может ли кто-нибудь просто добавить atimer в мой код, чтобы он запускал первый бит, ждал, а затем запускал его снова на основе bumpNum.
Code:
public class startReplyButtonListener implements ActionListener{
public void actionPerformed(ActionEvent ev){
int length = textAreaReplyMessage.getText().length();
int remLen = 400 - length;
String strHTML = neo.get("http://www.neopets.com/neoboards/topic.phtml?topic=" + txtTopicID.getText());
/*strHTML = neo.post("/neoboards/process_topic.phtml?", new String[][] {{"boardType", "topic_id", "board_id", "message", "next", "remLen"}, {"reply", txtTopicID.getText(), "4", textAreaReplyMessage.getText() , "1", ((Integer)remLen).toString()}});
if(strHTML.contains("No topic with ID")){
txtLog.append("Invalid Topic ID! \n");
}
else{
txtLog.append("Bumped Topic ID " + txtTopicID.getText() + "\n");
}
*/
System.out.println(strHTML);
bumpNum = 5;
wait = Integer.parseInt(textWait1.getText()) * 1000; //converting to miliseconds
int i=1;
do{
strHTML = neo.post("/neoboards/process_topic.phtml?", new String[][] {{"boardType", "topic_id", "board_id", "message", "next", "remLen"}, {"reply", txtTopicID.getText(), "4", textAreaReplyMessage.getText() , "1", ((Integer)remLen).toString()}});
txtLog.append("Board Bumped. Waiting "+ ((Integer)(wait/1000)).toString() +" Seconds..." + "\n");
//ADD TIMER HERE
i++;
}while(i <= bumpNum);
}
}
ЧтоЯ хочу выполнить:
Пользователь указывает, сколько раз он хочет «публиковать» (обозначается bumpNum), цикл будет сначала публиковаться один раз:
strHTML = neo.post("/neoboards/process_topic.phtml?", new String[][] {{"boardType", "topic_id", "board_id", "message", "next", "remLen"}, {"reply", txtTopicID.getText(), "4", textAreaReplyMessage.getText() , "1", ((Integer)remLen).toString()}});
Затем: на основе пользователейпосле ввода, он будет ждать сколько угодно секунд (txtWait1) и ТОГДА повторить приведенный выше код публикации до тех пор, пока он не достигнет bumpNum.
И он обновит txtLog со следующим КАКИМ ВРЕМЯМ, в течение которого он ударяет (поэтому программа не может быть заморожена)):
txtLog.append("Board Bumped. Waiting "+ ((Integer)(wait/1000)).toString() +" Seconds..." + "\n");