2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 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]
32 import java
.awt
.event
.WindowEvent
;
33 import java
.awt
.event
.WindowListener
;
34 import javax
.swing
.JFrame
;
35 import javax
.swing
.JPanel
;
36 import javax
.swing
.JSplitPane
;
38 import jexer
.backend
.SwingBackend
;
41 * This class is the main driver for a simple demonstration of Jexer's
42 * capabilities. It shows two Swing demo applications running in the same
45 public class Demo5
implements WindowListener
{
48 * The first demo application instance.
50 DemoApplication app1
= null;
53 * The second demo application instance.
55 DemoApplication app2
= null;
58 * Pass window events into the event queue.
60 * @param event window event received
62 public void windowActivated(final WindowEvent event
) {
67 * Pass window events into the event queue.
69 * @param event window event received
71 public void windowClosed(final WindowEvent event
) {
76 * Pass window events into the event queue.
78 * @param event window event received
80 public void windowClosing(final WindowEvent event
) {
90 * Pass window events into the event queue.
92 * @param event window event received
94 public void windowDeactivated(final WindowEvent event
) {
99 * Pass window events into the event queue.
101 * @param event window event received
103 public void windowDeiconified(final WindowEvent event
) {
108 * Pass window events into the event queue.
110 * @param event window event received
112 public void windowIconified(final WindowEvent event
) {
117 * Pass window events into the event queue.
119 * @param event window event received
121 public void windowOpened(final WindowEvent event
) {
126 * Run two demo applications in separate panes.
128 private void addApplications() {
131 JFrame frame
= new JFrame();
132 frame
.setDefaultCloseOperation(JFrame
.DISPOSE_ON_CLOSE
);
133 frame
.addWindowListener(this);
135 // Create two panels with two applications, each with a different
137 JPanel app1Panel
= new JPanel();
138 SwingBackend app1Backend
= new SwingBackend(app1Panel
, new Object(),
140 app1
= new DemoApplication(app1Backend
);
141 app1Backend
.setListener(app1
);
143 JPanel app2Panel
= new JPanel();
144 SwingBackend app2Backend
= new SwingBackend(app2Panel
, new Object(),
146 app2
= new DemoApplication(app2Backend
);
147 Font font
= new Font(Font
.MONOSPACED
, Font
.PLAIN
, 18);
148 app2Backend
.setFont(font
);
149 app2Backend
.setListener(app2
);
150 (new Thread(app1
)).start();
151 (new Thread(app2
)).start();
153 JSplitPane mainPane
= new JSplitPane(JSplitPane
.HORIZONTAL_SPLIT
,
154 app1Panel
, app2Panel
);
155 mainPane
.setOneTouchExpandable(true);
156 mainPane
.setDividerLocation(500);
157 mainPane
.setDividerSize(6);
158 mainPane
.setBorder(null);
159 frame
.setContentPane(mainPane
);
161 frame
.setTitle("Two Jexer Apps In One Swing UI");
162 frame
.setSize(1000, 640);
163 frame
.setVisible(true);
169 * @param args Command line arguments
171 public static void main(final String
[] args
) {
173 Demo5 demo
= new Demo5();
174 demo
.addApplications();
175 } catch (Exception e
) {