FAQ Database Discussion Community


i am trying to make a pong game in android but i am stuck ,i dont know why ball isnt moving

java,android,surfaceview,thread-sleep,pong
here is the class which extends surface view , in its run method i've called the method to animate ball but the ball isnt animating public class OurView extends SurfaceView implements Runnable { Canvas c; Thread t = null; SurfaceHolder holder; boolean isItOk = false; Rect racketTop,racketBottom; int TopLeft ;...

Actionlistener outputing Jlist info to textarea

java,swing,actionlistener,jlist,thread-sleep
Could someone help me with the following problem? I want to implement a actionlistener that outputs info about the highlighted Jlist object into the already present textarea. Here is the code i've managed to cook up: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ListModel extends JFrame { private JList...

JFrame: Sleep between statements

java,multithreading,swing,sleep,thread-sleep
I'm still very new to the world of programming and have recently noticed, that whenever I tell the programm to idle for some seconds between the code, it instead sleeps at the start and then goes through the remaining code. I've tried various ways like thread.sleep() or Timers but I...

Java Swing and Thread sleeping

java,multithreading,swing,thread-sleep
I decided to make something fun as a break from reading programming books, and I have hit a snag. This is my first swing program, and am ready to wrap it up! The problem: I clearly don't understand how threads work with Swing. I am writing a GUI for a...

Using JButton to start simple animation [duplicate]

java,swing,animation,event-dispatch-thread,thread-sleep
This question already has an answer here: All JFrame freeze while do JavaMail 1 answer I am following HeadFirst Java 2nd Edition and trying to perform a simple animation of a circle moving diagonally from one point to another on the click of a button. I am using JPanel...

Python time.sleep lock process

python,multithreading,thread-sleep
I want to create multi process app. Here is sample: import threading import time from logs import LOG def start_first(): LOG.log("First thread has started") time.sleep(1000) def start_second(): LOG.log("second thread has started") if __name__ == '__main__': ### call birhtday daemon first_thread = threading.Thread(target=start_first()) ### call billing daemon second_thread = threading.Thread(target=start_second()) ###...

abortable sleep() in Python

python,thread-sleep
I need a sleep() method which can be aborted (as described here or here). My approach is to let a threading.Event.wait() timeout at the specified duration: def abortable_sleep(secs, abort_event): abort_event.wait(timeout=secs) abort_event.clear() After calling abortable_sleep(10, _abort) I can now (from another thread) call _event.set(_abort) to let abortable_sleep() terminate before the 10...

Thread sleeping in a BackgroundWorker

c#,wpf,multithreading,backgroundworker,thread-sleep
I wrote a simple app that adds 100000 lines of "Hello World" to a list using a BackgroundWorker. Below is the code of the work that my backgroundworker is doing in a separate thread: private void BgWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { int min = 0; foreach (var hw in hwList)...

How do I successfully use the Thread.sleep() method in Graphics?

java,exception-handling,applet,awt,thread-sleep
This is my code so far: // Imported Classes public class Timer extends Applet { public void paint (Graphics page) throws InterruptedException { Thread.sleep(1000); } } I just want to know how I can get this to work. I've used the Thread.sleep() method in other code before, but never with...

When I click on the activity I have 3 Text View in that. I want to load the Text View one after another like after a gap of 2 seconds?

java,android,multithreading,textview,thread-sleep
I am not sure but my research led me to come to this point. I think I need to create Thread object and then I can use Thread.sleep(seconds); But I am not sure how it works with Text View. private void runThread() { new Thread() { public void run() {...

Can std::this_thread::sleep_for() have spurious wakeups?

c++,c++11,stl,sleep,thread-sleep
Note, this is not a question about std::condition_variable::wait_for(). I know that can wake spuriously. My program’s behavior suggests the answer to this question is Yes, but the STL documentation is quite clear for the condition_variable case. At least at cppreference.com, the correct answer for this_thread appears to be No. Compiler...

Windows Phone: Task.Delay not working / Application hanging on a page

c#,while-loop,windows-phone,hang,thread-sleep
I am producing an application for Windows Phone 8.1. When a user navigates to a certain Page of the app, a block of code in the OnNavigatedTo() method is called. Here is what it looks like: protected override void OnNavigatedTo(NavigationEventArgs e) { while (!hasUserWonGame) { Task.Delay(3000); //do stuff... Task.Delay(6000); //do...

Stop current thread & wait for HTTP connection

java,http,thread-sleep
I am running some logic in a Thread that depends on a HTTP connection to a remote server. Currently, the thread crashes, if the remote server is not running. I want to modify the logic so that the thread waits for the remote server to become available again. Technically, the...

How can we make a thread to sleep for a infinite time in java?

java,multithreading,thread-sleep
Pls help me to understand how can we make a thread to sleep for a infinite time period .

I want to add a delay in a way, on button click update a label, sleep for few seconds and then update other labels

java,swing,concurrency,event-dispatch-thread,thread-sleep
This is the listener for the button. dice.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String randomNum = String.valueOf(randomNumber); rand.setText(" Move forward "+randomNum+" boxes"); //rand is a label try { Thread.sleep(6000); //1000 milliseconds is one second. } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } //here some handling with randomNumber Position[playerTurn].setText(posi); }...

Rate-limit calls to an IRC bot

java,thread-sleep,rate-limiting
I am working on a IRC bot that has the command !Scouter and it will generate a random number.... I already have that done, what I wanted to make was a cool down system to keep from people spamming it over and over again. here is my code. public class...

How do I autohide a form

c#,timer,thread-sleep
I have a very simple question i guess...for which i am not able to find an answer for. I am trying to add an autohide feature for a borderless WinForm which is located at (0,0) with a width of 150. I have the following code: private int dx; private void...

Java synchronization(object locking) not working as expected

java,multithreading,synchronization,thread-safety,thread-sleep
Please consider the below code. import static java.lang.System.out; public class Task { public Integer k = new Integer(10) ; public Task() { out.println(k + " constructor of Task : " + Thread.currentThread().getName()); } } import static java.lang.System.out; public class Executor2 implements Runnable { private Task task; public Executor2(Task t) {...

How to interrupt a thread by button listener

java,android,runnable,thread-sleep,interrupted-exception
I have a button listener witch include a thread sleep and another button listener. Second button listener must interrupt this thread and I don t know how to do this: My code: button1.setOnClickListener (new View.OnClickListener() { @Override public void onClick(View v) { .......... button1.setEnabled(false); button1.setVisibility(View.GONE); button2.setVisibility(View.VISIBLE); button2.setEnabled(true); new Thread(new Runnable()...