현재 두 개의 증권 거래소 알고리즘을 비교하기 위해 애니메이션 작업 중입니다. JComponent를 확장하는 페인트 구성 요소 내에서 알고리즘을 실행 중입니다. (최고는 아니지만 상관하지 않습니다.) 페인트 구성 요소를 통해 화면을 절반 새로 고침해야합니다. 화면에 날짜가 표시되기 전에 모든 것이 끝나기를 원하지 않습니다. 그 이유는 중첩 된 while 루프가있는 하나의 알고리즘과없는 다른 알고리즘이 있다는 것입니다. 이 일을 어떻게 하죠?오브젝트가 Reapint의 중간에 렌더링되도록하기
public void paintComponent(Graphics g) {
//calls in the super class and calls the calibrate the graphics method
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
calibrateFrame(getHeight(), getWidth());
//Clears the rectangle to avoid overlaying, makes it black
g2D.clearRect(0, 0, getWidth(), getHeight());
g2D.setColor(Color.BLACK);
g2D.fillRect(0, 0, getWidth(), getHeight());
//Draws the rectangles without the algorithm started
redraw(g2D, -1);
/**
*algorithms
*/
fastSpans[0] = 1;
slowSpans[0] = 1;
//Makes a new stack pushes 0 on the stack
Stack myStack = new Stack();
myStack.push(0);
//If it has not been sorted or paused, continue the algorithm
if (!(pause) && !(sorted)){
//The slower algorithm needs to start out at zero (j)
int j = indexValue-1;
g2D.setColor(Color.BLUE);
//Calculates the values for the X and Y coordinates for the
//new rectangle, along with the height
int slowY = calSlowY(j);
int slowX = calSlowX(j);
int curHeightSlow = (int) ((stocks[j]/maxStockValue)*maxHeight);
//Here is the actual algorithm
int k = 1;
boolean span_end = false;
//Nested While Loop
while (((j-k)>0) && !span_end){
if (stocks[j-k] <= stocks[j]){
k = k + 1;
// Draw the current component
// **********************
// DO REFRESH MID PAINT COMPONENT
}
else{ span_end = true; }
}
slowSpans[j] = k;
g2D.setColor(Color.WHITE);
for(int i = 0; i < numberOfStock ; i++){
}
if (!(indexValue >= numberOfStock)){
while (!(myStack.empty()) && (stocks[(int)myStack.peek()]) <= stocks[indexValue]){
myStack.pop();
}
if (myStack.empty()){
fastSpans[indexValue] = indexValue + 1;
}
else {
fastSpans[indexValue]= indexValue - (int) myStack.peek();
//System.out.println("Im in the else");
}
myStack.push(indexValue);
}
}
drawStrings(g2D);
}
은 (http://www.oracle.com/technetwork/java/painting-140037.html), 다음 추가 질문으로 돌아와. 모든 의도와 목적으로 paintComponent를 원 자성 조작으로 간주해야합니다. –