# (DD02) Business Logic — UI.panel() [24 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.github.blaxk3.ui.UI` |
| Layer | Utility / Presentation |
| Module | `ui` (Package: `com.github.blaxk3.ui`) |

## 1. Role

### UI.panel()

`panel()` constructs the main Swing container used by the `UI` window and assembles the visual layout for the currency converter screen. It creates a root panel, then groups the input controls into two horizontal sub-panels so the amount, source currency, target currency, label, and action buttons are presented in a structured way. This method follows a UI composition pattern: it delegates the creation of individual widgets to helper methods (`textField()`, `comboBox1()`, `label()`, `comboBox2()`, and `button()`) and only handles orchestration and layout assembly. In business terms, it is the screen composition entry point for the converter workspace and defines how the user interacts with the conversion workflow. There is no branching logic in this method; every invocation builds the same two-section layout and returns the completed Swing component tree.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["panel()"]
    STEP1["Create root JPanel framePanel"]
    STEP2["Set framePanel layout to BoxLayout Y_AXIS"]
    STEP3["Create top panel panelFramePanel1"]
    STEP4["Set panelFramePanel1 background to Color.DARK_GRAY"]
    STEP5["Set panelFramePanel1 layout to FlowLayout.CENTER"]
    STEP6["Add textField() component"]
    STEP7["Add comboBox1() component"]
    STEP8["Create lower panel panelFramePanel2"]
    STEP9["Set panelFramePanel2 layout to FlowLayout.CENTER"]
    STEP10["Add label() component"]
    STEP11["Add comboBox2() component"]
    STEP12["Set panelFramePanel2 background to Color.DARK_GRAY"]
    STEP13["Add button()[0]"]
    STEP14["Add button()[1]"]
    STEP15["Add button()[2]"]
    STEP16["Add panelFramePanel1 to framePanel"]
    STEP17["Add panelFramePanel2 to framePanel"]
    END_NODE["Return framePanel"]
    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> STEP5
    STEP5 --> STEP6
    STEP6 --> STEP7
    STEP7 --> STEP8
    STEP8 --> STEP9
    STEP9 --> STEP10
    STEP10 --> STEP11
    STEP11 --> STEP12
    STEP12 --> STEP13
    STEP13 --> STEP14
    STEP14 --> STEP15
    STEP15 --> STEP16
    STEP16 --> STEP17
    STEP17 --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

External state read by the method:
- No method parameters are accepted.
- The method does not read instance fields directly, but it invokes helper methods that initialize and assign the screen components (`textField`, `comboBox1`, `label`, `comboBox2`).
- The method depends on Swing layout and component classes to build the container hierarchy.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `UI.button` | UI | - | Calls `button` in `UI` |
| - | `UI.comboBox1` | UI | - | Calls `comboBox1` in `UI` |
| - | `UI.comboBox2` | UI | - | Calls `comboBox2` in `UI` |
| - | `UI.label` | UI | - | Calls `label` in `UI` |
| - | `UI.textField` | UI | - | Calls `textField` in `UI` |

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `textField()` | UI | - | Creates and returns the amount input field for the converter form |
| R | `comboBox1()` | UI | - | Creates and returns the source-currency selector |
| R | `label()` | UI | - | Creates and returns the result display label |
| R | `comboBox2()` | UI | - | Creates and returns the target-currency selector |
| R | `button()` | UI | - | Creates and returns the action buttons used by the converter screen |

`panel()` does not perform persistence CRUD against a database. Its only business effect is presentation assembly and delegation to other UI-building methods.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen/UI constructor | `UI.UI()` -> `UI.panel()` | `textField() [R] -` |
| 2 | Screen/UI constructor | `UI.UI()` -> `UI.panel()` | `comboBox1() [R] -` |
| 3 | Screen/UI constructor | `UI.UI()` -> `UI.panel()` | `label() [R] -` |
| 4 | Screen/UI constructor | `UI.UI()` -> `UI.panel()` | `comboBox2() [R] -` |
| 5 | Screen/UI constructor | `UI.UI()` -> `UI.panel()` | `button() [R] -` |

The direct caller is the `UI` constructor, which immediately inserts the assembled component into the frame via `add(panel())`. The method then cascades into helper methods that build the child controls for the screen. No external screen, batch, or service class calls `panel()` in the current source set.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL] `(panel assembly start)` (L70)

> Creates the root container for the currency converter screen.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel framePanel = new JPanel();` |
| 2 | EXEC | `framePanel.setLayout(new javax.swing.BoxLayout(framePanel, javax.swing.BoxLayout.Y_AXIS));` |

**Block 2** — [SEQUENTIAL] `(build top input section)` (L73)

> Builds the first horizontal row that captures the amount and source currency.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel panelFramePanel1 = new JPanel();` |
| 2 | EXEC | `panelFramePanel1.setBackground(Color.DARK_GRAY);` [-> Color.DARK_GRAY="dark gray UI theme"] |
| 3 | EXEC | `panelFramePanel1.setLayout(new FlowLayout(FlowLayout.CENTER));` |
| 4 | CALL | `textField();` |
| 5 | EXEC | `panelFramePanel1.add(textField());` |
| 6 | CALL | `comboBox1();` |
| 7 | EXEC | `panelFramePanel1.add(comboBox1());` |

**Block 3** — [SEQUENTIAL] `(build bottom action section)` (L79)

> Builds the second horizontal row that shows the result label, target currency selector, and command buttons.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel panelFramePanel2 = new JPanel();` |
| 2 | EXEC | `panelFramePanel2.setLayout(new FlowLayout(FlowLayout.CENTER));` |
| 3 | CALL | `label();` |
| 4 | EXEC | `panelFramePanel2.add(label());` |
| 5 | CALL | `comboBox2();` |
| 6 | EXEC | `panelFramePanel2.add(comboBox2());` |
| 7 | EXEC | `panelFramePanel2.setBackground(Color.DARK_GRAY);` [-> Color.DARK_GRAY="dark gray UI theme"] |
| 8 | CALL | `button();` |
| 9 | EXEC | `panelFramePanel2.add(button()[0]);` |
| 10 | CALL | `button();` |
| 11 | EXEC | `panelFramePanel2.add(button()[1]);` |
| 12 | CALL | `button();` |
| 13 | EXEC | `panelFramePanel2.add(button()[2]);` |

**Block 4** — [SEQUENTIAL] `(compose final container)` (L88)

> Stacks the two sub-panels vertically and returns the completed component tree.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `framePanel.add(panelFramePanel1);` |
| 2 | EXEC | `framePanel.add(panelFramePanel2);` |
| 3 | RETURN | `return framePanel;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `framePanel` | Field/Local | Root UI container that holds the complete currency converter form |
| `panelFramePanel1` | Local component | Top input row that groups the amount field and source currency selector |
| `panelFramePanel2` | Local component | Lower action row that groups the result label, target currency selector, and buttons |
| `textField` | Method/Component | Amount entry field where the user types the value to convert |
| `comboBox1` | Method/Component | Source currency selector |
| `comboBox2` | Method/Component | Target currency selector |
| `label` | Method/Component | Result display label used to show the converted amount or status message |
| `button` | Method/Component factory | Creates the action buttons for conversion-related actions |
| `Color.DARK_GRAY` | UI constant | Dark gray visual theme used for the panel backgrounds |
| `FlowLayout.CENTER` | Layout constant | Centers child controls horizontally inside a panel |
| `BoxLayout.Y_AXIS` | Layout constant | Stacks the two sub-panels vertically |
| Swing | Technical term | Java desktop UI toolkit used to render the window and controls |
| Component | Technical term | Base UI element type returned by the method |
| Currency converter | Business term | Screen that converts a monetary amount from one currency to another |
