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

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

## 1. Role

### UI.panel()

This method constructs the main Swing container for the currency conversion screen and assembles the visual layout used by the `UI` frame. It creates a two-row panel structure: the first row holds the amount entry field and source currency selector, while the second row holds the result label, target currency selector, and the three action buttons created by `button()`. The method follows a UI composition / layout-builder pattern, where the frame is assembled from smaller component factory methods rather than building all controls inline in the constructor. Its role in the larger system is to provide the primary presentation shell for the application and to centralize the screen layout so the frame can be initialized consistently from a single entry point. There are no business-rule branches inside this method; instead, it deterministically builds the UI hierarchy and returns the root panel for attachment to the frame.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
START["panel()"]
A["Create root JPanel framePanel"]
B["Set root layout to BoxLayout Y_AXIS"]
C["Create top section panelFramePanel1"]
D["Set top section background to DARK_GRAY"]
E["Set top section layout to FlowLayout CENTER"]
F["Call textField()"]
G["Call comboBox1()"]
H["Create bottom section panelFramePanel2"]
I["Set bottom section layout to FlowLayout CENTER"]
J["Call label()"]
K["Call comboBox2()"]
L["Set bottom section background to DARK_GRAY"]
M["Call button()[0]"]
N["Call button()[1]"]
O["Call button()[2]"]
P["Add top section to root panel"]
Q["Add bottom section to root panel"]
R["Return framePanel"]
START --> A
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
H --> I
I --> J
J --> K
K --> L
L --> M
M --> N
N --> O
O --> P
P --> Q
Q --> R
```

**CRITICAL — Constant Resolution:**
The method uses Java AWT/Swing constants only. The resolved constant values are:
- `BoxLayout.Y_AXIS = 1`
- `FlowLayout.CENTER = 1`
- `Color.DARK_GRAY = RGB(64,64,64)`

## 3. Parameter Analysis

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

External state read by this method:
- Instance fields are not directly read, but the method depends on the component-factory methods `textField()`, `comboBox1()`, `label()`, `comboBox2()`, and `button()` to populate the panel.
- The returned `Component` is the assembled root panel used by the `UI` constructor when calling `add(panel())`.

## 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 |
|------|----------|---------|-------------|----------------------|
| - | `panel()` | UI | Swing `JPanel` hierarchy | Creates the root container for the screen layout |
| - | `textField()` | UI | Swing `JTextField` component | Creates the amount input field used in the converter form |
| - | `comboBox1()` | UI | Swing `JComboBox` component | Creates the source-currency selector |
| - | `label()` | UI | Swing `JLabel` component | Creates the output label displayed in the lower section |
| - | `comboBox2()` | UI | Swing `JComboBox` component | Creates the target-currency selector |
| - | `button()` | UI | Swing `JButton` array | Creates the action buttons and adds them to the panel |

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

## 6. Per-Branch Detail Blocks

There are no conditional branches, loops, or exception blocks in this method. The method is a straight-line UI assembly routine.

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

> Builds the root panel and the two nested row panels used by the currency converter screen.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JPanel framePanel = new JPanel();` |
| 2 | SET | `framePanel.setLayout(new javax.swing.BoxLayout(framePanel, javax.swing.BoxLayout.Y_AXIS));` [-> `BoxLayout.Y_AXIS = 1`] |
| 3 | SET | `JPanel panelFramePanel1 = new JPanel();` |
| 4 | SET | `panelFramePanel1.setBackground(Color.DARK_GRAY);` [-> `Color.DARK_GRAY = RGB(64,64,64)`] |
| 5 | SET | `panelFramePanel1.setLayout(new FlowLayout(FlowLayout.CENTER));` [-> `FlowLayout.CENTER = 1`] |
| 6 | CALL | `panelFramePanel1.add(textField());` |
| 7 | CALL | `panelFramePanel1.add(comboBox1());` |
| 8 | SET | `JPanel panelFramePanel2 = new JPanel();` |
| 9 | SET | `panelFramePanel2.setLayout(new FlowLayout(FlowLayout.CENTER));` [-> `FlowLayout.CENTER = 1`] |
| 10 | CALL | `panelFramePanel2.add(label());` |
| 11 | CALL | `panelFramePanel2.add(comboBox2());` |
| 12 | SET | `panelFramePanel2.setBackground(Color.DARK_GRAY);` [-> `Color.DARK_GRAY = RGB(64,64,64)`] |
| 13 | CALL | `panelFramePanel2.add(button()[0]);` |
| 14 | CALL | `panelFramePanel2.add(button()[1]);` |
| 15 | CALL | `panelFramePanel2.add(button()[2]);` |
| 16 | CALL | `framePanel.add(panelFramePanel1);` |
| 17 | CALL | `framePanel.add(panelFramePanel2);` |
| 18 | RETURN | `return framePanel;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `UI` | Class | The Swing-based user interface for the currency converter application |
| `panel` | Method | Builds and returns the root screen container |
| `framePanel` | Variable | The outer container that holds the complete screen layout |
| `panelFramePanel1` | Variable | The top row of the form, containing input and source-currency selection |
| `panelFramePanel2` | Variable | The bottom row of the form, containing output and action controls |
| `JPanel` | Technical term | Swing container used to group visual components |
| `JTextField` | Technical term | Editable text input for entering the amount to convert |
| `JComboBox` | Technical term | Drop-down list used to select a currency |
| `JLabel` | Technical term | Non-editable text display used for showing the result |
| `JButton` | Technical term | Clickable action control used to trigger conversion-related actions |
| `BoxLayout` | Technical term | Layout manager that stacks components vertically in this screen |
| `FlowLayout` | Technical term | Layout manager that centers controls within each row |
| `DARK_GRAY` | UI constant | Dark background color used to visually separate the panels |
| `Y_AXIS` | Layout constant | Vertical stacking direction for the root panel |
| `CENTER` | Layout constant | Alignment mode that centers controls in the row |
| `Currency Converter` | Business term | The application domain of this screen, converting monetary values between currencies |
| `amount` | Business term | The numeric value entered by the user for conversion |
| `source currency` | Business term | The currency code selected as the original unit of the amount |
| `target currency` | Business term | The currency code selected as the conversion destination |
| `result` | Business term | The converted amount shown to the user |
