-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswing notes.txt
More file actions
33 lines (23 loc) · 1.96 KB
/
Copy pathswing notes.txt
File metadata and controls
33 lines (23 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Three types of threads:
Initial: threads that run at the start
Event Dispatch: All event handling code is executed here. Most code interacting with Swing also executes here
Worker: Background tasks executed
INITIAL:
For swing, the initial thread should just create a runnable object initializing the GUI and scheduling execution for the GUI on the event threads.
How to create GUI: Use javax.swing.SwingUtilities.invokeLater or javax.swing.SwingUtilities.invokeAndWait. For non-applets (not connecting to the web), both can be used.
EVENT DISPATCH:
For "thread-safe" Swing methods, you can invoke these methods in any thread, but for non-thread-safe methods they can only be invoked in event thread.
Quick way to see if you're on the event thread: invoke javax.swing.SwingUtilities.isEventDispatchThread.
WORKER:
Created using SwingWorker classes. Provides a way to return values when finished, as well as provide intermediate results (which get processed in event threads)
SwingWorker:
protected doInBackground(): main logic, returns final output
protected done(): called when doInBackground() finishes, use get() to get the value from doInBackground(), updates can be made to GUI here (therefore this method is executed in event dispatch)
public execute(): Executes this thread
protected publish(): Sends intermediate results
protected process(): Receives data chunks from publish(). These values from publish() get congregated, then this method gets called for you to update the gui
public run(): Sets java.util.concurrent.Future to result of doInBackground(). No idea what that means
protected setProgress()/public getProgress(): For loading bars
TODO ANTHONY We can consider making new SwingWorker classes for all our different attacks, but I don't think that solves our current issue since all our things are processed in the event thread already.
TODO Add the slider/input box to let user choose how many guesses are ran per second
TODO Fix "additional stats" to have text naturally break