runnable

Java: return results from Runnable

二次信任 提交于 2019-12-10 11:40:00
问题 Suppose the following simplified example. Let B represent a class processing some raster data: import java.awt.image.BufferedImage; public class B implements Runnable{ private boolean c; private Runnable f; public B (boolean c_, Runnable f_) { c = c_; f = f_;} public BufferedImage process() { //Some operations BufferedImage output = null; if (c) output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); return output; } public void run() { process();} } The process() method may but

how to package images into a Runnable JAR

无人久伴 提交于 2019-12-10 11:23:35
问题 Before ... (question deleted) I'm trying to make a runnable jar from a Swing project. I add some images in /img folder. Previous version didn't have it and runnable jar was good through export in Eclipse. Now I guess something is going wrong. In runnable jar I added at same level of main package and META-INF folder, this img folder but it seems GUI does not appear. Some process before building GUI went good so main class seems ok. Any suggestion!? Thanks. Comments : Run it on the command line

Combining two Runnable objects

大城市里の小女人 提交于 2019-12-10 10:47:57
问题 Say for example that I have a Runnable called RunnableA that does something. I also have a Runnable called RunnableB that does something else. Is there a way that I can combine these two Runnables someway so that they will run in the same thread? The second part of the question is if this is possible, can I then specify the order that they will run in? EDIT!: The reason why I wanted to do this was because I need to run code on the EDT but some of the other code needs to be run on another

Bad practice to use Runnable as callback / subroutine?

橙三吉。 提交于 2019-12-10 01:36:29
问题 Is it's considered bad practice to use Runnable as a callback? Considering that Runnable is meant to be used with threads (see it's JavaDoc), I'm wondering if this is okay - or whether I should make my own interface for this purpose. What I'm talking about is something like: public class KeyBinding { public KeyBinding(KeyStroke stroke, Runnable handler) { //... } } 回答1: Actually, Runnables can be used for any purpose. "The general contract of the method run is that it may take any action

Android: one handler for all runnables?

送分小仙女□ 提交于 2019-12-10 01:31:43
问题 Can I use one handler in my Activity for all runnables or should I have multiple instances of Handler, each for one runnable? 回答1: You can use only one handler and to specify from where your are coming use different message. handler.sendEmptyMessage(messagevalue); //use this to send message from different place Now handle message private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); //specify msg value if(msg.what==10){ //do this

successfully posted Runnable only gets executed when parent is invalidated

梦想的初衷 提交于 2019-12-09 23:27:09
问题 I sometimes run into the following scenario : I call View.post(Runnable r) and it returns true when calling android.os.Looper.myLooper().dump(...), the runnable seems not in the messageQueue after calling invalidate on the main layout (for example after 20 seconds), the Runnable gets executed This only happens from time to time, it happens on multiple devices and on multiple Android versions. The problem seems similar to Runnable is posted successfully but not run and Android: Button within

Android - Correct Multithreading

对着背影说爱祢 提交于 2019-12-09 14:07:12
问题 Can someone please give me a hand with this image downloading code? I want it to run in the background, but it seems like new Thread(new Runnable()) is definitely not the way to go, according to the Android docs, and I'm not sure how else to approach this: // caller while( exhibitorCursor.moveToNext() ) { new Thread(new Runnable() { public void run() { downloadImage(exhibitorId, exhibitorString, DOWNLOAD_EXHIBITOR); } }).start(); } // first function public void downloadImage(long id, String

Add properties file to build path of runnable jar

≡放荡痞女 提交于 2019-12-09 01:38:08
问题 is it possible to add to the classpath of a runnable jar file some properties file? I tryed these solutions solutions: running the executable file using the following command: java -cp ../prop_dir/prop1.properties;../prop_dir/prop2.properties -jar MyRunnableJar.jar adding to the MANIFEST FILE (in the Class-Path section) ../prop_dir/prop1.properties ../prop_dir/prop1.properties but none of them works. The architecture of the running dir is the following + + MyRunnableJar.jar + prop_dir/ +

TextView stops updating after bringing activity back to the front

流过昼夜 提交于 2019-12-09 01:28:25
问题 I'm trying to figure out threading and have this issue where a TextView stops being updated if the app is sent to the back, and then restored. How can I ensure that the TextView continues to be updated after the app is brought back to the front? Or... How do I reconnect the TextView to the handler in my run-nable thread after restarting the activity? There is a Progress Bar which works just fine, so I'm somewhat confused. I'd appreciate some advice as I think I may be making a simple mistake.

Process output only becomes available after the process has finished

*爱你&永不变心* 提交于 2019-12-09 01:21:32
问题 I have a Runnable that reads Console output from an externally called exe (see below) and writes it to both a log file and a JTextArea. But my Runnable doesn't show the Console output in the JTextArea until the exe completely finishes. How do I get it to print Console output as it happens? Short Concise Code Example below: //Main import java.awt.*; import java.io.IOException; import javax.swing.*; public class Example extends JFrame { private static final long serialVersionUID = 1L; public