developer/생활코딩 - JAVA1

[생활코딩 - JAVA1] 3/10 개발공부일지 - JOPtionpane

페달파워 2023. 3. 11. 13:40

input 으로 output을 만들어내는 Program

 

ex) JOptionpane method??

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 brightness level!");
//        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 + " / Floor Lamp");
        floorLamp.on();

        DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
        moodLamp.setBright(Double.parseDouble(bright));
        moodLamp.on();
    }
}

요렇게 창이 두번 뜨고 각각 창에 값을 입력하면

요렇게 결과를 출력한다.

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

이 코드를 통해서 가능하다.

https://stackoverflow.com/questions/17180023/how-do-i-make-a-popup-window-with-just-a-textfield

 

How do I make a popup window with just a textfield?

I want to create a popup window when the user clicks a "Load from file" button. I want that popup box to have a text box and an "OK" "Cancel" option. I have read through a lot of Java Documentatio...

stackoverflow.com

이때 JOptionPane은

import javax.swing.*;

요렇게 임폴트가 필요하다.

임폴트는 뭐고, 저 javax, swing, * 은 뭘 나타내는지 모르겠다.

일단 시키는 대로 했다.

 

아 그리고 오류떴을 때

option+return 키 누르니까

짠.. 새로운 음.. 뭔가가 import 되었다. 꿀!