100% found this document useful (1 vote)
37 views47 pages

Buy Ebook Frontend Development With JavaFX and Kotlin: Build State-of-the-Art Kotlin GUI Applications Peter Späth Cheap Price

Peter

Uploaded by

imperavivica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
37 views47 pages

Buy Ebook Frontend Development With JavaFX and Kotlin: Build State-of-the-Art Kotlin GUI Applications Peter Späth Cheap Price

Peter

Uploaded by

imperavivica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Download the full version of the ebook at

https://ebookmass.com

Frontend Development with JavaFX and Kotlin:


Build State-of-the-Art Kotlin GUI
Applications Peter Späth

https://ebookmass.com/product/frontend-
development-with-javafx-and-kotlin-build-state-of-
the-art-kotlin-gui-applications-peter-spath/

Explore and download more ebook at https://ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Beginning Kotlin: Build Applications with Better Code,


Productivity, and Performance Ted Hagos

https://ebookmass.com/product/beginning-kotlin-build-applications-
with-better-code-productivity-and-performance-ted-hagos/

testbankdeal.com

Programming Kotlin Applications: Building Mobile and


Server-Side Applications With Kotlin Brett Mclaughlin

https://ebookmass.com/product/programming-kotlin-applications-
building-mobile-and-server-side-applications-with-kotlin-brett-
mclaughlin/
testbankdeal.com

Kotlin for Web Development and Kotlin Collections: A


Beginner's Odyssey in Web Development 2 Books in 1 Jp
Parker
https://ebookmass.com/product/kotlin-for-web-development-and-kotlin-
collections-a-beginners-odyssey-in-web-development-2-books-in-1-jp-
parker/
testbankdeal.com

Pro Spring 6 with Kotlin: An In-depth Guide to Using


Kotlin APIs in Spring Framework 6 1st Edition Peter Späth

https://ebookmass.com/product/pro-spring-6-with-kotlin-an-in-depth-
guide-to-using-kotlin-apis-in-spring-framework-6-1st-edition-peter-
spath/
testbankdeal.com
Pro Kotlin Web Apps from Scratch August Lilleaas

https://ebookmass.com/product/pro-kotlin-web-apps-from-scratch-august-
lilleaas/

testbankdeal.com

Numerical Methods Using Kotlin: For Data Science,


Analysis, and Engineering 1st Edition Haksun Li

https://ebookmass.com/product/numerical-methods-using-kotlin-for-data-
science-analysis-and-engineering-1st-edition-haksun-li-2/

testbankdeal.com

Numerical Methods Using Kotlin: For Data Science,


Analysis, and Engineering 1st Edition Haksun Li

https://ebookmass.com/product/numerical-methods-using-kotlin-for-data-
science-analysis-and-engineering-1st-edition-haksun-li/

testbankdeal.com

Next-Level UI Development with PrimeNG: Master the


versatile Angular component library to build stunning
Angular applications 1st Edition Dale Nguyen
https://ebookmass.com/product/next-level-ui-development-with-primeng-
master-the-versatile-angular-component-library-to-build-stunning-
angular-applications-1st-edition-dale-nguyen/
testbankdeal.com

Pro Kotlin Web Apps from Scratch: Building Production-


Ready Web Apps Without a Framework 1st Edition August
Lilleaas
https://ebookmass.com/product/pro-kotlin-web-apps-from-scratch-
building-production-ready-web-apps-without-a-framework-1st-edition-
august-lilleaas/
testbankdeal.com
Frontend
Development with
JavaFX and Kotlin
Build State-of-the-Art Kotlin
GUI Applications

Peter Späth
Frontend Development with JavaFX and Kotlin
Peter Späth

Frontend Development
with JavaFX and Kotlin
Build State-of-the-Art Kotlin GUI Applications
Peter Späth
Leipzig, Sachsen, Germany

ISBN-13 (pbk): 978-1-4842-9716-2 ISBN-13 (electronic): 978-1-4842-9717-9


https://doi.org/10.1007/978-1-4842-9717-9

Copyright © 2023 by Peter Späth


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by
similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of
a trademarked name, logo, or image, we use the names, logos, and images only in an editorial fashion and to the benefit of the
trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such,
is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors
nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher
makes no warranty, express or implied, with respect to the material contained herein.

Managing Director, Apress Media LLC: Welmoed Spahr


Acquisitions Editor: Celestin Suresh John
Development Editor: Laura Berendson
Coordinating Editor: Mark Powers

Cover designed by eStudioCalamar


Cover image by Jerryyaar Designer on Pixabay (www.pixabay.com)

Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-
800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media,
LLC is a California LLC, and the sole member (owner) is Springer Science + Business Media Finance Inc. (SSBM Finance
Inc). SSBM Finance Inc. is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint, paperback, or audio rights,
please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also
available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/
bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://
github.com/Apress). For more detailed information, please visit https://www.apress.com/gp/services/source-code.

Paper in this product is recyclable


Contents

1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Gradle for JavaFX and Kotlin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
A HelloWorld Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Setting Up for Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Setting Up for IntelliJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Kotlin and Java Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
A Note About Kotlin Utilities for JavaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
A Note About FXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
A Note About Downloading JavaFX Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Build Setup for This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Why you Should use Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
One-Way and Two-Way Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Custom Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
About Observable Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3 Stages and Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
About Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using Stages and the Application Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Dialog-Like Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
The JavaFX Application Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
About Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Position and Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Mnemonic and Accelerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Node Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Fill and Other Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Mouse Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

v
vi Contents

Mouse Drag Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52


Gestures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4 Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
StackPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
VBox and HBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
FlowPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
GridPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
TilePane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
BorderPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
AnchorPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Styling Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Adding Stylesheets to the Whole Scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Adding Stylesheets to Individual Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
JavaFX CSS Selectors for Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
JavaFX CSS Properties for Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5 Visual Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Node Coordinate Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Image Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Text Fields and Text Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Action Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Button Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Checkboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Radio Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Combo Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Sliders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Miscellaneous Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Control Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Scroll Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Accordions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Tab Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Split Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Styling Visual Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6 Lists and Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Lists with ListView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Tables with TableView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Trees with TreeView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Contents vii

7 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
What Events Are and Event Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Event Handlers and Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Drag and Drop Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
8 Effects and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
About Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Animating Your Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Timeline Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
9 Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The JavaFX Concurrency Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
About Kotlin Coroutines for JavaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
About the Author

Peter Späth graduated in 2002 as a physicist and soon afterward became an IT consultant, mainly for
Java-related projects. In 2016, he decided to concentrate on writing books on various aspects, but with
a main focus on software development. With two books about graphics and sound processing, three
books on Android app development, and a couple of books about Java, Jakarta EE, and Kotlin, Peter
continues his effort in writing software development-related literature.

ix
About the Technical Reviewer

Massimo Nardone has more than 25 years of experience in security,


web and mobile development, cloud, and IT architecture. His true
IT passions are security and Android. He has been programming
and teaching how to program with Android, Perl, PHP, Java, VB,
Python, C/C++, and MySQL for more than 20 years. He holds a
Master of Science degree in Computing Science from the University
of Salerno, Italy. He has worked as a CISO, CSO, security executive,
IoT executive, project manager, software engineer, research engineer,
chief security architect, PCI/SCADA auditor, and senior lead IT
security/cloud/SCADA architect for many years. His technical skills
include security, Android, cloud, Java, MySQL, Drupal, Cobol, Perl,
web and mobile development, MongoDB, D3, Joomla, Couchbase,
C/C++, WebGL, Python, Pro Rails, Django CMS, Jekyll, Scratch,
and more. He worked as visiting lecturer and supervisor for exercises
at the Networking Laboratory of the Helsinki University of Technol-
ogy (Aalto University). He holds four international patents (PKI, SIP,
SAML, and Proxy areas). He is currently working for Cognizant as
head of cyber security and CISO to help both internally and externally
with clients in areas of information and cyber security, like strategy,
planning, processes, policies, procedures, governance, awareness,
and so forth. In June 2017 he became a permanent member of the
ISACA Finland Chapter Board.
Massimo has reviewed more than 45 IT books for different
publishing companies and is the coauthor of Pro Spring Security:
Securing Spring Framework 5 and Boot 2-based Java Applications
(Apress, 2019), Beginning EJB in Java EE 8 (Apress, 2018), Pro
JPA 2 in Java EE 8 (Apress, 2018), and Pro Android Games (Apress,
2015).

xi
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Introduction

Building elegant and highly responsible, responsive, and stable Java client applications (fat clients)
is a highly acceptable approach if security considerations or network availability speaks against
web applications, or maintaining servers and server applications lies out of scope for your project.
Additionally, using Kotlin as a programming language boosts code expressiveness and maintainability,
allowing for a development yielding a clean code approach.
The book introduces JavaFX as a frontend technology and from the very beginning focuses
on using Kotlin instead of Java for coding the program artifacts. Many listings and code snippets
accompany the text, readily allowing for a hands-on learning style.

The Book’s Targeted Audience

The book is for low- to mid-level Java or Kotlin developers with or without JavaFX experience,
wishing to learn how to build JavaFX applications with Kotlin.
The readers will in the end be able to use Kotlin as a language for building basic to moderately
advanced and elaborated apps targeting JavaFX.
Any experience in using JavaFX and frontend coding is not a requirement for reading the book.
Being a Kotlin expert is not necessary either, but having read introductory-level books or studied
online resources is surely helpful. The online documentation of Kotlin and JavaFX also provides
valuable resources you can use as a reference while reading this book.

Source Code

All source code shown or referred to in this book can be found at github.com/apress/frontend-
development-javafx-kotlin.

How to Read This Book

This book should be read sequentially to get the most benefit from it. Of course, you can skip one
or the other chapter if you already gained knowledge elsewhere. Taking its introductory nature, the
book is not meant to present a reference fully covering each and every aspect of Kotlin frontend
programming or JavaFX, so also consulting the online documentation at
https://openjfx.io/
https://openjfx.io/javadoc/19/
https://kotlinlang.org/docs/home.html

xiii
xiv Introduction

while you are reading the book certainly is not a bad idea.
The book is split up into nine chapters. Chapter 1 gives a general introduction and presents hello
world-style programs for Gradle, Eclipse, and IntelliJ.
Chapter 2 talks about using properties as data holders and addresses one- and two-way binding
techniques for connecting controls and data in your program.
Chapter 3 introduces stages and scenes, which serve as primordial containers for visual artifacts.
Chapter 4 talks about containers and ways to lay out and style your scenes.
Chapter 5 handles nodes and controls including styling. These aspects usually constitute the biggest
part of your project work speaking of time budget.
Chapter 6 presents lists and tables, which are particularly important for enterprise-level projects.
Chapter 7 is for summarizing and deepening our knowledge about event handling in JavaFX. This
also includes drag and drop procedures.
Chapter 8 introduces effects and animation, improving user experience and giving your programs
some eye candies.
As a prospect, Chapter 9 briefly introduces concurrency techniques, giving you a starting point for
handling background processing needs.
Getting Started
1

In this chapter, we give a brief introduction to using JavaFX and Kotlin together, and we create “Hello
World”–style projects for the command line, for Eclipse, and for IntelliJ IDEA.

Introduction

JavaFX is the dedicated fat client (desktop application) GUI toolkit for current Java releases. It is
the replacement and successor of the venerable Java Swing technology. This switch happened around
2010, and since then JavaFX has been constantly improved and extended. With JREs up to version
JDK 9, JavaFX was part of the Java distribution—with JDK 11 and later, it has to be installed
separately.
The following features describe JavaFX:

. Built-in controls: Labels, editable text fields, buttons, combo boxes, checkboxes, radio buttons,
menu bars, scrollbars, accordion, tabs, canvas (for drawing shapes and figures), color picker, pag-
ination, 3D graphics (games, science, product presentation), WebView (presenting and interacting
with web contents), dialogs, sliders, spinners, progress bars
. Lists, tables, trees
. Built-in layouts: AnchorPane (anchoring nodes to one of the edges or to the center point),
BorderPane (placing nodes at bottom, top, right, left, center), FlowPane (placing nodes consec-
utively and wrapping at the boundaries), TilePane (same as FlowPane, but with all cells the same
size), GridPane (placing nodes in a grid with cell sizes dynamically calculated and on demand
spanning several rows and columns), VBox (placing nodes in columns), HBox (placing nodes in
rows), StackPane (placing nodes in an overlay fashion)
. Animation (fade, fill, stroke, translate, rotate, scale, . . . ), effects (glow, blend, bloom, blur,
reflection, sepia, shadow, lighting)
. Nodes stylable via CSS
. Some built-in chart widgets
. Flexible and concise data binding via observable properties
. Descriptive layouting via FXML
. Module support (for JDK 9+)

© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023 1
P. Späth, Frontend Development with JavaFX and Kotlin,
https://doi.org/10.1007/978-1-4842-9717-9_1
2 1 Getting Started

. Graphics transformations and coordinate systems


. Media APIs
. Java Swing interoperability
. Comes as a set of JAR modules and native libraries
. An external Scene Builder for graphically creating scenes
. Printing API

In this book, we describe a subset of these features, giving you a starting point for your own
projects.
Using Kotlin as a programming language instead of Java gives a boost to your coding experience.
Just to give you an example, consider a button with a click handler. In Java, you’d write
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});

(255 characters) The very same code written in Kotlin reads


val btn = Button().apply {
text = "Say 'Hello World'"
setOnAction { _ ->
println("Hello World!")
}
}

With 142 characters, this is more than 40% shorter than the Java variant! And besides being shorter,
it is also more expressive and by that easier to understand and easier to maintain.
Using some sufficiently nonobtrusive utility functions, this can even be further reduced to 81
characters in size:
val btn = Button("Say 'Hello World'") {
println("Hello World!")
}

This works by Kotlin’s ability to dynamically add additional constructors to classes.

Gradle for JavaFX and Kotlin

As a build tool, we use Gradle from https://gradle.org/. It is highly flexible, works on any operating
system that provides a Java installation, and by means of plugins or preinstalled components can be
operated from many IDEs.
I first describe the CLI mode for running Gradle builds. This is how you would use it in a server
environment, but it also serves as a good starting point if you want to learn how to use Gradle inside
an IDE workflow.
If not already present, get and install a version 17 JDK. Throughout the book, we will be using
OpenJDK 17, but if chances are good you can also take Oracle’s supported JDK 17 or a higher version
from either Oracle or https://openjdk.org/ without any problems possibly coming up.
Gradle for JavaFX and Kotlin 3

Note Using Oracle’s JDK 17 or higher requires buying a license if you plan to use it for a longer
term; see www.oracle.com/java/.

As a next step, fetch Gradle from https://gradle.org. In this book, we use version 7.6 from https://
gradle.org/next-steps/?version=7.6&format=bin. In order to announce Java to Gradle, either make
sure java and javac (with .bat extension on Windows) are in your PATH, or you have the
environment variable JAVA_HOME point to your JDK installation folder (recommended). To simplify
using Gradle, you can also put GRADLE-INST-DIR/bin (with GRADLE-INST-DIR pointing to your
Gradle folder), or GRADLE-INST-DIR\bin for Windows, on the path.

Note In Linux, environment variables like PATH or JAVA_HOME get set via
export PATH=/bin:/usr/bin:/path/to/my/gradle/bin.
In Windows, you must use the system settings dialog.

In order to check your Gradle installation, in a terminal enter


gradle -version

or, if Gradle is not in the path:


/path/to/gradle -version (Linux)
C:\path\to\gradle.bat -version (Windows)

The output of the command should be similar to


---------------------------------------------------------
Gradle 7.6
---------------------------------------------------------

Build time: 2022-11-25 13:35:10 UTC


Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8

Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on
July 10 2021
JVM: 17.0.1 (Oracle Corporation 17.0.1+12-39)
OS: Linux 5.15.0-56-generic amd64

Important is the “JVM:” line. The Kotlin version shown does not mean you would not be able to build
applications running under a different Kotlin version—it just tells it is using Kotlin 1.7.10 for its own
purposes.
Next, create a project folder anywhere on your system. For our example project, we call it
HelloWorld. Change into that folder:
cd /path/to/HelloWorld (Linux)
chdir C:\path\to\HelloWorld (Windows)

In order to initialize the Gradle project, enter (one line)


gradle init --dsl groovy --incubating
--insecure-protocol ALLOW --package book.kotlinfx
--project-name kotlinfx --test-framework kotlintest
--type kotlin-application

You can also enter just gradle init, but then you will subsequently be asked for project
coordinates inside the terminal.
4 1 Getting Started

The “init” task creates a simple scaffold project which consists of a main project described by
file settings.gradle and a subproject called “app” in the accordingly named subfolder. The
application can be run by just entering either of
gradle app:run
gradle run

The second variant is possible, because there is just one subproject. By the way, you can list all
possible tasks via gradle tasks or gradle tasks --all, and entering gradle help shows
more info.
Did you notice that two executable files gradlew and gradlew.bat and a folder gradle were
created? This is the Gradle Wrapper, and it is a Gradle installation on its own, and you can henceforth
use it to build the project. Just use gradlew from the wrapper instead of gradle from the Gradle
distribution. You can even delete the main Gradle installation folder at this time, if you like.
It is now time to add JavaFX to the project. In Gradle, the build.gradle file is the main
configuration file for the build process. You can find it inside the app subproject inside the app folder.
Open the file inside a text editor, and inside the plugins { . . . } section, add
plugins {
...
id 'org.openjfx.javafxplugin' version '0.0.13'
}

This plugin adds almost all that is necessary to add JavaFX to a Java or Kotlin project. Kotlin
capabilities were already added during gradle init. We however still need to make sure that
Kotlin compiles for JDK 17 and that JavaFX uses version 19 and allows for using the modules
“javafx.controls” and “javafx.graphics”. For that aim, add at the end of build.gradle
compileKotlin {
kotlinOptions {
suppressWarnings = true
jvmTarget = "17"
}
}
javafx {
version = "19"
modules("javafx.controls", "javafx.graphics")
}

Note JavaFX is separated into different modules. The modules “javafx.base”, “javafx.controls”, and
“javafx.graphics” are essential to almost any JavaFX application. Because both the controls and the
graphics module require the base module, the latter gets implicitly included in any build and can be
omitted from the modules list. For more details, see https://openjfx.io/javadoc/19/

In the next section, we code our little “Hello World” JavaFX with Kotlin application.

A HelloWorld Project

The scaffold project built via gradle init just prints “Hello World!” on the console if run. As a
starter JavaFX project, we instead want to show a little window with a button on it reacting to press
events. To do so, replace the contents of
app/src/main/kotlin/book/kotlinfx/App.kt
Setting Up for Eclipse 5

by
package book.kotlinfx

import javafx.application.Application
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.layout.StackPane
import javafx.stage.Stage

fun main(args:Array<String>) {
Application.launch(HelloWorld::class.java, *args)
}

class HelloWorld : Application() {


override
fun start(primaryStage:Stage) {
primaryStage.title = "Hello World!"
val btn = Button().apply {
text = "Say 'Hello World'"
setOnAction { evnt ->
println("Hello World!")
}
}

val root = StackPane().apply {


children.add(btn)
}

with(primaryStage){
scene = Scene(root, 300.0, 250.0)
show()
}
}
}

Save the file. To now run the application, enter


./gradlew run (Linux)
gradlew run (Windows)

See Figure 1-1.


To first compile and build the project is not necessary—Gradle takes care of that if needed.

Setting Up for Eclipse

Note You can skip this section if you don’t use Eclipse.

Download and install a recent Eclipse IDE from www.eclipse.org/downloads/. Start Eclipse and then,
at Window → Preferences → Java → Installed JREs, register a JDK version 17 and make it the
default. See Figure 1-2.
Then, at File → New → Project. . . → Gradle → Gradle Project, create a new Gradle project. Once
asked, enter “kotlinfx” as the project’s name; see Figure 1-3.
Keep everything else at its defaults. You end up with a main and a subproject; see Figure 1-4.
The name of the subproject reads “lib.” We want to change it to a more meaningful variant.
6 1 Getting Started

Figure 1-1 JavaFX HelloWorld Running

Figure 1-2 Eclipse JRE Setting

Caution Due to a design issue inside the Gradle-Plugin for Eclipse 2022-12, you cannot rename the
subproject’s name via Mouse-Right → Refactor → Rename. . . We must apply a workaround.
Setting Up for Eclipse 7

Figure 1-3 Eclipse Gradle Project Wizard

First, edit file settings.gradle. Change the line


include('lib')
->
include('HelloWorld')

Now delete the “lib” subproject from Eclipse. Make sure the “Also delete project contents” checkbox
is not checked.
In your system’s file explorer, rename folder lib inside WORKSPACE/kotlinfx to
HelloWorld.
On the main project, invoke Mouse-Right → Configure → Configure and Detect Nested
Projects. . . Press the “Finish” button. Ignore possibly shown errors.
Just to be on the safe side, restart Eclipse. The package view should now be as shown in
Figure 1-5.
Back to the application, replace the contents of the build.gradle file by
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.13'
}

repositories {
mavenCentral()
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
8 1 Getting Started

dependencies {
}

application {
mainClass = 'book.kotlinfx.AppKt'
}

compileKotlin {
kotlinOptions {
suppressWarnings = true
jvmTarget = "17"
}
}

javafx {
version = "19"
modules("javafx.controls", "javafx.graphics")
}

After changes to file build.gradle, the project regularly needs to be updated: on “kotlinfx,”
press Mouse-Right → Gradle → Refresh Gradle Project. Also, remove the packages inside src/
test/java; we don’t need them for now.

Figure 1-4 Eclipse


Gradle Project
Setting Up for Eclipse 9

A fresh Eclipse installation doesn’t know how to handle Kotlin files. To fix this, open Help →
Eclipse Marketplace. . . Enter “kotlin” in the search field, and select to install “Kotlin Plugin for
Eclipse” from the search result list. Restart Eclipse twice.
Make a new folder src/main/kotlin and register it as a source folder via Mouse-Right →
Java Build Path → Source → Add folder. . . See Figure 1-6.

Figure 1-5 Eclipse Subproject Renamed

Figure 1-6 Eclipse Kotlin Sources


Random documents with unrelated
content Scribd suggests to you:
hike again, your cold, wet clothes clinging to you.
Eight weary hours of this. At last, just before daybreak, we turned off
the road through the gateway of a once palatial estate, and hiked
across a park to a grove where we were billeted. The fifteen miles
we had covered seemed like 30. We were done in enough to fall
asleep, many without unrolling their packs. The rain, however, found
us out, trickled in at every corner, and morning found us miserable
enough.
No word was vouchsafed to us as to when we should move again;
and this playing at secrecy cost “D” and “C” Cos. their meal. It was
more luck than good management that gave me the hunch to rout
out our weary cooks and have chow at 11:00 o’clock. At 12:00
o’clock orders came in a great hurry that we were to clear the
crossroads at 2:30. We did it at 3:00.
Our new lieutenant-colonel, Arthur Budd, had joined us the night
before. During the first halt Lt. Foulkes came galloping up on old
Mary, and his former platoon—the first—chortled with glee every
time daylight showed between Louis and the saddle. Col. Budd
promptly treated me to a cold and fishy stare, and inquired if it was
the custom for “B” Co. to yell at officers when they passed. I hastily
delivered a brief resume of Louis’ career with the company and the
estimation in which we held him, intimating that he was regarded as
one helofa good fellow, and that no mutiny was breaking out.
Meanwhile I had hastily sized up our new acquisition as a goof. I had
reason to revise this estimate, and that shortly.
The rain let up this evening, for a wonder, and the march wasn’t half
bad, except for the mud under foot, which we were pretty well used
to. We passed by a sizeable cantonment of Chinese labor troops,
and Diskin wanted to fall out and leave his laundry. We had only the
most vague idea of where we were; in fact, our notions of French
geography were of the crudest anyhow. Bill Reid, from his six-foot
eyrie, solemnly announced that he saw the Alps ahead, and had the
1st platoon craning its respective necks for an hour.
Just as darkness fell, we ran into an ammunition train, the tail end of
the 42d Division. We pushed on behind them up a hill into the village
of Viocourt, where our old dependable of the advance party, Sgt. Hill,
met us and pointed out our billets, in lofts and stables on both sides
of the “street.”
We all knew pretty well by now that we must be in for action soon.
The St. Mihiel salient meant nothing more to us than it did to folks at
home then. The general impression was that it was to be a drive on
Metz; and this wasn’t so far out of the way, at that.
By this time it didn’t take us long to make ourselves at home in a
strange place. We had bagged a good place for the rolling kitchen,
and the billets weren’t so bad. Between showers we got in some
drilling, and a couple of hours on an extemporized 30-yard range
that Lt. Schuyler put up one morning before breakfast. Everyone
tried his hand at the Chauchat for a magazine full. This was the only
chance we had to fire this gun before we had to meet the enemy with
it. The men armed with pistols punctured a few tin cans after a vast
expenditure of lead.
There was a beautiful meadow below town, and on Sunday, the 8th,
we staged a couple of good ball games. On Monday we had a
company problem through the woods beyond the meadow, and
Tuesday we got in the target practice.
Wednesday morning the Major assembled the Co. cmdrs. and
ordered us to be ready to march at 1:30. After the usual bustle all
was ready for the road, two days’ rations being carried. Our kitchen
and cooks were attached to the regt’l supply train.
It had been raining all the morning, but old J. Pluvius had only been
practising for the real show. We started off in a steady downpour,
which speedily became a regular deluge. The wind rose to a gale,
which drove the sheets of water directly at us, penetrating right
through slickers and clothing. In 15 minutes we were all wet to the
skin.
It was only an hour’s march this time. At 3:00 P. M., we came to a
crossroads just outside Chatenois. There stood a long line of motor
trucks, stretching away in either direction as far as the eye could
see. The embussing was well handled, and in 20 minutes we were
packed in, 20 or more to a truck, jammed as tight as they could be,
every man wet through and chilled. Even our incorrigibly optimistic
regimental history says, “We shall never forget this day because of
its miserable and nasty weather.”
These busses were driven by Chinese in the French service. With
their impassive Oriental faces looking out over their great sheepskin
coats, they looked fitting agents of destiny; grave Charons, bearing
us on the last lap of our progress toward our fate.
At 4:00 o’clock we were off, with a jerk and a clank of gears and a
steady rumble. On and on, over the long French road, rolling on
through rain and wind, steadily, inevitably; each lorry nearly touching
the one in front. Darkness fell; the long gray train rolled on, not a
light, not a sound save the rumble of the trucks. We got colder and
colder; more and more cramped. Capt. Fleischmann and I spent
most of the night each cherishing the other’s icy feet in his bosom.
On and on, through gray, silent towns, past the ghostly figure of a
lonely M. P. at a crossroads; through fields, woods, villages, all wet
and quiet in the falling rain.
Just as the daylight began to thin the inky mist, the train halted, and
the word was passed along the line to debus. Wet, shivering,
miserable, “B” Co. struggled hastily into clammy shoes and slung
their heavy, soggy packs. As we formed on the side of the road, the
busses started again, and rolled swiftly off into the shadows ahead,
leaving us on the road, with heavy woods on either side.
We marched down the road to an open field on the left. Here a
railroad track entered the corner of the wood. We turned off up the
track, and about 300 yards along we came upon the 2nd battalion
bivouacking. We went on just beyond them, and were allotted our
own share of squishy ground and drenched underbrush.
A limited number of fires were allowed, and we made ourselves as
comfortable as we could under the circumstances. I was detailed on
O. D. and spent a busy day dissuading the regiment from straggling
all over the road and open fields. All knew that a big attack was in
preparation, and that it was important that the concentration be kept
under cover from the enemy’s aircraft. But some men apparently
couldn’t compree that we weren’t roosting in that bally old dysentery
generator of a wood for sheer sport.
Showers fell intermittently during the day, but nothing like the
previous day’s deluge. At about 4 P. M. there was an officers’ call,
and we were warned to march at 7 P. M. Co. Commanders were
issued maps, and we learned that our present bivouac was in the
Bois de la Cote en Haye, east of Tremblecourt.
About 5 P. M., six French tanks came clanking down the road, did a
Squads Left, waddled across the fields and disappeared over the
brow of the hill, toward the rumble of intermittent artillery fire in the
distance that meant the front.
The 312th Inf. was bivouacked on the other side of the railroad track,
and the rest of the division was hidden in the woods near by. Across
the main road was a great artillery ammunition dump, big enough to
blow up ten divisions if a bomb ever hit it. But I kept this to myself,
and what a soldier doesn’t know doesn’t worry him. He has enough
to worry about anyhow.
The kitchens came up late in the afternoon, and we got outside of a
ration of hot slum before dark.
By 6:45 P. M. we had rolled packs, and were ready to hit the road
again. I went to sleep on the ground, with my pack on my back, and
was awakened by Dunn to find it nearly dark, and the battalion ready
to move off.
It seemed hours before we got out of the wood into the open field.
We would go forward a few steps along the track, and then stand
and wait for ten or fifteen minutes. The road by which we had arrived
was crowded with transport and artillery, and we turned off on a
bypath through the woods. It was now quite dark, and blind work it
was blundering along, touching the man ahead to keep from losing
him, slipping and tripping in the wet underbrush. It is remarkable how
exasperating a pack and rifle become under such circumstances.
However, the excitement of anticipation buoyed us up, and “B” Co.
wallowed through the wood, across a mushy field, and scrambled up
a slippery embankment on to a strange road, much more cheerfully
than now seems possible.
Once re-formed on said road, we hiked along briskly in column of
squads. Soon we overtook a long column of transport wagons,
trucks and artillery. Road discipline was something apparently
unknown; every vehicle seemed to be trying to pass every other one.
The consequence was of course wondrous confusion, and here and
there a total jam, through which we had to thread our way in single
or double file as best we could.
When we got clear of the last jam, the company ahead had gained
about 15 yards, and was consequently as completely out of sight as
if they had been in Timbuctoo. We passed through a village in hot
pursuit of them. At the crossroads, by sheer good luck I turned off up
the right one. After a long hour’s stern chase we were relieved to see
the bobbing forms of Headquarters Co. show through the gloom
ahead.
At about 10:30 we came upon Sgt. Hill waiting for us by the
roadside, with the welcome news that our temporary destination was
only a couple of kilos off. We toiled up a long hill, and turned off the
macadam into a rough road that was a series of four inch ponds. We
plashed along to the edge of a large wood, and Hill showed us a pile
of empty bandoliers and boxes, where the Marines had been issued
ammunition and grenades about an hour before. They had just
pulled out, and were going over the top at dawn.
A hundred yards or so, and we turned into the woods, on a road
which was from ankle to knee deep in all varieties of mud, from
sticky to liquid. We moved on, stumbled over a railroad track, and
finally Hill said we were at our bivouac. The trees and underbrush
grew so thick along the road that we blundered about a bit before we
found a couple of places where we could force our way through. As
each man reached a place where he could sit or lie down, down he
flopped, and the rest of the company walked over him. The woods
already had some occupants, and more and more poured in every
minute.
At last “B” Co. had distributed itself on the ground, and was
preparing for a dismal wallow until morning. In spite of wet, mud and
chill some were already asleep. We were just within the artillery
zone, and the jar and grumble of the guns ahead was occasionally
punctuated by the roar and scream of one of the heavies nearer by.
This, however, was only normal artillery fire, such as we had been
accustomed to at St. Pol and Lattre St. Quentin, and we settled
down to wait for the big show. Some of the more energetic started to
pitch their pup tents.
Just as I dozed off, some idiot shouted “Gas!” Our long hours of gas
drill, and many vivid and gruesome lectures on the subject, promptly
bore fruit. In fact, the good seed shot up like Jack’s beanstalk. The
cry was re-echoed by a dozen, then a score of startled voices.
Everyone reached into the familiar canvas satchel that he cherished
on his bosom, donned his mask more or less expeditiously, and sat
expectantly awaiting developments.
In the midst of the rumpus I heard Lt. Foulkes’ voice from the road
bawling for the company commanders. I thought sadly that the lad
had probably lost his mask, or the gas had caught him suddenly and
he was raving. However, for sake of auld lang syne, I took a long
breath, and shouted, “Whatsmatterwhydontyouputonyourmask?” I
replaced my mouthpiece, and started blundering toward Louis’ voice,
hoping I might be in time at least to view his remains.
During the next two minutes I walked on every man in “B” Co. at
least once, and probably on most of “A” and “C” Cos. Then Foulkes
roared my name within five yards of me.
“Where’s the gas?” I demanded.
There wasn’t any gas.
CHAPTER VI
ST. MIHIEL AND LIMEY SECTOR
The Major was waiting for us up the “road.” He informed us that the
156th Brigade was the alert brigade. We were not to pitch tents nor
unroll packs, but lie on our arms ready to reinforce the front line
division should occasion demand it. The barrage was due to start at
1 A. M.; at 5 A. M. the infantry was to go over the top.
I waded back with this gladsome news, and we lay in the mud and
wet leaves and shivered and wished we could smoke, and waited for
the show to start. Word had passed that there was a big French
railroad gun about 30 yards away, and a pleasant time was
anticipated by all.
At 1 A. M. the sullen jar of the usual cannonade was shattered by a
tremendous crash. And that crash lasted solid for four hours. I shall
not try to describe a real A-1 barrage to men who have been there.
The railroad gun came across according to plan too. Every five
minutes her mighty roar and scream would announce the departure
of a G. I. can towards Metz, and then would come the clanking of the
cars as the recoil drove the train back along the track against the
logs piled behind it. After an hour or so we got accustomed to the
barrage and the glare that lit up the sky ahead; but as often as we
drowsed off, the thunder of this mighty gun would shake the earth
beneath us, and jar us into consciousness.
The night wore on, and the gray morning light crept into the woods;
and still the thunder rolled unceasing. I watched the glow of my wrist
watch hand creep to five o’clock. There was a slight lull as the
artillery shifted to their rolling barrage schedule. Then she started up
again with renewed fury. We knew the doughboys were off. The A. E.
F. was starting its first show on its own. The overture was over, the
fiery curtain raised, the act begun; and we were awaiting our cue.
Morning broke, cloudy, but little or no rain, and about 7 o’clock it
quite cleared off. We made ourselves as comfortable as we could,
and prayed for our kitchen.
I went wading through the mud along the road to look for it. There
were several Marines about, belonging to the skeleton organization,
left behind to act as a nucleus in case a whole outfit was wiped out. I
passed a Marine lieutenant whose face looked familiar, and after a
moment recognized “Happy” Mason. He had been a cadet at V. M. I.
with me, and had helped me wind a red silk sash around my middle
for many a dress parade. It was a far cry from the Blue Ridge to the
Bois de la Rappe, and from dress parade to the St. Mihiel drive.
We had a glad reunion there in the mud, and he invited the “B” Co.
officers to share his breakfast. Their rolling kitchen, or “galley” as
they called it, was on hand, and they had hot coffee and peach
turnovers!
Those Marines were regular guys. When they heard our transport
wasn’t up yet, they turned to and fed as many of our men as they
could, until their supply ran out. They had been through the mill
before, at Chateau Thierry and Belleau Wood. As one of them said
“Better help the other fellow now. Tomorrow’s a hell of a way off
here.”
The Marines have had an awful lot of joshing, of course, about their
press agent stuff—“Ace high with the Satevepost,” and so on. But
these were certainly a fine bunch, and gave us a lift when we
needed it. Naturally, those of them who did the fighting did the least
of the blowing about it afterward.
The sun came out to look at the battle after awhile, and we got
warmed and partially dried. Also the kitchen arrived, and a hot dinner
was in prospect.
About 11 A. M. bulletins began arriving from the front, and were read
out to us. All objectives were being taken according to schedule, and
the number of prisoners and guns captured mounted by leaps and
bounds. We were not allowed out of the woods, but even from the
trees on the outskirts one couldn’t see much except a great cloud of
smoke and dust slowly rolling up the slope of a range of distant hills.
The wet exposure and irregular eating of half cooked food had
already started to tell on us. Dysentery was appearing; nearly all the
company suffered with constant diarrhoea from this time on.
The afternoon dragged on; still no call for the alert brigade. We were
allowed to pitch pup tents, but no fires were allowed; the wood was
too wet and smoky.
Night fell; we crawled into whatever shelter we had, and
surreptitiously smoked, and talked, and listened to the rumble of the
guns until we got to sleep.
At about 1:30 A. M. a battalion runner fell over my feet and lit on Lt.
Dunn. After a few hasty remarks we stopped for breath, and were
informed that the battalion was to form on the road right away. Stiff
and sleepy, I stumbled out into the dank night, routed out Chiaradio,
my staunch little runner and striker, and broke the glad news to
Robbins and the company runners. The woods were soon in a bustle
as we rolled packs, donned equipment, and filed out by platoons into
the mud of the road.
By 2 A. M. the battalion was standing ankle deep in the slushy mud
in column of squads, the Major at our head. Half an hour passed.
Not a sound except an occasional “su-luck-slosh,” as someone
shifted his heavy pack, or tried in vain to find a less liquid footing.
The leaden minutes dragged by. Three o’clock; no move. Half past
four—the company ahead moved off, and we sloshed along behind,
but only to the edge of the wood. Dawn broke—another gray and
misty dawn. Oh, that awful wait in that awful hole! It was quite light
before, at 5 o’clock, we finally moved out, and, splashing and sliding
over a muddy field, finally hit the road and were off toward the scene
of action.
As we were stretching the kinks out of our legs on a fairly good road,
we passed a U. S. Coast Artillery outfit; a 12-inch gun. Some of the
crew came out to the roadside from the emplacement, and Capt.
O’Brien recognized his old outfit, in which he had served as an
enlisted man years before.
On we go toward the distant booming of the guns. We wind around
hills, hike across a valley, over another long hill. Then the road runs
along the bottom of a long, long valley. During the ten-minute rests
we snatch a hasty breakfast from our reserve rations, with growls
from those who don’t get in on the jam.
Now we begin to see traces of the battle—an overturned wagon,
abandoned in the ditch; a train of ammunition trucks crossing the
road ahead of us; a motor truck repair shop, hastily set up in a little
cabin along the road, from which came a smell of hot coffee that
tantalized our cold stomachs. Further on we passed a field hospital;
great white tents pitched in a sheltered dell, with red crosses glaring
on the tent flies.
At the next halt, a Ford ambulance came down the muddy road with
a load of wounded. It stopped by us, and the driver went around
behind to see to one of the occupants. The canvas curtain was
pushed aside from the top, and a head lolled out—a face of ghastly
yellow paste, surrounded by dirty light brown hair. The poor chap
was evidently badly gassed. He retched violently time and again,
spat out some blood, stared vacantly at us with glassy, miserable
eyes. The driver put the head inside with a kindly “All right, buddy;
nearly there now;” and the old Henry started off again with a jerk,
and a groan from within.
As we resumed the march, a youngster from the 5th Division
overtook us. He wore an M. P.’s brassard, and no equipment but a
.45 and a canteen. We with our heavy packs and ammunition envied
him. He was sleepy eyed and jaded, but still enthusiastic. Ever since
the drive started he had been on the job escorting prisoners from
front line division headquarters to the pens in the rear.
By 9 o’clock we had done twelve miles under our full pack,
ammunition, and two days’ rations, with a breakfast of a little corned
willy and hard bread and chlorinated water; the whole preceded by
three hours’ standing in eight inches of liquid mud. We felt pretty well
done in, for a fact. The auto riflemen were the worst off, having their
heavy Chauchats and several big magazines of ammunition besides.
One of them lightened his load by the ingenious means of
“forgetting” his bag of magazines at a halt. When Lt. Schuyler
discovered it, the culprit was promptly accommodated with a double
dose to carry.
But this was the exception. As I shifted about, hiking first with one
platoon and then another, I always found a set of determined grins,
and a cheerful “Oh, we’re all right. How’s the rabble up ahead?”
We had been passing through the rear area of the former Allied
sector. Now and again a trench system—trenches, barbed wire,
emplacements, all complete—stretched away on either hand. Here
and there were great stretches of barbed wire filling gullies and
ravines.
At 10 o’clock we crossed a stone bridge and started up a long, long
hill. At the top we found that we were on a ridge that had been the
front line before the attack. Shell holes covered the whole place. To
our left, the ground fell away in a long dip, and we saw the ground
over which the first wave had attacked. The battle was now far away
over the horizon.
For a couple of kilos we hiked along the road on top of the ridge. It
had already been repaired roughly, and all sorts of traffic was
passing over it. Once it had been bordered with trees, set at regular
intervals, like most self respecting French roads. Now only a
shattered, blasted stump stood here and there.
A few men began to straggle from the outfits ahead, but “B” Co.
stuck to it gamely. On that day not a man fell out.
Now we drew near a large barbed wire enclosure filled with men. It
was a P. W. pen, where prisoners were collected on their way to the
rear. A couple of detachments of them were going in as we came by.
We turned off here to the left, toward the front. About a kilo down this
road we hit a traffic jam—a regular one. This road was badly cut up,
and poor road discipline soon did the rest. Some truck or ambulance
had tried to pass another, and both had stalled. Others, arriving from
both directions, instead of lining up behind on the right of the road,
pressed up as far as they could go, until the road was so completely
jammed that even we on foot could not get through. Belts of barbed
wire that ran up to the road on either side prevented us from going
around. So there we were.
It was a most cosmopolitan collection. French 75’s, Ford
ambulances, a general’s Cadillac, rubbed shoulders with lumbering
lorries, sturdy steel ammunition Quads, and limbers. A French
transport wagon driver cracked his long whip and argued volubly
with the chauffeur of a tank, who spat and regarded him
contemplatively. Field kitchens, huddled in the jam, held the food that
was so desperately needed up front.
At last a Colonel of Marines blew in from somewhere, and plunged
into the mess. He got it thinned out enough for us to filter through on
the outskirts. And then—Glory be—we turned off the road into an
open space, with no barbed wire and comparatively few shell holes.
Here we found part of the 312th Inf., and the battalion stacked arms
and fell out.
We slipped off our packs, and fell to on monkey meat and hard
bread with a will. The sun had come out, and we lay around and
soon got warm and dry, and felt nearly human again.
All too soon we fell in, and set off again. We threaded our way
across the jam—now nearly as bad as ever—and spent the
afternoon drifting down a little valley at right angles to the road we
had just left. Nobody seemed to know just where we were going, or
why. We heard later that a jumbled order somewhere between
Division and Brigade Hdqs. had caused us to spend this day in a
wild goose chase.
The Colonel and Regt’l Hdq. had not been seen since the morning.
We hiked a few hundred yards, waited awhile, then moved on a bit
again. We passed, and were in turn passed by artillery, supply trains,
infantry. We sweated and chafed under our burdens, and wondered
what t’ell, but supposed it was all part of the game.
At last, about 6 P. M., we came to the head of the valley. There we
spied the Colonel and his car, on a road up on the top of the hill. We
climbed up to the road, pushing a stalled rolling kitchen ahead of us.
We were urged to “Step out,” and showed our military discipline and
Christian forbearance by not saying what we thought of this request.
We got on a good road that led over the hill and up toward the front.
Along this we hiked a little way, then turned off to the left, and up a
lumber road that led straight up the hill into the woods. It was nearly
dark; the road was so steep that I could never understand how six
inches of liquid mud stayed on it. The climb up this road soon put our
feet into their usual muddy and wet condition. We turned off into the
woods, the Bois de Hoquemont, and were told that we would
bivouac here for the night.
Our kitchens pulled up along the main road shortly, and the cooks,
tired as they were, got to work at once. The rations consisted mostly
of dehydrated vegetables. They say they are good if you can soak
them for twenty-four hours. A stew and coffee were soon under way.
I toiled back up the hill and found a message to report at once to the
regt’l commander. On a hunch, I had Schuyler get a detail out and
bring up the chow right away. Sure enough, at the officers’ meeting
we were ordered to make combat packs and be ready to move again
in twenty minutes. We got our coffee and slum, though; and the half
cooked stuff tasted pretty good at that.
Then we again donned our equipment, and plashed down the sloppy
road on weary feet. The night was very dark, and the road, as usual,
jammed with transport, our kitchens among others. As we threaded
our way through, we got mixed up somehow with a company of
Marines going in the same direction. Finally the jam thinned out, and
we turned off on another road, though we had to sort out B company
and the Marines almost man by man. And so we plodded on.
It is remarkable how much a man can do after he thinks he is all in.
We picked ’em up and put ’em down for three hours. At last we drew
near some woods. Our orders were to proceed to Bois d’Euvezin
and bivouac, and show no lights. Well, we couldn’t see a map, and
didn’t know where we were on one anyhow, so this wood looked
pretty good. At any rate, we turned off the road and headed for it.
Easy enough for a staff officer to look at a map and say, “Bivouac in
these woods.” Unfortunately, there was a 30 foot belt of wire fringing
this particular one. Orders are orders, though, so we scrambled
through somehow, and pushed in far enough to hide from any further
marching orders that night. Then we flopped down, any place at all,
and dropped off.
It seemed but a couple of minutes before the sun came prying
through the leaves and under my eyelids. I rolled over, and saw Lt.
Col. Budd, sitting up with his back against a tree, wrapped in his
trench coat—no better off than we were. Right away my morale went
up.
An American outfit is never so weary that it doesn’t furnish a few
inquisitive souls. Already curiosity was driving the doughboys out of
the woods, by two’s and three’s, to see what was around. Just over a
knoll they found a little fragment of history. A German machine gun,
cunningly camouflaged; across it the body of a big “Feldwebel,” or
German top sergeant, with a bayonet wound through his body; a
couple of yards away a dead Marine, riddled with machine gun
bullets, still grasping his rifle with the bloody bayonet fixed.
At 9 A. M. the outfit was rounded up, and we were off again. As we
plugged along the road in column of squads we thought with some
disgust of the night marches we had made a hundred kilos behind
the lines. Fortunately this hike was short. In an hour we entered
another and larger wood, the Bois d’Euvezin sure enough, this time.
Here we found the rest of the brigade, and bivouacked in the woods
just off the road.
The woods were full of German dugouts, evacuated by the enemy
only a day or so before. Most of these were preempted by various
headquarters. We settled down to make the most of our rest. For a
wonder the sun was out; and despite the mud under foot, we were
soon fairly warm and dry—and oh, how hungry! It was well along in
the afternoon before the water carts pulled in, though, and we got
our hot slum and coffee.
The Y. M. C. A. kicked through with a canteen, and after some
trouble in keeping the men from mobbing the place, crackers,
chocolate and tobacco were sold.
That night our gas training blossomed forth again. The Boche
dropped a couple of shells around and our over-anxious sentries
promptly bawled “Gas!” The alarm would be taken up and spread
through the brigade, and by the time things quieted down they were
off again. We finally got some sleep by the primitive but effective
expedient of promising to blow the head off the next guy that raised
the cry.
Next day a great bunch of orders were dumped on me to read—all
about the new censorship regulations. After wading through these,
the officers were summoned to go up on a reconnoitering party to
look over the sector which we were to take over that night.
We set out, and after a couple of hours’ stiff hiking arrived at a very
elaborate system of dugouts, in the edge of a wood, the Bois St.
Claude. Here was the Regt’l Hdq. of the 61st Infantry, 5th Division,
which we were to relieve. About five hundred meters north lay the
little village of Vieville-en-Haye. Descriptions of this charming hamlet
are superfluous, as we all had plenty of opportunity to contemplate it
thereafter.
It was early afternoon, and the Boche was behaving rather well; only
occasionally slamming an .88 into the village in a perfunctory sort of
way. From the northeast, however, came an intermittent crackle of
rifle and machine gun firing, where the outposts were snarling and
chattering away at each other.
We sat around for an hour while the regt’l hdq’s made their
arrangements. I found out that the C. O. of the 61st was an old friend
of my father’s—his father had been in my father’s company at V. M.
I. in the Civil War.
At last the dope filtered down to the Co. Cmdrs., and we were given
ten minutes to reconnoiter our positions. We then had to make haste
back to the regiment, so that we could be ready to start again at
dark. Packs were made, the platoons gathered together, and at 7:30
P. M. we filed out onto the road and were off on the last lap of our
journey to the battle line.
Hardly were we clear of the woods when we halted, for some
unknown reason. We sat and lay on the grass by the roadside,
among shell holes, and listened to the drone of airplanes above us. It
was an eerie, ominous sound; and though we were pretty sure the
motors were not the deep voiced monsters of the enemy, still we
were relieved when they drew off without dropping any H. E. into our
midst.
In half an hour we started, this time in earnest. It was rough going,
and blind work at best. We stumbled up a ravine, out onto a road,
skirted a wood lined with artillery, and so drew near our position
south of Vieville-en-Haye.
The 1st battalion was in support, the 2nd holding the front line, and
the 3rd brigade reserve. I never did know where the battalion was
that we were relieving. A and B Cos., however, were to hold the crest
of a slight swell of the ground about 300 meters south of the village.
Trenches there were none; but there were plenty of shell holes, and
the company was posted so as to command the terrain in front with
Chauchat and rifle fire; two or three men to a shell hole. The 4th
platoon found a little stretch of trench which they improved for
themselves. A Co. was on our left; C and D Cos. were posted about
700 meters to our right rear, behind Regt’l Hdq.
We had gotten pretty well settled, when just before dawn a battalion
runner came up, with the cry that haunted me day and night,
“Commanding Officer, B Co.” Hard on his heels came the Major. Two
companies of the 2nd battalion had lost their way and were
temporarily missing, and B Co. was to go up and hold the line of
resistance at once.
So B Co. was routed out of its bivvies, and donned packs and
ammunition, and set off in double file. I was to report to the C. O. of
the 61st Inf. front line battalion at Vieville.
We hiked down to the road, and up to where the houses began; then
through a spacious barn, climbing over a dead horse, and arriving
finally at the northern outskirts of the town. Not finding the Bn. Hdq. I
had the company take what cover they could in the road and barn
while the Major and I strolled up to the top of the hill beyond to have
a look ’round.
Near the top of this long hill were two German concrete pillboxes,
nicely turfed over. We found one of these occupied as a first aid
post; in the other we found a machine gun company hdq. Nobody
knew any dope about where we were wanted, but they said that Bn.
Hdq. was about a kilo away to the right.
Just then Heinie started his morning strafe of Vieville-en-Haye.
Three or four whiz bangs came hurtling over our heads, and landed
in the east end of the village, right where B Co. was lying. I saw no
necessity of our doing a Casabianca, and hastily obtained
permission from the Major to take B Co. back to its former position
until we knew where to go. As I shuffled down the hill, hitting the dirt
now and then when one landed close by, I chanced to look back just
in time to see a shell hit the first aid pillbox and pivot it neatly around,
so that the door faced us instead of the enemy. It didn’t take long to
start B Co. toward our bivvies, very much disgusted with the
morning’s work, but glad to stop playing target for a while.
Fortunately, no one was hit.
The 2nd Battalion located its wandering sheep later in the day, so we
were not called on for that errand again.
The regiment’s task was now to organize and strengthen our sector
of the line. The main line of resistance, as indicated on the map, was
being held and dug in by three Cos. of the 2nd Battalion, H Co.
holding the outpost line about two kilos in advance.
Our kitchens were established in the woods behind Regt’l Hdq., and
started work on the old standby, slum. The rough roads leading into
these woods were all ankle deep in mud, and the ration detail wasn’t
any bed of roses.
The day we spent in deepening our bivvies as best we could, though
our intrenching tools made little impression on the hard and stony
ground. Whoever salvaged a man-sized pick or shovel was lucky.
While it was light, we kept down under cover as much as possible,
for the German observation balloons were peeping sinisterly over the
horizon, and we didn’t care about drawing attention to our position.
On Wednesday, September 18th, at about 1 P. M., A and B Cos.
received orders to report to the Engineer Dump at 368.3-240.3, as a
working party. Several enemy observation balloons were up, and it
was a clear afternoon; but orders were orders, and off we filed.
At the dump we met an Engineer Lieutenant—very stout, very
bullheaded and very incompetent. I asked where we were to work,
and he replied he didn’t know—over there somewhere—pointing in
the general direction of Germany. Having had enough of that sort of
business in the morning, I told him to toddle right off and find out
where he was to take us. He got quite huffy at this, but finally set out,
and returned with some definite information. We drew picks and
shovels, and hiked away after him; I being forced to hurt his
importance again by refusing to march the company along in single
file on the sky line.
Our task was to dig a communication trench, already taped out, from
the point where the line of resistance entered the Bois Gerard back
over the brow of the hill. The first platoon was in plain view of the
enemy’s observation balloon, the other three were just behind the
rise.
We posted sentinels, and set to work, absolutely out in the open, no
cover save a few shell holes. For ten minutes we dug. Then it came.
A whistle, scream and slam, just over the hill; another; then a fierce,
deadly whir, right in our ears. We hit the dirt, and a second later Lt.
Dunn called to me “Captain, there’s a man killed here and I don’t
know how many wounded.”
For an instant of horror the company gazed at the spot. I sent Sgt.
Hill to the first aid pillbox for stretchers, put the others to work again,
and hastened up to see the situation. The shell had landed just
between the 1st and 2nd platoons. Lt. Schuyler was already having
the wounded carried into the edge of the woods near by, and had the
rest of the 1st platoon take cover there. Poor O’Hara was lying dead
right by the shell hole. It had burst nearly underneath him, and a
fragment of shell had torn its way through his temple and right out
through his steel helmet. His brains were oozing out through the
hole.
Seeing that nothing could be done for him, I went over to the woods.
Lester Farry, our mechanic, as fine a man as ever walked, was
sitting up between Lt. Schuyler and Sgt. Reid, with a big hole in the
side of his head. He never uttered a word of complaint; just sat still
while they bandaged it; and the stretchers came up and took him off.
He died in hospital six days later.
Curcio had a great hole in the upper part of his leg. Donohue had an
ugly bit of shell in his back, and Bogucki, Fielding, and Hauber were
wounded, but less seriously.
This was a nasty introduction to shell fire, because the whole
company saw the thing happen. Their behaviour, however, was
excellent. Doggedly the men continued at the work, and soon we
had enough cover to at least be in while the shells burst near by.
Our gallant friend, the Engineer Lieutenant, had promptly vanished,
and I never saw him again. I withdrew the first and second platoons
behind the hill, and we kept on the job until 6 P. M., as ordered. At
about 5:30, A Co. came along over the hill, and the Heinies sped
them on their way with a few gas shells, which made them scamper.
As we turned in our shovels at the dump, every man mustered up a
grin as he passed by; and though it had been one hell of a party, the
old morale was still on deck.
On the top of the knoll where our position was, the Germans had had
an anti-aircraft gun, gaudily camouflaged. Some cooks from an
artillery outfit had found a lot of ammunition belonging to it, and,
dragging it into Vieville, had amused themselves during the day by
shooting Fritz’s own H. E. in his general direction. This apparently
annoyed Fritz; and just as I got back to our bivvies at the tail of B
Co., two ash cans—whoppers—arrived at the gun’s former position,
right in the midst of A Co. Our comrades promptly departed to the
woods until the next morning.
The cooks sent up a good chow—steaks and coffee—and we got to
sleep in our holes as best we could.
The next day—Thursday, September 19th—was rainy. We dug our
shelters a little deeper, and wished this war thing were over. I found
a German translation of one of De Maupassant’s novels, which I
read through, but for the life of me I can’t remember a bit of the story.
In the afternoon the chaplain, Lt. Cressman, came around, and
O’Hara’s platoon was allowed to attend his burial service in the little
cemetery in the edge of the Bois St. Claude, east of Vieville.
In the meantime I had been called to Btn. Hdq., where Mr. Morse,
our faithful old “Y” man, had brought up some chocolate and
cigarettes. He was supposed by the regulations of the “Y” to sell
them, but he refused to take any money from the Co. Cmdrs. at first,
intending to account for them out of his own small pay. When we
understood this, we insisted on paying for the stuff out of the
company funds. The news got out that the “Y” was charging for
chocolate and tobacco, and caused some bitterness, under the
circumstances. But thereafter Mr. Morse made some arrangement
whereby the stuff was issued free.
As for Mr. Morse himself, I think we should here express something
of our appreciation of his faithful and unselfish devotion to the men of
the battalion. A man well past the prime of life, he shared our
hardships, hiked with us—not sticking like grim death to a Ford as
some of his confreres were prone to do—; slept in mud and rain with
us. Right under shell fire he would come plugging on up with his little
bag of smokes and chocolate. The Red Cross, the Salvation Army,
were only names to us. But the “Y,” which we cussed out so
frequently, surely did us proud when they gave us Mr. Morse.
That night the 1st, 3rd and 4th platoons went out as separate
working parties. Apparently the deaths of O’Hara and Farry had
demonstrated even to our friends the Engineers that sporting about
in sight of Hun balloons in the daytime was magnificent, but not war.
The Boche had the range, though, and shelled the area all night. The
1st platoon ran on an average schedule of dig two minutes and duck
five. The 3rd was in no better case, and Barney O’Rourke got an
ugly little piece of shell through his foot. He hobbled off between Hill

You might also like