thread-sleep

Java Swing JButton Time Delays (Flicker)

我们两清 提交于 2020-01-19 01:54:29
问题 I am trying to make my JButton flicker red for this game I am creating. All the solutions on this website suggest using a thread and putting it to sleep or using a timer, however, the pause allays seems to come after the color change Here is my code: Color cb = board[Y1][X1].getBackground(); board[Y1][X1].setBackground(Color.RED); //Pause board[Y1][X1].setBackground(cb); If I put a thread and put it to sleep on line 3 and comment out line 4 the pause will come before the JButton is turned red

Long Running Blocking Methods. Difference between Blocking, Sleeping, Begin/End and Async

蓝咒 提交于 2020-01-13 05:06:31
问题 This question is not about designs or patterns and which to use. The heart of this question is about what is happening regarding threads and blocking. This example is to apply to any blocking method that is designed to perform the same action continuously. In this case it is a blocking read or write on a networkstream. Is there any appreciable difference behind the scenes as to threading and performance between the methods? My assumption is that each of the methods below creates a thread or

Difference between Task.Delay() and new Task(()=>Thread.Sleep())

人盡茶涼 提交于 2020-01-11 09:44:10
问题 I was putting together a small little demo to take a long running method simulated with a Thread.Sleep() and wanted to add async to easily go from a synchronous process to an async one. Here's the initial code: private void button1_Click(object sender, EventArgs e) { LongProcess(); } private void LongProcess() { for (int i = 0; i < 33; i++) { progressBar1.Value += 3; Thread.Sleep(1000); } progressBar1.Value += 1; } I was thinking I could simply change the Thread.Sleep(1000) into a new Task(()

Forcing a GUI update inside of a thread - JSlider updates

廉价感情. 提交于 2020-01-06 13:31:32
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Forcing a GUI update inside of a thread - JSlider updates

家住魔仙堡 提交于 2020-01-06 13:31:29
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Forcing a GUI update inside of a thread - JSlider updates

筅森魡賤 提交于 2020-01-06 13:31:19
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Analog Clock working but seconds repainting

浪尽此生 提交于 2020-01-05 04:25:12
问题 I made an Analog Clock and its working but when a remove the filloval (Background) the seconds hand keep repeating itself and but when i add filloval it is working. but i do not want the background there. Thanks here is the code import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import javax.swing.JFrame; import javax.swing.JPanel; public class Clock extends JPanel implements Runnable {

JavaFX pausing during for loop WITHOUT using Thread.Sleep()

对着背影说爱祢 提交于 2020-01-05 04:08:11
问题 I'm coding this in JavaFX using a FXMLController and the scene builder. I'm currently creating an Instagram "liker" mostly just for practice as I'm a Computer Science major, and I just like coding. My issue is, I have a for loop that "likes" 20 photos for each hashtag, I obviously need a delay or I'd get banned rather quickly. The user can choose the delay, then I randomize this delay so it's not too robotic. The only way I've been able to use this delay is through the thread.sleep method,

VB.net Inconsistant Thread Sleep Timer

谁说我不能喝 提交于 2020-01-04 06:08:05
问题 Ok so I have been playing with VB.net and brainstorming ways to accomplish launching a thread reliably every 60 seconds reguardless of how long the prior thread took to do it's work. Here is my question. Given the following code: Dim intTemp As Integer intTemp = 2 Do While intTemp > 1 Dim objWriter As New System.IO.StreamWriter("C:\Documents\Visual Studio 2010\Projects\Report\Report\Stream.txt", True) intTemp = intTemp + 1 System.Threading.Thread.Sleep(5000) objWriter.Write(intTemp & " " &

VB.net Inconsistant Thread Sleep Timer

与世无争的帅哥 提交于 2020-01-04 06:07:47
问题 Ok so I have been playing with VB.net and brainstorming ways to accomplish launching a thread reliably every 60 seconds reguardless of how long the prior thread took to do it's work. Here is my question. Given the following code: Dim intTemp As Integer intTemp = 2 Do While intTemp > 1 Dim objWriter As New System.IO.StreamWriter("C:\Documents\Visual Studio 2010\Projects\Report\Report\Stream.txt", True) intTemp = intTemp + 1 System.Threading.Thread.Sleep(5000) objWriter.Write(intTemp & " " &