2014-12-26 2 views
0

학교 프로젝트 (첫 번째 Java 과정)를 마치고 JOptionPane만을 사용해야한다고 들었습니다. 나는 System.out.println하지만JOptionPane를 사용하여이없이 같은 것을 수행해야합니다JOptionPane 내부에서 배열을 반복 처리하고 사용자 정의 메시지를 표시하는 방법

이런 아름다운 일 인쇄
int[] den = {1000, 500, 100 ,50, 20, 10 ,5, 2, 1}; 
System.out.println("\nDENOMINATIONS: \n"); 

for (int i = 0; i < 9; i++) { 
    count = amount/den[i]; // counting number of den[i] notes 
    if (count != 0) { //printing that denomination if the count is not zero 
     System.out.println(den[i] + "\tx\t" + count + "\t= " + den[i] * count); 
    } 
    totalNotes = totalNotes + count; //finding the total number of notes 
    amount = amount%den[i]; //finding the remaining amount 
} 
System.out.println("--------------------------------"); 
System.out.println("TOTAL\t\t\t= " + copy); 
System.out.println("--------------------------------"); 
System.out.println("Total Number of Notes\t= " + totalNotes); 

:

DENOMINATIONS: 

1000  x  14  = 14000 
500  x  1  = 500 
100  x  3  = 300 
50  x  1  = 50 
5  x  1  = 5 
1  x  1  = 1 
————————————– 
TOTAL     = 14856 
————————————– 
Total Number of Notes = 21 

답변

3

JOptionPane API 읽기를. 옵션 창에 구성 요소를 추가 할 수 있습니다. "message"매개 변수는 텍스트를 표시하는 간단한 문자열 일 수도 있고 스윙 구성 요소 일 수도 있고 문자열 및 구성 요소가 포함 된 배열 일 수도 있습니다.이 경우 여러 구성 요소가 옵션 창에 세로로 추가됩니다.

그래서 JTextArea에 텍스트를 추가 할 수 있습니다. 그런 다음 옵션 영역에 텍스트 영역을 추가하십시오.

텍스트를 올바르게 정렬 할 수 있도록 텍스트 영역의 글꼴을 고정 폭 글꼴로 변경해야 할 수도 있습니다.

+1

나는'JTable'을 생각하고있다. – MadProgrammer

관련 문제