728x90
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
import javax.swing.*;
public class OkJavaGoingHomeInput {
public static void main(String[] args){
String id = JOptionPane.showInputDialog("Enter a ID");
String bright = JOptionPane.showInputDialog("Enter a Bright level");
// Elevator call
Elevator myElevator = new Elevator(id);
myElevator.callForUp(1);
// Security off
Security mySecurity = new Security(id);
mySecurity.off();
//Light on
Lighting hallLamp = new Lighting("JAVA APT 507 / Hall Lamp");
hallLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}
전에 만들었던 간단한 IoT 시스템에 기능 몇가지를 추가하였다.
JOptionPane.showInputDialog("Enter a ID");
위의 코드는 팝업창을 띄워 C언어의 scanf 기능과 유사한 역할을 한다.
moodLamp.setBright(Double.parseDouble(bright));
위의 코드는 moodLamp.setBright는 double형을 받아야만 하는 함수인데, 그 외 자료형이 들어올 경우
double형으로 변환하는 코드이다.


위의 사진과 같이 심플한 GUI가 출력된다.
728x90
'java study' 카테고리의 다른 글
[Java Study] 자바 문서 보는 법 (패키지, 클래스, 변수, 메소드) (0) | 2022.06.28 |
---|---|
[Java Study] API와 UI의 개념 (0) | 2022.06.28 |
[Java Study] 인텔리제이(intellij) 디버거 사용하기 (0) | 2022.06.24 |
[Java Study] 간단한 IoT 구현하기 (0) | 2022.06.20 |
[Java Study] 데이터 타입의 변환 (Casting) (0) | 2022.06.20 |