swingworker

Trying to stop swingworker

Deadly 提交于 2019-11-30 09:10:25
问题 I have a custom JDialog that pops up when my SwingWorker thread fires up. The dialog just has a JProgressbar and a Button (cancel button). I am trying to figure out how to cancel my SwingWorker, but am having no luck. I think I am on the right path though. I wrote a cancel method, now I just need to figure out how to call it when the button is pushed. Code is below... btn_Cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //trying to access

Swingworker instances not running concurrently

我与影子孤独终老i 提交于 2019-11-30 08:50:42
My computer has 4 cores and I am running a Java swing gui program. When I run my application it only uses two cores and about 30% CPU utilization. I have a large number of files to process and want to split them up into two threads to get this task done faster using more cpu. I have a SwingWorker class called PrepareTask, that has a constructor with two ints: class PrepareTask extends SwingWorker<Void, Void> { int start, end; PrepareTask (int start, int end) { ... } ... public Void doInBackground() {... } public void done() { ... } I create two instances of this like: PrepareTask prepareTask =

Turn-based Game Design: Event-Driven vs. Game Loop

此生再无相见时 提交于 2019-11-30 07:08:08
I am creating my first game in Java. The game is Monopoly. I am struggling with how I should design the game to model its turn-based structure (managing player turns). I want to allow for both a single human-controlled and one or multiple AI-controlled players to play the game. My specific issue is that I do not know whether to implement a game loop or not, meaning a loop which can manage the players and the variables directly related to the game of Monopoly, (think of things such as prompting each player for their turn, incrementing the turn to the next player, or getting dice rolls from each

JProgressBar not triggering propertyChange on setProgress

 ̄綄美尐妖づ 提交于 2019-11-29 18:17:19
I've read many different articles about JProgressBar...including the dodgy code found over at Java; here. Most indicate you need a SwingWorker to get things happening properly, which makes perfect sense, I understand that much. I am finding that when I call setProgress(value) to update the progressbar, it's not triggering the propertyChange event most of the time. I've checked the value I'm passing to setProgess and it definitely changes every time, so I'm not sure if it's just firing the event too quickly? Please see relevant code below, any help/explanation would be greatly appreciated.

Java GUI threads - SwingWorker

≡放荡痞女 提交于 2019-11-29 17:02:53
I have a question regarding SwingWorker and Java GUI's. I have several classes which process information, we can call them Foo1 , Foo2 , and Foo3 . This processing can take a very long time. These are all subclasses of Foo , however Foo is not called directly itself (the Foo[x] classes use methods inherited from Foo . In order to keep the EDT free to paint a progress bar, what is the best way to use SwingWorker when keeping my object hierarchy? Is it possible to have wrapper classes such as Foo1Worker extends SwingWorker and have its doInBackground() call Foo1.myProcessMethod() ? Even though

How to delegate SwingWorker's publish to other methods

ε祈祈猫儿з 提交于 2019-11-29 15:00:28
问题 My "problem" can be described by the following. Assume we have an intensive process that we want to have running in the background and have it update a Swing JProgress bar. The solution is easy: import java.util.List; import javax.swing.JOptionPane; import javax.swing.JProgressBar; import javax.swing.SwingWorker; /** * @author Savvas Dalkitsis */ public class Test { public static void main(String[] args) { final JProgressBar progressBar = new JProgressBar(0,99); SwingWorker<Void, Integer> w =

Safely open and close modal JDialog (using SwingWorker)

寵の児 提交于 2019-11-29 14:43:57
I needed a way to get some data from a database and prevent the user from modifying existing data for that moment. I created a SwingWorker to make the db update and a modal JDialog to show user what is going on (with a JProgressBar). The modal dialog has defaultCloseOperation set to DO_NOTHING, so it can only be closed with a proper call - I use setVisible(false) . MySwingWorkerTask myTask = new MySwingWorkerTask(); myTask.execute(); myModalDialog.setVisible(true); The SwingWorker does some stuff within doInBackground() and lastly it calls: myModalDialog.setVisible(false); My only concern and

Swingworker instances not running concurrently

时光总嘲笑我的痴心妄想 提交于 2019-11-29 13:34:55
问题 My computer has 4 cores and I am running a Java swing gui program. When I run my application it only uses two cores and about 30% CPU utilization. I have a large number of files to process and want to split them up into two threads to get this task done faster using more cpu. I have a SwingWorker class called PrepareTask, that has a constructor with two ints: class PrepareTask extends SwingWorker<Void, Void> { int start, end; PrepareTask (int start, int end) { ... } ... public Void

How I append text to textarea with using swingworker class?

拜拜、爱过 提交于 2019-11-29 13:06:27
I want to append text in loop with swingworkerclass in java. for ex : while(true) { mytextarea.append("sometext"); if(some_condition) {break;} } I want this with swingworker because I want to see every uptade on textarea. For this code I only see update when my proccess done. I dont want swingworker samples for another situations. Please give me some code here.Thanks. SwingWorker is not right here. Your code is not running in the EDT so you doesn´t see updates. You can use SwingUtilities.invokeLater(...) to execute your code in the EDT. But do not execute the whole while-loop in the EDT

Trying to stop swingworker

爱⌒轻易说出口 提交于 2019-11-29 12:59:04
I have a custom JDialog that pops up when my SwingWorker thread fires up. The dialog just has a JProgressbar and a Button (cancel button). I am trying to figure out how to cancel my SwingWorker, but am having no luck. I think I am on the right path though. I wrote a cancel method, now I just need to figure out how to call it when the button is pushed. Code is below... btn_Cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //trying to access cancel() } }); SwingWorker worker = new SwingWorker<String, Void>() { @Override protected String