본문 바로가기
Computer/Mobile3D

4. Thread 를 이용한 화면 갱신

by DogBull 2007. 7. 30.
사용자 삽입 이미지


import java.io.*;
import javax.microedition.lcdui.*;
import com.mascotcapsule.micro3d.v3.*;

public class Canvas3D extends Canvas implements Runnable{
    public Canvas3D(){
        Thread thread=  new Thread(this);   //화면 갱신, 게임계산 등을 위한 쓰레드
         thread.start();                     //쓰레드 시작
    }

    public void run(){
        while(true){
            repaint();                      //내부적으로 paint(...)메소드를 호출한다.
            
            try{
                Thread.sleep(100);          //쓰레드를 100밀리초 재운다.
            }catch(Exception e){}
        }
    }

    public void paint(Graphics g){
        //~ 화면 전체를 0x339933색으로 채운다.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        g.setColor(0x339933);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        //~ 화면이 한번 갱신될 때 마다 count 변수를 1씩 증가시키며, 화면에 출력~~~~~~~~~~~~
        g.setColor(0xffffff);
        g.drawString(String.valueOf(count++), this.getWidth()/2, this.getHeight()/2, g.TOP|g.LEFT);
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    }
    
    private int count;
}

'Computer > Mobile3D' 카테고리의 다른 글

5. Color Cube  (0) 2007.07.30
5. 3D Draw  (0) 2007.07.30
3. Hello MIDlet  (0) 2007.07.30
2. MIDlet 생명 주기  (0) 2007.07.30
1. Mobile3D  (0) 2007.07.30