U E D R , A S I H C RSS

Java Study2003/두번째과제/입출력예제

Java의 Swing 중 JOptionPane 으로 입력과 출력을 받는 예제.



이건 제가 프로그래밍 하는 습관이 많이 반영되었으므로 완전히 따라하지 않았으면 합니다. 그냥 참고만 하세요.

예제코드


  • 주석은 왠만하면 영문으로 달겠습니다. -_-+


~cpp 
import javax.swing.JOptionPane;

public class InputOutputExample {
	
	private String input = "";
	private String output = "";
	
	public InputOutputExample() {	// Constructor
		// input string
		input = inputDialogbox("Enter the first word : ");
		output += input;	// add text to String instance; 
		
		input = inputDialogbox("Enter the second word : ");
		output += input;	// add text to String instance;
		
		outputDialogbox(output);						
	}

	public static void main(String[] args) {
		InputOutputExample example = new InputOutputExample();
	}
	
	public String inputDialogbox(String text) {
		// Shows a question-message dialog requesting 
		// input from the user parented to parentComponent. 
		return JOptionPane.showInputDialog(null, text);		
	}
	
	public void outputDialogbox(String message) {
		// Brings up an information-message dialog titled "Message".
		JOptionPane.showMessageDialog(null, message);
	}
}



Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:31
Processing time 0.0226 sec