Samples Hands-on code

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.

Where the Examples Live

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.

Available Examples

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

MegaGame

Core Syntax

A larger sample entry point intended to exercise application-level composition and reusable language-level building blocks.

klyn samples/MegaGame.kn

File Handling

Export XLSX

File Handling

Creates 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

GUI

Calculator

GUI

A 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 value-change events.

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 Demo

GUI

Shows slider variants: filled track, ticks, values, vertical orientation, and live value tooltip during pointer drag.

klyn samples/gui/DemoSlider.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

TUI

Breakout

TUI

A multi-file terminal game. It is useful for understanding how a larger Klyn sample is split into several classes and views.

klyn samples/Breakout/Breakout.kn

Terminal Resize

TUI

Focuses on terminal resize behavior and is useful when validating layout and event-loop behavior on a new platform.

klyn samples/TerminalResize.kn

Advanced Topics

SQL Login

Advanced Topics

A console MariaDB login flow using DriverManager, try-with-resources, and a prepared update statement.

klyn samples/sql/Login.kn

ORM Sample

Advanced Topics

Demonstrates the object-relational mapping layer and the shape of database-oriented Klyn code. It may require a configured database environment.

klyn samples/ORMSample.kn

LLM

Advanced Topics

Exercises the language-level LLM helpers. This sample normally requires provider configuration and valid credentials.

klyn samples/llm.kn

Financial

Advanced Topics

Shows an LLM-backed financial agent sample and is a good place to inspect how domain logic can be combined with agent-style helpers.

klyn samples/Financial.kn
Next Step

Continue with Lexical Structure to understand the source rules used by these examples, or open API Reference while reading their imports.