[답변]JProgressBar 사용법


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :조신제 1999년 8월 04일 09:28:25

In Reply to: [질문] ProgressBar를 만들려고 하는데.. posted by 장진성 on 1999년 8월 03일 00:42:03:

만약 PC에 jdk1.2.x판을 깔아서 사용한다면 ProgressBar를 사용하는 방법이 제공된 예제가
들어있습니다.
아래의 디렉토리에서 NotePad.java 파일을 열어서 FileLoader라는 inner class를 보시면 됩니다.


C:\jdk1.2.x\demo\jfc\Notepad\


참고로 FileLoader 부분만 올려드리겠습니다.


class FileLoader extends Thread {


FileLoader(File f, Document doc) {
setPriority(4);
this.f = f;
this.doc = doc;
}


public void run() {
try {
// initialize the statusbar
status.removeAll();
JProgressBar progress = new JProgressBar(); <-- 여기서 부터
progress.setMinimum(0);
progress.setMaximum((int) f.length()); <-- 여기까지 설정하면 됩니다.
status.add(progress);
status.revalidate();


// try to start reading
Reader in = new FileReader(f);
char[] buff = new char[4096];
int nch;
while ((nch = in.read(buff, 0, buff.length)) != -1) {
doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
progress.setValue(progress.getValue() + nch); <-- 그리고 여기에서 ProgressBar의 값을 변경시키면 됩니다.
}


// we are done... get rid of progressbar
doc.addUndoableEditListener(undoHandler);
status.removeAll();
status.revalidate();
}
catch (IOException e) {
System.err.println(e.toString());
}
catch (BadLocationException e) {
System.err.println(e.getMessage());
}
}


Document doc;
File f;
}





다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]