package IoTPackage;

public class IoTMain {

	public static void main(String args[]) {
		
		String id = "Raye";
		
		SmartphoneImple mySmartphone = new SmartphoneImple(id+" / iphone13");
		mySmartphone.powerOn();
		
		LaptopImple myLaptop = new LaptopImple(id+" / macAir");
		myLaptop.powerOn();
	}
}

<aside> 💁🏻 만약 위의 코드가 사용자가 많아진다면 id의 값이 다양해질 것이다. 매번 id를 찾아서 수정하는 것보다 프로그램 실행시 user id(text 정보)를 입력하라는 pop-up 알림창이 화면에 출력되도록 만드는 것도 하나의 좋은 방법이겠다! 이러한 기술을 Swing이라 한다.

구현결과

Screen Shot 2022-09-09 at 3.26.23 PM.png

package IoTPackage;

import javax.swing.JOptionPane;

public class IoTMain {

	public static void main(String args[]) {
		
		String id = JOptionPane.showInputDialog("Enter a ID");
		
		SmartphoneImple mySmartphone = new SmartphoneImple(id+" / iphone13");
		mySmartphone.powerOn();
		
		LaptopImple myLaptop = new LaptopImple(id+" / macAir");
		myLaptop.powerOn();
	}
}

출처