ios개발/함수형 프로그래밍

<java> 자바 MVVM 사용하는 방법. swing

studying develop 2021. 1. 4. 02:27

[book.interpark.com/product/BookDisplay.do?_method=detail&sc.prdNo=268649098&gclid=Cj0KCQiA88X_BRDUARIsACVMYD_EgPJiBYn7QGOpnAAB5PG4enQ4GLG4LNBz3DquMUEsDIbyhEeZ6WYaAgC1EALw_wcB]

 

이 책을 보는데 

import javax.swing.*;
import java.awt.FlowLayout;
import swidgets.*;
import nz.sodium.*;

public class clearfield {
    public static void main(String[] args) {
        JFrame frame = new JFrame("clearfield");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());
        
        SButton clear = new SButton("Clear");
        Stream<String> sClearIt = clear.sClicked.map(u -> "");

        STextField text = new STextField(sClearIt, "Hello");
        
        frame.add(text);
        frame.add(clear);

        frame.setSize(400, 160);
        frame.setVisible(true);
    }
}

 

코드에서 이해가 안되는 라이브러리가 많아서, 좀 검색해 봤다. 자바는 처음이라...

 

java.awt.FlowLayout에 속한 JFrame은 근야 일반적인 레이아웃이나 프레임을 다루기 위한것 같다.

 

javax.swing에 속한 SButton, STextField는 [scope.sourceforge.net/apidocs/org/scopemvc/view/swing/SButton.html] 여기 레퍼런스가 있는데, 자바 라이브러리를 잘 몰르겠다. 

 

javax.swing.JButton이랑 무슨 관계인지 모르겠다.... 왜 그 밑에 SButton이 있지?

 

 

"A JButton that issues a Control when pressed. The button label comes from UIStrings keyed against the Control ID. "

JButton인데 눌르면 컨트롤을 발행하는 그런 특이한 버튼이라는거 같다.

 

 

 

 

SText는 [scope.sourceforge.net/apidocs/org/scopemvc/view/swing/STextField.html]

 

A JTextField linked to a property of a bound model object. The property must have a StringConvertor to handle conversion to and from a String representation that will be edited in the textfield. Updates to the textfield result in changes to the model property when focus is lost.

 

JTextField인데 바운드 모델 객체의 프로퍼티에 연결된 놈이다. 값은(프로퍼티)는 텍스트 필드에서 변경될 수 있는 문자열 표현을 다룰수 있는 스트링 컨버터를 가져야 한다. 텍스트 필드의 변경은 초점을 잃게되면 모델 값을 변경한다.

 

 

 

 

음 결국 MVVM에서 사용하는 값 바인딩 구현을 도와주는 놈 같다?

스위프트로 치면 combine 프레임 워크