IOT 프로그램 만들기

hanahana·2022년 7월 29일

JAVA 생활코딩

목록 보기
3/8
post-thumbnail

실제로 만드는건 아니고 만드는 구조를 알아본다.

import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;

public class OkJavaGoInHome {
public static void main(String[] args) {
	
		String id = "JAVA APT 507";
		//Elevater call
		Elevator myElevater = new Elevator(id);
		myElevater.callForUp(1);
		
		//Security off
		Security mysecurity=new Security(id);
		mysecurity.off();
		
		//Light on
		Lighting hallLamp=new Lighting(id+" / Hall Lamp");
		hallLamp.on();
		
		Lighting floorLamp=new Lighting(id+" / floor Lamp");
		floorLamp.on();
	}

결과문

JAVA APT 507 -> Elevator callForUp stopFloor : 1
JAVA APT 507 -> Security off
JAVA APT 507 / Hall Lamp -> Lighting on
JAVA APT 507 / floor Lamp -> Lighting on

이미 있는 프로그래밍을 불러와 실행시키는 원리다

예를들어 Lighting을 쓰고 Ctlr + space를 누르면 import할수있는 Lighting파일이 나타나고 선택하여 작성중인 파일로 불러올수있다

이렇게 이미 작성된 프로그램을 불러와 새로운 변수로 정의하고

변수에게 적절한 명령을 입력하면 실행할수있다.

텍스트 입력받기

String id = JOptionPane.showInputDialog("Enter a ID");
String bright= JOptionPane.showInputDialog("Enter a Id");

DimmingLights moodLamp = new DimmingLights(id+" moolamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();
  • 구글에서 java popup input test swing 으로 검색해서 받은 코드를 사용해였다.
    JOptionPane.showInputDialog이라는 코드가 새로운 윈도우 창을 출력하여 텍스트를 입력받는데
    “Enter ID” 구문은 입력창에 뜨는 메세지 이다.
  • String으로 입력받은 bright는 Doubble로만 인식가는한 변수이기에
    setBright의 값안에 Double.parseDouble(bright)을 입력하여 Double 정의를 바꾸어주었다
    구글에서 java string to double conversion 으로 검색하여 나온 코드이다

고정된 입력값 받기

이클립스에서 run밑에 runconfigurations를 누르고 고정값을 주고싶은 class를 찾아 Aguments창을 눌러 “원하는고정값1” “원하는고정값2” “원하는고정값3”... 식으로 입력받을 고정값을 미리 설정할수있다.

이 고정값은

String id = args[0];
		String bright= args[1];

이처럼 args[고정값숫자-1]을 입력하면 순서에 따라 고정값이 입력된다

profile
hello world

0개의 댓글