import com.nttdocomo.ui.*; import com.nttdocomo.system.*; import com.nttdocomo.io.*; import java.io.*; public class scroll_sumple extends IApplication { mycanvas w_canvas = new mycanvas(); public void start() { w_canvas.setSoftLabel(w_canvas.SOFT_KEY_1,"終了"); w_canvas.setSoftLabel(w_canvas.SOFT_KEY_2,"読込"); Display.setCurrent(w_canvas); } class mycanvas extends Canvas { String words; int y = 0; int f_height; String buff_text = ""; public void paint(Graphics g){ //画面クリア g.clearRect( 0,0, getWidth(),getHeight() ); //フォントの高さを取得 f_height = Font.getDefaultFont().getHeight(); int st = 0; int k = 1; //行数 int xx = 10; //x軸の初期値 int yy = 15; //y軸の初期値 int getit = buff_text.indexOf('\n',st); while(getit != -1){ //改行までの文字列を抜き出し String phrase = buff_text.substring(st,getit); int len = phrase.length(); char data[] = new char[len]; phrase.getChars(0, len, data, 0); int startIdx = 0; int endIdx = 0; //空白行対応 if(len == 0){ if(y < k){ yy += f_height; } k++; } //折り返し対応 while (len > 0) { endIdx = Font.getDefaultFont().getLineBreak(phrase, startIdx, len, getWidth() - 20); if(y < k){ g.drawChars(data, xx, yy, startIdx, endIdx - startIdx); yy += f_height; } len -= (endIdx - startIdx); startIdx = endIdx; k++; } st = getit + 1; getit = buff_text.indexOf('\n',st); } } public void processEvent(int w_type,int w_param) { // ソフトキー1が離された時に実行 if ((w_type==Display.KEY_RELEASED_EVENT) && (w_param==Display.KEY_SOFT1)) { // iアプリ終了 (IApplication.getCurrentApp()).terminate(); } if ((w_type==Display.KEY_RELEASED_EVENT) && (w_param==Display.KEY_SOFT2)) { try { // 偽装ファイルの読み込み // ImageStore ie = ImageStore.selectEntry(); //実機の時はこっちを活性化 ImageStore ie = ImageStore.getEntry(1); //エミュレータの時はこっちを活性化 //バイトストリームで読み直す InputStream in = ie.getInputStream(); BufferedReader in2 = new BufferedReader(new InputStreamReader(in)); //1行ずつ読み込む String line = in2.readLine(); //バッファ域の初期化 buff_text = ""; //ファイルが終了するまで while(line != null){ //改行を加えて溜め込む buff_text = buff_text + line + "\n"; line = in2.readLine(); } } catch(Exception e) { System.out.println("read-error:"+e.getMessage()); } repaint(); } if ((w_type==Display.KEY_PRESSED_EVENT) && (w_param == Display.KEY_UP)){ if(y > 0){ y--; repaint(); } } if ((w_type==Display.KEY_PRESSED_EVENT) && (w_param == Display.KEY_DOWN)){ y++; repaint(); } } } } [PR]動画