---
# (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 builds the main Swing container used by the `UI` frame and arranges the screen into two horizontally centered content bands stacked vertically. In business terms, it prepares the user-facing currency conversion workspace by assembling the input area, the currency selection controls, the result display area, and the action buttons into a single reusable panel. The method follows a composition / routing pattern: it does not implement conversion logic itself, but delegates UI element creation to helper methods (`textField()`, `comboBox1()`, `label()`, `comboBox2()`, and `button()`) and embeds their returned components into the layout. The first band is the input section for entering an amount and selecting the source currency, while the second band is the output-and-actions section for viewing the converted amount, selecting the target currency, and executing UI actions such as convert, swap, and clear. There are no conditional branches in this method; its behavior is deterministic and always builds the same two-panel structure before returning the root container. As a result, it serves as the frame-level assembly entry point for the presentation layer and provides the visual structure that other UI methods populate with business functionality.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["panel()"])
    N1["Create root JPanel framePanel"]
    N2["Set framePanel layout to BoxLayout Y_AXIS"]
    N3["Create first child JPanel panelFramePanel1"]
    N4["Set panelFramePanel1 background to Color.DARK_GRAY"]
    N5["Set panelFramePanel1 layout to FlowLayout CENTER"]
    N6["Add textField() to panelFramePanel1"]
    N7["Add comboBox1() to panelFramePanel1"]
    N8["Create second child JPanel panelFramePanel2"]
    N9["Set panelFramePanel2 layout to FlowLayout CENTER"]
    N10["Add label() to panelFramePanel2"]
    N11["Add comboBox2() to panelFramePanel2"]
    N12["Set panelFramePanel2 background to Color.DARK_GRAY"]
    N13["Add button()[0] to panelFramePanel2"]
    N14["Add button()[1] to panelFramePanel2"]
    N15["Add button()[2] to panelFramePanel2"]
    N16["Add panelFramePanel1 to framePanel"]
    N17["Add panelFramePanel2 to framePanel"]
    END(["Return framePanel"])
    START --> N1
    N1 --> N2
    N2 --> N3
    N3 --> N4
    N4 --> N5
    N5 --> N6
    N6 --> N7
    N7 --> N8
    N8 --> N9
    N9 --> N10
    N10 --> N11
    N11 --> N12
    N12 --> N13
    N13 --> N14
    N14 --> N15
    N15 --> N16
    N16 --> N17
    N17 --> END
```

## 3. Parameter Analysis

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

External state read by the method: none directly. The method creates and configures Swing containers locally and delegates component creation to helper methods on the same class.

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

This method does not perform CRUD against a database or service endpoint. Its callable dependencies are internal UI builders only, so the table above remains the full CRUD/call inventory for this method. The `button()` call is the only multi-instance call, and it returns an array whose elements are added individually to the second panel.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `UI.textField` | UI | - | Builds the amount entry field and returns the input component |
| R | `UI.comboBox1` | UI | - | Builds the source-currency selector and returns the input component |
| R | `UI.label` | UI | - | Builds the result display label and returns the output component |
| R | `UI.comboBox2` | UI | UI | Builds the target-currency selector and returns the input component |
| R | `UI.button` | UI | - | Builds the action button set and returns the button array |

## 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.UI()` -> `UI.add(panel())` -> `UI.panel()` | `textField [R] -`, `comboBox1 [R] -`, `label [R] -`, `comboBox2 [R] -`, `button [R] -` |

## 6. Per-Branch Detail Blocks

This method is branch-free and executes as a fixed sequence of panel composition steps.

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

> Creates the root container and establishes the overall vertical stacking structure.

| # | 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] `(first input section)` (L73)

> Builds the top band that captures the amount and source currency.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel panelFramePanel1 = new JPanel();` |
| 2 | EXEC | `panelFramePanel1.setBackground(Color.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** — [SEQUENTIAL] `(second output/action section)` (L79)

> Builds the lower band that shows the result, target currency, and action controls.

| # | 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);` |
| 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] `(assemble and return root panel)` (L88)

> Adds both bands to the root container 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 |
|------|------|------------------|
| `UI` | Class | Main desktop user interface for the currency converter application |
| `panel` | Method | Builds the root screen panel and arranges all visible controls |
| `framePanel` | UI container | Root panel that holds the full content area of the window |
| `panelFramePanel1` | UI container | Upper input panel containing the amount field and source currency selector |
| `panelFramePanel2` | UI container | Lower panel containing the result label, target currency selector, and action buttons |
| `textField` | UI control | Amount entry field where the user inputs the value to convert |
| `comboBox1` | UI control | Source currency selector used to choose the currency being converted from |
| `comboBox2` | UI control | Target currency selector used to choose the currency being converted to |
| `label` | UI control | Output label used to display the converted amount or status text |
| `button` | UI control factory | Produces the action buttons used to run converter actions |
| `BoxLayout` | Technical term | Swing layout manager that stacks components vertically in the root panel |
| `FlowLayout` | Technical term | Swing layout manager that centers components within each child panel |
| `Color.DARK_GRAY` | Technical term | Dark background color used to visually separate UI sections |
| `Currency Converter` | Business term | The application domain shown in the window title |
| `Component` | Technical term | Swing base type returned so the panel can be attached to the frame |
| `CurrencyCode` | Class | Background loader used by the currency selector builders to populate code lists |
| `Convert` | Business action | Executes the currency conversion operation |
| `Swap` | Business action | Swaps the source and target currencies |
| `Clear` | Business action | Clears the current input and result state |
