2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import java
.net
.ServerSocket
;
32 import java
.net
.Socket
;
33 import java
.text
.MessageFormat
;
34 import java
.util
.ResourceBundle
;
36 import jexer
.TApplication
;
37 import jexer
.backend
.*;
38 import jexer
.demos
.DemoApplication
;
39 import jexer
.net
.TelnetServerSocket
;
43 * This class shows off the use of MultiBackend and MultiScreen.
50 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(Demo8
.class.getName());
52 // ------------------------------------------------------------------------
53 // Demo8 ------------------------------------------------------------------
54 // ------------------------------------------------------------------------
59 * @param args Command line arguments
61 public static void main(final String
[] args
) {
62 ServerSocket server
= null;
66 * In this demo we will create a headless application that anyone
71 * Check the arguments for the port to listen on.
73 if (args
.length
== 0) {
74 System
.err
.println(i18n
.getString("usageString"));
77 int port
= Integer
.parseInt(args
[0]);
80 * We create a headless screen and use it to establish a
83 HeadlessBackend headlessBackend
= new HeadlessBackend();
84 MultiBackend multiBackend
= new MultiBackend(headlessBackend
);
87 * Now we create the shared application (a standard demo) and
90 DemoApplication demoApp
= new DemoApplication(multiBackend
);
91 (new Thread(demoApp
)).start();
92 multiBackend
.setListener(demoApp
);
95 * Fire up the telnet server.
97 server
= new TelnetServerSocket(port
);
98 while (demoApp
.isRunning()) {
99 Socket socket
= server
.accept();
100 System
.out
.println(MessageFormat
.
101 format(i18n
.getString("newConnection"), socket
));
103 ECMA48Backend ecmaBackend
= new ECMA48Backend(demoApp
,
104 socket
.getInputStream(),
105 socket
.getOutputStream());
108 * Add this screen to the MultiBackend, and at this point we
109 * have the telnet client able to use the shared demo
112 multiBackend
.addBackend(ecmaBackend
);
115 * Emit the connection information from telnet.
118 System
.out
.println(MessageFormat
.
119 format(i18n
.getString("terminal"),
120 ((jexer
.net
.TelnetInputStream
) socket
.getInputStream()).
122 System
.out
.println(MessageFormat
.
123 format(i18n
.getString("username"),
124 ((jexer
.net
.TelnetInputStream
) socket
.getInputStream()).
126 System
.out
.println(MessageFormat
.
127 format(i18n
.getString("language"),
128 ((jexer
.net
.TelnetInputStream
) socket
.getInputStream()).
131 } // while (demoApp.isRunning())
134 * When the application exits, kill all of the connections too.
136 multiBackend
.shutdown();
139 System
.out
.println(i18n
.getString("exitMain"));
141 } catch (Exception e
) {
144 if (server
!= null) {
147 } catch (Exception e
) {