public class SameTextGUIThread extends AbstractTextGUIThread
TextGUIThread
implementation is assuming the GUI event thread will be the same as the thread that
creates the TextGUI
objects. This means on the thread you create the GUI on, when you are done you pass over
control to lanterna and let it manage the GUI for you. When the GUI is done, you'll get back control again over the
thread. This is different from SeparateTextGUIThread
which spawns a new thread that manages the GUI and
leaves the current thread for you to handle.
Here are two examples of how to use SameTextGUIThread
:
MultiWindowTextGUI textGUI = new MultiWindowTextGUI(new SameTextGUIThread.Factory(), screen);
// ... add components ...
while(weWantToContinueRunningTheGUI) {
if(!textGUI.getGUIThread().processEventsAndUpdate()) {
Thread.sleep(1);
}
}
// ... tear down ...
In the example above, we use very precise control over events processing and when to update the GUI. In the example
below we pass some of that control over to Lanterna, since the thread won't resume until the window is closed.
MultiWindowTextGUI textGUI = new MultiWindowTextGUI(new SameTextGUIThread.Factory(), screen);
Window window = new MyWindow();
textGUI.addWindowAndWait(window); // This call will run the event/update loop and won't return until "window" is closed
// ... tear down ...
SeparateTextGUIThread
,
TextGUIThread
Modifier and Type | Class and Description |
---|---|
static class |
SameTextGUIThread.Factory
Default factory class for
SameTextGUIThread , you need to pass this to the TextGUI constructor if
you want it to use this class |
TextGUIThread.ExceptionHandler
customTasks, exceptionHandler, textGUI
Modifier and Type | Method and Description |
---|---|
Thread |
getThread()
Returns the Java thread which is processing GUI events and updating the screen
|
void |
invokeAndWait(Runnable runnable)
Schedules custom code to be executed on the GUI thread and waits until the code has been executed before
returning.
|
invokeLater, processEventsAndUpdate, setExceptionHandler
public Thread getThread()
TextGUIThread
public void invokeAndWait(Runnable runnable) throws IllegalStateException, InterruptedException
TextGUIThread
invokeAndWait
in interface TextGUIThread
invokeAndWait
in class AbstractTextGUIThread
runnable
- Code to runIllegalStateException
- If the GUI thread is not runningInterruptedException
- If the caller thread was interrupted while waiting for the task to be executedCopyright © 2016. All rights reserved.