본문 바로가기
Language/JAVA

[JAVA] 11~12 입력 input & 출력 output

by 아이엠제니 2022. 1. 30.

생활코딩 [자바 입문 수업] 공부 기록

 

 

11.1 입력과 출력

 

 

팝업창이 뜨면서 입력할 수 있었으면 좋겠어!

google searching
java popup input text swing

 

package java09;

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

import javax.swing.*;

public class OkJavaGoInHomeInput {
    public static void main(String[] args) {

        String id = JOptionPane.showInputDialog("Enter a ID"); // 추가

        // Elevator call
        Elevator myElevator = new Elevator(id);
        myElevator.callForUp(1); // 올라갈 거니까, 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();
    }
}

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

이 부분을 추가했고!

run 하니, 팝업창이 떴다.

 

 

 

입력한 것이 이렇게 뜬다!

good.

 

사용자가 입력한 값에 따라 다르게 동작할 수 있는!

굉장히 똑똑하고 범용적으로 쓰일 만한 프로그램이다. 

 

 

 

google searching
java string to double conversion
package java09;

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 OkJavaGoInHomeInput {
    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); // 올라갈 거니까, 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();

        DimmingLights moodLmap = new DimmingLights(id + " moodLamp"); //★
        moodLmap.setBright(Double.parseDouble(bright)); //string to double //★
        moodLmap.on(); //★
    }
}

 

 

 

11.2 입력과 출력 : arguments & parameter 

argument: 인자

parameter: 매개변수

 

 

 

12.1 직접 컴파일하고 실행하기

java 확장자가 붙은 소스 코드를 class 확장자가 붙은 실행 파일로 바꾸는 거.

 

Compile

Run

Input

 

 

 

12.2 직접 컴파일하고 실행하기 : 실행환경 살펴보기

windows + R => cmd

 

우리카 컴파일 하고, 실행을 하기 위해서는 javac를 이용해서 컴파일 할 수 있다.

 

cd: change directory

ls: list

 

자바 환경 변수 설정

 

 

 

(여기서부터는 부스트코스에서 봄)

똑같이 따라하지 않아도 되니, 흐름을 이해하는 걸로.

12.3 직접 컴파일-실행 : 컴파일과 실행하기

dir 명령어로 프로젝트 디렉토리 내부 구조를 확인할 수 있음

 

 

 

12.4 직접 컴파일-실행 - 라이브러리 이용

Library

 

--class-path 옵션은 -cp로 줄여 표현 가능

 

 

 

12.5 직접 컴파일-실행 - 입력과 출력



 

12강은 cmd 창으로 따라해야 하는 부분이었다.

cmd창으로 코드를 작성하는 건 매우 낯설다.

일단은 영상 보며 최대한 이해하면서 보려고 했다.

 

300x250