thread-sleep

How to create a delay in Swing

大兔子大兔子 提交于 2019-11-26 11:38:37
问题 I made a blackjack game, and I want the AI player to pause between taking cards. I tried simply using Thread.sleep(x), but that makes it freeze until the AI player is done taking all of his cards. I know that Swing is not thread safe, so I looked at Timers, but I could not understand how I could use one for this. Here is my current code: while (JB.total < 21) { try { Thread.sleep(1000); } catch (InterruptedException ex) { System.out.println(\"Oh noes!\"); } switch (getJBTable(JB.total, JB

How JavaFX application thread works?

浪尽此生 提交于 2019-11-26 10:02:14
问题 I have a problem with Java FX application thread. Here is a pseudo-code: showMenu(); //Contoller which waits for action(pressing button)... showLoadingPic(); Thread.sleep(2000); showMap(); The problem is that the sleep occurs in window which is displayed in showMenu(), showLoadingPic() is not shown at all, and at the end window in showMap() is shown. The scene in showLoadingPic has a progress bar which runs 2 secs which is the same time as Thread.sleep(2000). So it seems like javafx

Swing - Thread.sleep() stop JTextField.setText() working [duplicate]

故事扮演 提交于 2019-11-26 06:48:49
问题 Possible Duplicate: using sleep() for a single thread I\'m having issues with JTextField.setText() when using Thread.sleep(). This is for a basic calculator I\'m making. When the input in the input field is not of the correct format I want \"INPUT ERROR\" to appear in the output field for 5 seconds and then for it to be cleared. The setText() method did work when I just set the text once to \"INPUT ERROR\" and by printing out the text in between I found it does work with both that and the

Thread.Sleep() without freezing the UI

夙愿已清 提交于 2019-11-26 06:08:19
问题 First off, I am a beginner in C# and I would like to make this: class2.method_79(null, RoomItem_0, num, num2, 0, false, true, true); System.Threading.Thread.Sleep(250); class2.method_79(null, RoomItem_0, num, num4, 0, false, true, true); System.Threading.Thread.Sleep(300); class2.method_79(null, RoomItem_0, num, num6, 0, false, true, true); But this solution freezes the UI, how could I make the second event occur 250ms after the first etc without freezing the UI? 回答1: The simplest way to use

How to put delay before doing an operation in WPF

心已入冬 提交于 2019-11-26 03:58:20
问题 I tried to use the below code to make a 2 second delay before navigating to the next window. But the thread is invoking first and the textblock gets displayed for a microsecond and landed into the next page. I heard a dispatcher would do that. Here is my snippet: tbkLabel.Text = \"two mins delay\"; Thread.Sleep(2000); Page2 _page2 = new Page2(); _page2.Show(); 回答1: The call to Thread.Sleep is blocking the UI thread. You need to wait asynchronously. Method 1: use a DispatcherTimer tbkLabel

using sleep() for a single thread

两盒软妹~` 提交于 2019-11-26 01:47:47
问题 I am fairly new to java, and am starting to get into using different threads in order to use wait() or sleep() on one part of my code and have the others still run. For this project, I am using JFrame with the javax.swing.* and java.awt.* imports. What I am trying to do is have one of the threads (in my code it is the main, starting thread) allow the player to choose a space on the tic tac toe board, and when they click it, it will change icons, and then the AI will wait for 1 second before

using sleep() for a single thread

别说谁变了你拦得住时间么 提交于 2019-11-25 22:51:20
I am fairly new to java, and am starting to get into using different threads in order to use wait() or sleep() on one part of my code and have the others still run. For this project, I am using JFrame with the javax.swing.* and java.awt.* imports. What I am trying to do is have one of the threads (in my code it is the main, starting thread) allow the player to choose a space on the tic tac toe board, and when they click it, it will change icons, and then the AI will wait for 1 second before playing back from the second thread that I created. Unfortunately, whenever I call ait.sleep(1000) ( ait