Code Examples
Klyn distributions include a samples directory with runnable examples. Use these
programs to explore the standard library, the terminal GUI layer, database access, and larger
application structure before starting your own project.
From a source checkout, examples are available in the repository-level samples
directory. Packaged Linux installations also install them under the Klyn home directory.
cd samples
klyn gui/Calculator.kn
When an example spans several files, launch its main file from the sample directory or use the path shown below. Klyn will resolve dependencies through its normal class-loading rules.
Examples are grouped with the same high-level categories and order as the tutorial sidebar. Each card tag shows the category it belongs to.
Core Syntax
Hello World Countdown
Core Syntax
A first Klyn program built as a launch countdown. It introduces an explicitly typed
variable, a while loop, decrementing, and console output before lift-off.
klyn samples/HelloWorld.kn
MegaGame
Core SyntaxA larger sample entry point intended to exercise application-level composition and reusable language-level building blocks.
klyn samples/MegaGame.kn
Types and OOP
POO
Types and OOPA compact shape hierarchy showing classes, constructors, inheritance, overriding, and polymorphic calls in idiomatic Klyn.
klyn samples/POO.kn
File Handling
JSON Game Configuration
File Handling
Stores typed game settings in a HashSet, writes them as a formatted JSON
array beside the sample, then reloads the file and reconstructs the set.
klyn samples/io/JsonConfig.kn
Export XML
File HandlingExports the people and monthly activity data from the XLSX example as a structured DOM document beside the sample, then parses the result back for verification.
klyn samples/io/ExportXML.kn
Export XLSX
File HandlingCreates an XLSX workbook with a people directory, a second activity worksheet, and a line chart based on the exported monthly values.
klyn samples/io/ExportXLSX.kn
Databases & Entities
SQL Login
Databases & Entities
A console MariaDB login flow using DriverManager, try-with-resources, and a
prepared update statement.
klyn samples/sql/Login.kn
Entities and KQL
Databases & EntitiesBuilds a MariaDB article catalog with the Klyn Entity Engine, creates its schema, persists demonstration entities transactionally, and executes typed KQL price queries from a desktop GUI. A configured MariaDB database is required.
klyn samples/sql/Entities.kn
GUI
Calculator
GUIA compact graphical application showing event handling, widgets, and simple interaction patterns.
klyn samples/gui/Calculator.kn
Speed Demo Window
GUI
A custom speedometer widget built with Canvas, gradients, antialiased
painting, sliders, and signal-property bindings.
klyn samples/gui/SpeedDemoWindow.kn
Clock Sample
GUI
An analog clock implemented as a custom Canvas widget. It combines gradients,
antialiased painting, time-based geometry, and a GUI Timer that repaints once
per second.
klyn samples/gui/ClockSample.kn
Slider Sample
GUIShows slider variants: filled track, ticks, values, vertical orientation, and live value tooltip during pointer drag.
klyn samples/gui/SliderSample.kn
DatePicker Sample
GUI
Shows the standard calendar popup and the quickEditMode workflow where the
user selects a year, a month, then a day.
klyn samples/gui/DatePickerSample.kn
File Dialogs
GUIDemonstrates typed modal lightboxes for opening one or more files, choosing a save destination, and selecting a folder inside the application window.
klyn samples/gui/FileDialogsSample.kn
Font Dialog
GUI
Lists operating-system fonts in an embedded lightbox with per-family previews and applies
the selected typed Font value to a widget.
klyn samples/gui/FontDialogSample.kn
Menu Bar Sample
GUIDemonstrates a desktop menu bar with File, Edit, and Help menus, mnemonic labels, shortcuts, icons, separators, and typed action events.
klyn samples/gui/MenuBarSample.kn
Terminal Widget
GUI
Embeds a TerminalWidget in a desktop window, demonstrates cwd tracking,
multi-tab terminals, and the compact singleTerminal mode.
klyn samples/gui/TerminalWidgetSample.kn
Browser Widget
GUIEmbeds a styled HTML document with asynchronous navigation, retained rendering, history, and deterministic DOM scripting.
klyn samples/gui/BrowserWidgetSample.kn
Login Form
GUI
A MariaDB-backed login window using FormLayout, password input, default-button
behavior, buddies, and prepared statements.
klyn samples/gui/LoginForm.kn
Color Picker
GUI
Demonstrates the reusable ColorPicker, its RGB, HSV, HSL, color-wheel
and spectrum modes, plus the standalone dialog and embedded lightbox hosts.
klyn samples/gui/ColorPickerSample.kn
Color Chooser
GUI
Shows Binding.twoWay between sliders and spin boxes, plus
Binding.watch to repaint a live color preview.
klyn samples/gui/ColorChooser.kn
Color Chooser 2
GUI
Refactors the color editor into reusable color lines that expose a bindable
value signal property, while keeping the live preview synchronized.
klyn samples/gui/ColorChooser2.kn
Database Explorer
GUIA larger GUI sample with a modal connection lightbox, split views, a schema tree, closable tabs, live database schema discovery, editable table models, read-only views, and an SQL editor with schema-aware completion.
klyn samples/gui/dbexplorer/DatabaseExplorer.kn
Graphical Breakout
GUIA resizable vector game built around one custom canvas, a fixed-step animation loop, direct mouse and keyboard input, four levels, brick effects, and falling bonuses.
klyn samples/gui/Breakout/Start.kn
TUI
Breakout
TUIA multi-file terminal game. It is useful for understanding how a larger Klyn sample is split into several classes and views.
klyn samples/tui/Breakout/Breakout.kn
Terminal Resize
TUIFocuses on terminal resize behavior and is useful when validating layout and event-loop behavior on a new platform.
klyn samples/tui/TerminalResize.kn
Cyber Snake
TUIA colorful terminal arcade game with keyboard input, animated food and particles, and responsive layout. Press Space to start, then steer with the arrow keys or WASD. Read the sample to see how a terminal widget combines input, game state, and rendering.
klyn samples/tui/Snake.kn
Advanced Topics
Structured Logging
Advanced TopicsUses a generic class logger, structured fields, scoped context, and a timed span while a multi-handler writes the same events to the console and a file beside the sample. See the Logging tutorial for configuration and handler details.
klyn samples/logging/MoonMissionLogs.kn
Performance Benchmark
Advanced TopicsRuns equivalent Python, Klyn, and C++20 programs three times, compares cold and warm Klyn startup, and generates a self-contained HTML performance report.
klyn samples/perf/Benchmark.kn
LLM
Advanced TopicsExercises the language-level LLM helpers. This sample normally requires provider configuration and valid credentials. See the LLM API and Agents tutorial for the underlying request model.
klyn samples/llm.kn
Financial
Advanced TopicsShows an LLM-backed financial agent sample and is a good place to inspect how domain logic can be combined with annotated tools and the agent loop described in the LLM API and Agents tutorial.
klyn samples/Financial.kn
Continue with Lexical Structure to understand the source rules used by these examples, or open API Reference while reading their imports.