# (DD01) Module: algo_Calc — Detailed Design [249 LOC]

## Module Overview
The `algo_Calc` module implements a Swing-based sorting algorithm calculator. It provides a simple GUI workflow where the user selects a sorting algorithm, enters a space-separated list of integers, and receives the sorted result in the output panel.

The module is centered on a single public entry class, `Sortingss`, which manages the application window, dispatches the UI based on a selected algorithm key, and performs the sorting logic inline through the submit action handler. The broader module also includes auxiliary sorting classes in the source tree, but the documented module inventory for this DD contains only `Sortingss`.

---

## Class: Sortingss

### Class Summary
| Field | Value |
|-------|-------|
| FQN | `algo_Calc.Sortingss` |
| Layer | Presentation / GUI controller |
| Methods | 3 |

`Sortingss` owns the main sorting window, exposes the application entry point, and coordinates the current algorithm context through the `vis()` method. The class stores the selected algorithm key and label, then uses those values when the user submits input from the second screen.

### Method: main(String[] args)

#### 1. Role
`main()` is the application bootstrap method. It starts the Swing UI on the Event Dispatch Thread and creates the primary `Sortingss` window instance.

This method is responsible only for startup orchestration and error reporting. It does not perform sorting itself.

#### 2. Processing Pattern
```mermaid
flowchart TD
A["main()"] --> B["EventQueue.invokeLater"]
B --> C["Create Sortingss instance"]
C --> D["Call constructor"]
D --> E["initialize()"]
E --> F["Show frame"]
```

#### 3. Parameter Analysis
| Parameter | Type | Meaning | Notes |
|-----------|------|---------|-------|
| `args` | `String[]` | Command-line arguments | Present for Java entry-point compatibility; the implementation does not inspect them. |

#### 4. CRUD Operations / Called Services
| Target | Operation | Purpose |
|--------|-----------|---------|
| `EventQueue` | C | Schedules UI creation on the Swing thread. |
| `Sortingss` | C | Creates the main application window. |
| `JFrame` | U | Makes the frame visible after construction. |
| `Throwable#printStackTrace` | R | Reports startup failures to the console. |

#### 5. Dependency Trace
| Entry Point | Next Hop | Notes |
|-------------|----------|-------|
| JVM launch | `main()` | Standard Java entry point. |
| `main()` | `EventQueue.invokeLater()` | Ensures GUI initialization happens safely on the Swing thread. |
| `EventQueue.invokeLater()` | `new Sortingss()` | Creates the UI controller instance. |
| `new Sortingss()` | `initialize()` | Builds widgets and configures the frame. |

#### 6. Per-Branch Detail Blocks
- **Thread scheduling branch**
  - The runnable is queued on the Event Dispatch Thread rather than executed immediately.
  - This protects Swing component creation from threading issues.
- **Construction success branch**
  - A `Sortingss` object is instantiated.
  - The frame is initialized and shown.
- **Exception branch**
  - Any exception during startup is caught.
  - The stack trace is printed and the UI may remain unavailable.

---

### Method: Sortingss()

#### 1. Role
The constructor initializes the instance and immediately delegates to the UI setup routine. Its job is to ensure the window state is ready as soon as the object is created.

This method does not contain business logic. It acts as the object lifecycle bridge between instantiation and frame construction.

#### 3. Parameter Analysis
| Parameter | Type | Meaning | Notes |
|-----------|------|---------|-------|
| None | - | - | The constructor takes no arguments. |

#### 4. CRUD Operations / Called Services
| Target | Operation | Purpose |
|--------|-----------|---------|
| `initialize()` | C | Builds the GUI and component tree. |

#### 5. Dependency Trace
| Entry Point | Next Hop | Notes |
|-------------|----------|-------|
| `main()` | `new Sortingss()` | Constructor is invoked during application startup. |
| `new Sortingss()` | `initialize()` | The frame and widgets are prepared immediately. |

#### 6. Per-Branch Detail Blocks
- **Normal construction branch**
  - The constructor calls `initialize()` once.
  - No conditional branching is present.

---

### Method: vis(int k, String str)

#### 1. Role
`vis()` activates the algorithm context for the secondary window. It records the selected sorting mode through the `key` field and updates the title/label text through `tname`.

The method is called from the main menu buttons in the companion `Frame` class. Its practical effect is to make the next screen visible and preserve enough state for the submit action to choose the correct sorting routine.

#### 2. Processing Pattern
```mermaid
flowchart TD
A["vis(k, str)"] --> B["Store key"]
B --> C["Set temporary label text"]
C --> D["Assign selected label"]
D --> E["Make frame visible"]
E --> F["Return 0"]
```

#### 3. Parameter Analysis
| Parameter | Type | Meaning | Notes |
|-----------|------|---------|-------|
| `k` | `int` | Selected algorithm key | Encodes which sort routine should run later in the submit handler. |
| `str` | `String` | Display label for the selected algorithm | Used as the current title/marker for the UI context. |

#### 4. CRUD Operations / Called Services
| Target | Operation | Purpose |
|--------|-----------|---------|
| `key` field | U | Stores the selected algorithm identifier. |
| `tname` field | U | Stores the active label text. |
| `JFrame#setVisible(true)` | U | Shows the GUI window. |

#### 5. Dependency Trace
| Entry Point | Next Hop | Notes |
|-------------|----------|-------|
| `Frame` button listeners | `vis(k, str)` | The main menu uses this method to switch to the sorting window. |
| `vis(k, str)` | `frame.setVisible(true)` | Displays the target frame for user input. |

#### 6. Per-Branch Detail Blocks
- **State assignment branch**
  - The selected key is stored in `key`.
  - `tname` is overwritten several times before ending with the provided string.
- **Visibility branch**
  - The frame is shown unconditionally.
- **Return branch**
  - The method returns `0` as a placeholder result value.

---

## Class Interaction Summary
| Source | Target | Interaction |
|--------|--------|-------------|
| `main()` | `Sortingss()` | Creates the GUI controller. |
| `Sortingss()` | `initialize()` | Builds the UI. |
| `Frame` | `vis(int, String)` | Passes the selected algorithm choice to the sorting window. |
| `vis(int, String)` | `frame` | Makes the sorting window visible. |

## Key Design Notes
- The class follows a GUI-controller style design rather than a service-oriented design.
- Algorithm selection is represented by an integer key, which is later used by the submit action in the UI to decide which sort to execute.
- The class keeps mutable state (`key` and `tname`) so the selected mode can be preserved across screen transitions.
- UI construction is performed eagerly in the constructor, which keeps object creation tightly coupled with window setup.
