---

# (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()

This method constructs the main Swing container for the currency converter screen and assembles the visual layout used by the `UI` window. It does not perform any monetary conversion logic itself; instead, it acts as a presentation composition method that groups the input area, currency selectors, result display, and action buttons into a single root component.

From a business perspective, the method creates the working surface for a user who wants to enter an amount, choose a source currency and a target currency, view the converted result, and trigger one of the available actions. The first branch of the layout is the input selection area, which contains the amount field and the source-currency selector. The second branch is the output/action area, which contains the result label, the destination-currency selector, and three actions: Convert, Swap, and Clear.

The method follows a simple routing-and-composition pattern: it delegates the creation of each subcomponent to helper methods (`textField()`, `comboBox1()`, `label()`, `comboBox2()`, and `button()`), then aggregates them into two child panels and returns the fully assembled parent panel. In the larger system, this is the shared entry point that the `UI` constructor adds to the frame, so it is effectively the root screen fragment for the application window.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["panel()"])
    FP1(["Create framePanel and set BoxLayout Y_AXIS"])
    P1(["Create panelFramePanel1"])
    BG1(["Set panelFramePanel1 background to Color.DARK_GRAY"])
    L1(["Set panelFramePanel1 layout to FlowLayout CENTER"])
    T1(["Call textField()"])
    C1(["Call comboBox1()"])
    P2(["Create panelFramePanel2"])
    L2(["Set panelFramePanel2 layout to FlowLayout CENTER"])
    LB(["Call label()"])
    C2(["Call comboBox2()"])
    BG2(["Set panelFramePanel2 background to Color.DARK_GRAY"])
    B0(["Call button()[0] - Convert"])
    B1(["Call button()[1] - Swap"])
    B2(["Call button()[2] - Clear"])
    A1(["Add panelFramePanel1 to framePanel"])
    A2(["Add panelFramePanel2 to framePanel"])
    END(["Return framePanel"])

    START --> FP1
    FP1 --> P1
    P1 --> BG1
    BG1 --> L1
    L1 --> T1
    T1 --> C1
    C1 --> P2
    P2 --> L2
    L2 --> LB
    LB --> C2
    C2 --> BG2
    BG2 --> B0
    B0 --> B1
    B1 --> B2
    B2 --> A1
    A1 --> A2
    A2 --> END
```

## 3. Parameter Analysis

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

External state read by the method:
- `this.textField` is created indirectly by `textField()` and then stored for later use by action handlers elsewhere in the class.
- `this.comboBox1` is created indirectly by `comboBox1()` and populated asynchronously by `CurrencyCode`.
- `this.comboBox2` is created indirectly by `comboBox2()` and populated asynchronously by `CurrencyCode`.
- `this.label` is created indirectly by `label()` and is used later to display the conversion result.

## 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` |

Analyze all method calls within this method and classify each as a CRUD operation.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `UI.textField` | UI | - | Creates the amount input field component used by the converter screen |
| R | `UI.comboBox1` | UI | - | Creates the source-currency selector component |
| R | `UI.label` | UI | - | Creates the result display label component |
| R | `UI.comboBox2` | UI | - | Creates the destination-currency selector component |
| R | `UI.button` | UI | - | Creates the action button set for Convert, Swap, and Clear |

## 5. Dependency Trace

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen: `UI` constructor | `UI.<init>()` -> `add(panel())` -> `UI.panel()` | `button [R] -`, `comboBox1 [R] -`, `comboBox2 [R] -`, `label [R] -`, `textField [R] -` |

The only direct caller identified in the source is the `UI` constructor, which embeds the assembled panel into the main application frame. This method then delegates to five internal helper methods that each create one UI component, so its terminal effects are limited to component construction and layout composition rather than database or service access.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] (L70-L71)

> Build the root container for the converter form and set it to a vertical stack layout.

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

**Block 2** — [SEQUENCE] (L73-L77)

> Build the first row of the screen for amount entry and source-currency selection.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel panelFramePanel1 = new JPanel();` |
| 2 | EXEC | `panelFramePanel1.setBackground(Color.DARK_GRAY);` [-> `Color.DARK_GRAY`="dark gray"] |
| 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** — [SEQUENCE] (L79-L86)

> Build the second row of the screen for the result display, target-currency selection, and action 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"] |
| 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** — [SEQUENCE] (L88-L91)

> Attach both rows to the root panel and return the assembled component.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `panel` | Method | Builds the main screen container for the currency converter UI |
| `framePanel` | Component | Root panel that holds the full converter layout |
| `panelFramePanel1` | Component | Upper input panel for amount entry and source currency selection |
| `panelFramePanel2` | Component | Lower action/output panel for result display, target currency selection, and buttons |
| `textField` | Component field | Amount entry field where the user types the foreign-currency value to convert |
| `comboBox1` | Component field | Source-currency dropdown selector |
| `comboBox2` | Component field | Destination-currency dropdown selector |
| `label` | Component field | Output label used to display the converted amount |
| `Convert` | UI action | Triggers conversion using the selected currencies and entered amount |
| `Swap` | UI action | Swaps the source and destination currency selections |
| `Clear` | UI action | Clears the amount entry and displayed result |
| `Color.DARK_GRAY` | UI constant | Dark gray background styling used for the two main panels |
| `FlowLayout.CENTER` | UI constant | Centers the children within each row panel |
| `BoxLayout.Y_AXIS` | UI constant | Stacks the two row panels vertically |
| `CurrencyRateAPI` | Class | API client used elsewhere in the UI to fetch live exchange-rate data |
| `SwingWorker` | Technical term | Background worker pattern used elsewhere in the UI to load currency codes asynchronously |
| `JPanel` | Technical term | Swing container used to group controls into layout regions |
| `JComboBox` | Technical term | Dropdown component for selecting a currency code |
| `JTextField` | Technical term | Editable text input component for entering the amount |
| `JLabel` | Technical term | Read-only display component for the conversion result |
