Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

JavaStudy2003/두번째과제/입출력예제

From ZeroWiki

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


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

예제코드

  • 주석은 왠만하면 영문으로 달겠습니다. -_-+
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);
	}
}

JavaStudy2003/두번째과제