event-dispatch-thread

I am trying to move a ball in applet using thread but its not moving

半世苍凉 提交于 2020-01-21 18:39:58
问题 I am trying to move a ball in applet using thread but its not moving. Can anyone help me out as m new to applet and proceeding for game development..for reference here is my code public class ballGame extends JApplet implements Runnable { int x_pos=50; int y_pos=100; int rad=10; Thread t; public void start() { super.start(); t=new Thread("t"); t.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); setBackground(Color.BLACK); g.drawOval(x_pos,y_pos,2*rad,2*rad);

I am trying to move a ball in applet using thread but its not moving

霸气de小男生 提交于 2020-01-21 18:39:04
问题 I am trying to move a ball in applet using thread but its not moving. Can anyone help me out as m new to applet and proceeding for game development..for reference here is my code public class ballGame extends JApplet implements Runnable { int x_pos=50; int y_pos=100; int rad=10; Thread t; public void start() { super.start(); t=new Thread("t"); t.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); setBackground(Color.BLACK); g.drawOval(x_pos,y_pos,2*rad,2*rad);

Progress bar freezing while downloading file in java [duplicate]

别来无恙 提交于 2020-01-15 06:08:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JProgressBar wont update So I am trying to show the download progress of a file being downloaded in Java. I can output the current percentage as a String to the console, but when I try to update the UI, it freezes until the download is complete. public void downloadFile(String fileName) { try { long startTime = System.currentTimeMillis(); System.out.println("Connecting to site...\n"); URL url = new URL("http:/

JFrame and why stay running

落爺英雄遲暮 提交于 2020-01-14 01:10:45
问题 Why if I create a JFrame then the program still runs until (i.e) I close it with the small "exit button" of the window? I looked for this answer and I failed. The only thing I guessed is that when I do new JFrame() it's like an special new , that keeps a reference of the object in the EDT, so it will always be referenced (even if was an anonymous "new") and it's not going to be deleted by the garbage collector. Then as soon as the event of windows close is triggered, the object is

JFrame and why stay running

偶尔善良 提交于 2020-01-14 01:10:08
问题 Why if I create a JFrame then the program still runs until (i.e) I close it with the small "exit button" of the window? I looked for this answer and I failed. The only thing I guessed is that when I do new JFrame() it's like an special new , that keeps a reference of the object in the EDT, so it will always be referenced (even if was an anonymous "new") and it's not going to be deleted by the garbage collector. Then as soon as the event of windows close is triggered, the object is

DispatchQueue crashing with main.sync in Swift

陌路散爱 提交于 2020-01-12 05:43:30
问题 Please explain to me why I am getting this crash? Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) in this DispatchQueue.main.sync { print("sync") } This is my code. override func viewDidLoad() { super.viewDidLoad() print("Start") DispatchQueue.main.async { print("async") } DispatchQueue.main.sync { print("sync") } print("Finish") } 回答1: @sankalap, Dispatch.main is a serial queue which has single thread to execute all the operations. If we call "sync" on this queue it will

Error handling in SwingWorker

别来无恙 提交于 2020-01-11 08:54:29
问题 My question is a theory-based question, but it does meet a specific need I have. What do you do when your SwingWorker throws an Exception that you a) can anticipate and b) need to recover from and continue, but you want to notify the user that this error has happened? How do you grab the expected exception and notify the user without violating the "No Swing code from doInBackground() " rule? I have, in consideration of this problem, developed a SSCCE that I would like to put forth with the

Why is SwingWorker not returning an object to the EDT?

烂漫一生 提交于 2020-01-07 08:24:30
问题 I am using the SwingWorker class to perform a background task. Many different components of the GUI get updated after the background thread has done is job (these are in the done() method). The doInBackground() method publishes a HeatMap class object and the process() method adds it to a JPanel component. I have added MouseListener and MouseMotionListener to this Heatmap class object. The mouseMoved() method is present in the main GUI class. When the mouse is moved, the coordinate position of

Why is SwingWorker not returning an object to the EDT?

岁酱吖の 提交于 2020-01-07 08:24:01
问题 I am using the SwingWorker class to perform a background task. Many different components of the GUI get updated after the background thread has done is job (these are in the done() method). The doInBackground() method publishes a HeatMap class object and the process() method adds it to a JPanel component. I have added MouseListener and MouseMotionListener to this Heatmap class object. The mouseMoved() method is present in the main GUI class. When the mouse is moved, the coordinate position of

The proper way to handle exceptions thrown by the SwingWorker.doInBackground

陌路散爱 提交于 2020-01-07 05:32:13
问题 The proper way to handle exceptions thrown by the doInBackground method of SwingWorker class is to invoke the get method from within the done method, as explained here and here. The documentation for the get method states the following: Waits if necessary for the computation to complete, and then retrieves its result. Note: calling get on the Event Dispatch Thread blocks all events, including repaints, from being processed until this SwingWorker is complete. Therefore, if the get method