일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 오라클클라우드에 젠킨스 설치하기
- 스프링 Ioc
- Spring Boot가 해결하려고 했던 문제
- 스프링
- 자바 왕기초
- 스프링 Ioc Container
- 스프링 에러
- 스프링과 스프링부트 차이점
- java
- CSS
- 오라클일별데이터
- 스프링 구글차트
- 자바기초
- 세션
- 오라클통계
- 자바
- 스프링 제어역전
- 제이쿼리
- 스프링 부트가 해결하려고 했던 문제
- 자바왕기초
- maven
- 스프링 구글차트로 기간별 현황 조회하기
- 오라클주별데이터
- 자바 기초
- 오라클
- 자바왕초보
- 오라클월별데이터
- jsp
- HTML
- 썸머노트
- Today
- Total
Just Do it
Java 입력과 출력 본문
1. 사용자가 직접 입력하여 작동할 수 있도록 프로그램을 만들 수 있다.
2. text를 입력 받는 팝업을 여는 코드를 찾기 위해 구글에 java popup input text swing 으로 검색하면 예제와 코드를 찾을 수 있다.
*swing: 자바에서 text 입력 받는 팝업을 여는 기술
*import javax.swing.JOptionPane;
String id = JOptionPane.showInputDialog("Enter a ID");
String bright = JOptionPane.showInputDialog("Enter a Bright level");
3. string을 double로 바꾸는 코드를 찾기 위해 구글에 java string to double conversion으로 검색하면 예제와 코드를 찾을 수 있다.
*moodLamp.setBright(Double.parseDouble(bright));
-------------------------------------------------------------------------
import javax.swing.JOptionPane;
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Security;
import org.opentutorials.iot.Lighting;
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);
// 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+ "/ floorLamp");
floorLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}
-----------------------------------------------------------------------------
프로그램을 개발할때 개발하는 과정에서 실행할때마다 input 값을 입력하는게 귀찮다.
이 귀찮음을 해결하기 위해 이클립스에 input 값을 미리 정의해놓을 수 있다.
1. Run옆에 작은 세모를 클릭 -> Run Configurations -> Arguments -> Program arguments:
Program arguments: 여기에 입력을 하면 문자열의 배열인 매개변수 args에 저장되며 args[0], args[1], ...등으로 호출할 수 있다.
1) Program Arguments: 'Java APT 507' '15.0' 입력(작은 따옴표로 하나로 묶어주기)
2) Apply (저장)
3) 상단에 Name: 실행에 대한 이름 설정
4) 최종적으로 'Run' 클릭하면 입력값이 들어간다.
그럼 Arguments에 입력한 값들을 어떻게 받느냐?
*Arguments: 인자
5) args 는 매개변수 (parameter) 이다. (프로그램을 사용하는 사람과 프로그램 사이의 값을 매개해줌)
'Java APT 507' '15.0' 두 개의 Arguments(인자)는 'args'라는 매개변수로 들어오는 것임
- String[] args 에서 대괄호([])는 문자열로만 이뤄져있는 '배열'이라는 데이터다. args라는 변수에 사용자가 입력한 변수가 들어옴.
- 나머지 중괄호 {} 안에서는 args가 사용자가 입력한 값이라는 점을 이해해야 함.
//parameter, 매개변수
public static void main(String[] args) {
String id = args[0]; //첫번째로 입력한 값. Java APT 507
String bright = args[1]; // 두번째로 입력한 값. 15.0
import javax.swing.JOptionPane;
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Security;
import org.opentutorials.iot.Lighting;
public class OKJavaGoinHomeinput {
//parameter, 매개변수
public static void main(String[] args) {
String id = args[0];
String bright = args[1];
// 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(id+ " / Hall Lamp");
hallLamp.on();
Lighting floorLamp = new Lighting(id+ "/ floorLamp");
floorLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}
'신입 개발자가 되기 위해 공부했던 독학 자료들 > Java 왕기초 (생활코딩 공부)' 카테고리의 다른 글
Java 제어문 (0) | 2021.12.15 |
---|---|
Java 문서 보는 법 (0) | 2021.12.15 |
Java 디버거 (0) | 2021.12.15 |
Java 프로그래밍 (0) | 2021.12.14 |
Java Casting (0) | 2021.12.14 |