입력과 출력

황찬호·2021년 3월 31일
0

Java1

목록 보기
6/14

다이얼로그(Dialog)를 통해 입력

import javax.swing.JOptionPane;
// 다이얼로그를 불러올 수 있게 JOptionPane클래스 불러오기

public static void main(String[] args) {
		
	// 다이얼로그 호출
	String id = JOptionPane.showInputDialog("Enter a ID");
    String bright = JOptionPane.showInputDialog("Enter a Bright level");
        
        // 위에서 입력한 다이얼로그는 String이므로 Double형으로 변환
	moodLamp.setBright(Double.parseDouble(bright));
import javax.swing.JOptionPane;

import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
// import를 통해 다른 클래스를 불러올 수 있다.

public class OKJavaGoInHomeInput {

	public static void main(String[] args) {
		
		// String이라는 데이터 타입을 변수 id로 지정
		String id = JOptionPane.showInputDialog("Enter a ID");
		String bright = JOptionPane.showInputDialog("Enter a Bright level");
		
		// Elevator call
		// myElevator 라는 변수는 반드시 Elevator라는 데이터 타입에 해당되는 데이터만 올 수 있다.
		// 위에서 import를 통해 org폴더의 Elevator를 불러옴
		Elevator myElevator = new Elevator(id); 
		myElevator.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();
		
		DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();

	}

}

argument & parameter

argument 설정

  • Run Configurations에서 Argument탭에 들어가면 입력값을 설정할 수 있다.
  • Argument는 띄어쓰기를 하게 되면 따로 입력이 들어가기 때문에 작은따옴표를 통해 묶어준다.
  • 여러개의 값을 주고싶을 땐 한칸 띄우고 작은따옴표 안에 작성하면 된다.
  • 여러가지 값들도 실행을 해야 한다면 Run Configurations에서 .java파일을 우클릭하여 Duplicate하면 된다.

parameter(매개변수)

매개변수는 프로그램과 사람 사이의 값을 매개 해준다고 하여 매개변수라고 한다.

// args = parameter(매개변수)
public static void main(String[] args) {
		String id = args[0] ;
		String bright = args[1];
		
import javax.swing.JOptionPane;

import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
// import를 통해 다른 클래스를 불러올 수 있다.

public class OKJavaGoInHomeInput {

	public static void main(String[] args) {
		
		// String이라는 데이터 타입을 변수 id로 지정
		String id = args[0] ;
		String bright = args[1];
		
		// Elevator call
		// myElevator 라는 변수는 반드시 Elevator라는 데이터 타입에 해당되는 데이터만 올 수 있다.
		// 위에서 import를 통해 org폴더의 Elevator를 불러옴
		Elevator myElevator = new Elevator(id); 
		myElevator.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();
		
		DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();

	}

}
profile
되는대까지 해보기

0개의 댓글