2008年9月27日土曜日

iアプリ ストップウォッチを作る(1)

ストップウォッチを作ろうとしています。
今日は、枠と、時間を表示するところでおしまい

改めてJavaのお勉強
http://www.y-adagio.com/public/standards/tr_javalang2/jTOC.doc.html
リファレンス
http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/

フォントの設定と枠の作成

Font f = Font.getFont(Font.FACE_SYSTEM|Font.STYLE_BOLD|Font.SIZE_LARGE);
g.setFont(f);
...

h = f.getBBoxHeight(tstr);
w = f.getBBoxWidth(tstr);
g.fillRect(x, y - h, w, h + f.getDescent());


java.lang.SystemはSystemで使える

public static long getCurrentMillis() {
return System.currentTimeMillis();
}

java.io,java.util は使える。

型変換

mtimer = Long.toString(t);


tstr = String.valueOf(t % 1000);

2008年9月13日土曜日

PREタグに入れる特殊文字の変換

以下のサイトを使った。

http://www.akiyan.com/cc_convert_html_specialchars

http://www.geocities.co.jp/Playtown-Bingo/6768/tools/no_tags.html

Bloggerのテンプレート編集

このブログのテンプレートの編集について

基本的に使いづらいのだが、おそらく、他のエディタを使って編集して投稿したほうがいいのだろう。

http://help.blogger.com/bin/answer.py?answer=46888&topic=12449を見てもよくわからない。

プログラムのコードとかのスタイルを指定したいのでスタイルシートを編集する。

ブログの管理画面から、[レイアウト]-[HTMLの編集]を選択して、テンプレートのHTMLを編集する。
うえのヘルプの意味するところでとかの説明があるが、これをみていきなりわかる人がどれだけいるのか。bはboldのタグではない。名前空間の接頭辞でgoogleが作っている。おそらくblockの略。

名前空間の設定部分。bのほかに、dataとexprの接頭辞がある。

<html expr:dir='data:blog.languageDirection'
xmlns='http://www.w3.org/1999/xhtml'
xmlns:b='http://www.google.com/2005/gml/b'
xmlns:data='http://www.google.com/2005/gml/data'
xmlns:expr='http://www.google.com/2005/gml/expr'
>


htmlを読むときは、この名前空間を全部飛ばすと、素のxhtmlになる

<head>
<title><data:blog.pageTitle/></title>
</head>
<body>
<div id='outer-wrapper'><div id='wrap2'>

<!-- skip links for text browsers -->
<span id='skiplinks' style='display:none;'>
<a href='#main'>skip to main </a> |
<a href='#sidebar'>skip to sidebar</a>
</span>

<div id='header-wrapper'>
</div>

<div id='content-wrapper'>
<div id='crosscol-wrapper' style='text-align:center'>
</div>
<div id='main-wrapper'>
</div>
<div id='sidebar-wrapper'>
</div>

<!-- spacer for skins that want sidebar and main to be the same height-->
<div class='clear'>&#160;</div>

</div> <!-- end content-wrapper -->
<div id='footer-wrapper'>
</div>

</div></div> <!-- end outer-wrapper -->
</body>
</html>

b:skin の部分がスタイル(スキン?)を指定している。

<b:skin><![CDATA[/*
-----------------------------------------------
Blogger Template Style
Name: Stretch Denim
Designer: Darren Delaye
URL: www.DarrenDelaye.com
Date: 11 Jul 2006
-----------------------------------------------
*/

/* Variable definitions
====================
<Variable name="bgColor" description="Page Background Color"
type="color" default="#efefef" value="#efefef">
<Variable name="textColor" description="Text Color"
type="color" default="#333333" value="#333333">
<Variable name="linkColor" description="Link Color"
type="color" default="#336699" value="#336699">

<Variable name="headerBgColor" description="Page Header Background Color"
type="color" default="#336699" value="#336699">
<Variable name="headerTextColor" description="Page Header Text Color"
type="color" default="#ffffff" value="#ffffff">
<Variable name="headerCornersColor" description="Page Header Corners Color"
type="color" default="#528bc5" value="#528bc5">

<Variable name="mainBgColor" description="Main Background Color"
type="color" default="#ffffff" value="#ffffff">
<Variable name="borderColor" description="Border Color"
type="color" default="#cccccc" value="#cccccc">
<Variable name="dateHeaderColor" description="Date Header Color"
type="color" default="#999999" value="#999999">

<Variable name="sidebarTitleBgColor" description="Sidebar Title Background Color"
type="color" default="#ffd595" value="#ffd595">
<Variable name="sidebarTitleTextColor" description="Sidebar Title Text Color"
type="color" default="#333333" value="#333333">

<Variable name="bodyFont" description="Text Font"
type="font" default="normal normal 100% Verdana, Arial, Sans-serif;" value="normal normal 100% Verdana, Arial, Sans-serif;">
<Variable name="headerFont" description="Page Header Font"
type="font" default="normal normal 210% Verdana, Arial, Sans-serif;" value="normal normal 210% Verdana, Arial, Sans-serif;">

<Variable name="startSide" description="Start side in blog language"
type="automatic" default="left" value="left">
<Variable name="endSide" description="End side in blog language"
type="automatic" default="right" value="right">
*/

body {
background: $bgColor;
margin: 0;
padding: 0px;
font: x-small Verdana, Arial;
text-align: center;
color: $textColor;
font-size/* */:/**/small;
font-size: /**/small;
}
a:link {
color: $linkColor;
}
a:visited {
color: $linkColor;
}
a img {
border-width: 0;
}

#outer-wrapper {
font: $bodyFont;
}

.main .code {
background-color:silver;
}
/* Header
----------------------------------------------- */
#header-wrapper {
margin:0;
padding: 0;
background-color: $headerCornersColor;
text-align: $startSide;
}

#header {
margin: 0 2%;
background-color: $headerBgColor;
color: $headerTextColor;
padding: 0;
font: $headerFont;
position: relative;
}

h1.title {
padding-top: 38px;
margin: 0 1% .1em;
line-height: 1.2em;
font-size: 100%;
}

h1.title a, h1.title a:visited {
color: $headerTextColor;
text-decoration: none;
}

#header .description {
display: block;
margin: 0 1%;
padding: 0 0 40px;
line-height: 1.4em;
font-size: 50%;
}

/* Content
----------------------------------------------- */

.clear {
clear: both;
}


#content-wrapper {
margin: 0 2%;
padding: 0 0 15px;
text-align: $startSide;
background-color: $mainBgColor;
border: 1px solid $borderColor;
border-top: 0;
}
#main-wrapper {
margin-$startSide: 1%;
width: 64%;
float: $startSide;
background-color: $mainBgColor;
display: inline; /* fix for doubling margin in IE */
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
#sidebar-wrapper {
margin-$endSide: 1%;
width: 29%;
float: $endSide;
background-color: $mainBgColor;
display: inline; /* fix for doubling margin in IE */
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}

/* Headings
----------------------------------------------- */
h2, h3 {
margin: 0;
}

/* Posts
----------------------------------------------- */
.date-header {
margin: 1.5em 0 0;
font-weight: normal;
color: $dateHeaderColor;
font-size: 100%;
}
.post {
margin: 0 0 1.5em;
padding-bottom: 1.5em;
}
.post-title {
margin: 0;
padding: 0;
font-size: 125%;
font-weight: bold;
line-height: 1.1em;
}
.post-title a, .post-title a:visited, .post-title strong {
text-decoration: none;
color: $textColor;
font-weight: bold;
}
.post div {
margin: 0 0 .75em;
line-height: 1.3em;
}

.post-footer {
margin: -.25em 0 0;
color: $textColor;
font-size: 87%;
}

.post-footer .span {
margin-$endSide: .3em;
}
.post img {
padding: 4px;
border: 1px solid $borderColor;
}
.post blockquote {
margin: 1em 20px;
}
.post blockquote p {
margin: .75em 0;
}

/* Comments
----------------------------------------------- */
#comments h4 {
margin: 1em 0;
color: $dateHeaderColor;
}
#comments h4 strong {
font-size: 110%;
}
#comments-block {
margin: 1em 0 1.5em;
line-height: 1.3em;
}
#comments-block dt {
margin: .5em 0;
}
#comments-block dd {
margin: .25em 0 0;
}
#comments-block dd.comment-footer {
margin: -.25em 0 2em;
line-height: 1.4em;
font-size: 78%;
}
#comments-block dd p {
margin: 0 0 .75em;
}

.deleted-comment {
font-style:italic;
color:gray;
}

.feed-links {
clear: both;
line-height: 2.5em;
}

#blog-pager-newer-link {
float: $startSide;
}

#blog-pager-older-link {
float: $endSide;
}

#blog-pager {
text-align: center;
}

/* Sidebar Content
----------------------------------------------- */
.sidebar h2 {
margin: 1.6em 0 .5em;
padding: 4px 5px;
background-color: $sidebarTitleBgColor;
font-size: 100%;
color: $sidebarTitleTextColor;
}

.sidebar ul {
margin: 0;
padding: 0;
list-style: none;
}
.sidebar li {
margin: 0;
padding-top: 0;
padding-$endSide: 0;
padding-bottom: .5em;
padding-$startSide: 15px;
text-indent: -15px;
line-height: 1.5em;
}
.sidebar {
color: $textColor;
line-height:1.3em;
}
.sidebar .widget {
margin-bottom: 1em;
}

.sidebar .widget-content {
margin: 0 5px;
}

/* Profile
----------------------------------------------- */
.profile-img {
float: $startSide;
margin-top: 0;
margin-$endSide: 5px;
margin-bottom: 5px;
margin-$startSide: 0;
padding: 4px;
border: 1px solid $borderColor;
}

.profile-data {
margin:0;
text-transform:uppercase;
letter-spacing:.1em;
font-weight: bold;
line-height: 1.6em;
font-size: 78%;
}

.profile-datablock {
margin:.5em 0 .5em;
}

.profile-textblock {
margin: 0.5em 0;
line-height: 1.6em;
}


/* Footer
----------------------------------------------- */
#footer {
clear: both;
text-align: center;
color: $textColor;
}

#footer .widget {
margin:.5em;
padding-top: 20px;
font-size: 85%;
line-height: 1.5em;
text-align: $startSide;
}

/** Page structure tweaks for layout editor wireframe */
body#layout #header {
width: 750px;
}
]]></b:skin>


投稿部分のセクションには、class="main"が設定されているので、

.main .code {
background-color:silver;
}

を追加すると、上記のようになる。

iアプリ 今日は Panel


また、サンプルのお世話になります。
http://omori.cside.com/java/javai34.htm
http://omori.cside.com/java/java92.htm#s6
スクラッチパッドも追加
http://omori.cside.com/java/java95.htm

高レベルAPI Panel編です。

iαppliTool for DoJa-5.1(FOMA)を起動して、新規作成。
前回よくわからず、いきなり新規作成するとPanelのテンプレートができて、
Panelの部分を削除して作った。
いまになって、Canvasのテンプレートを選択すればよかったことに気づく。

今回は、
テンプレート使用
フレームの種別:Panel
キーリスナを追加

で作成した。

今日理解したこと
  1. implement でクラス内の名前空間を追加
  2. switch文はintだけ
  3. static はクラスから参照できる
  4. IApplication.getCurrentApp() でアプリケーションを取得

/*
* second.java
*
* DATE : 2008/09/13 10:35
*/
import com.nttdocomo.ui.IApplication;
import com.nttdocomo.ui.Display;
import com.nttdocomo.ui.Panel;
import com.nttdocomo.ui.Frame;

import com.nttdocomo.ui.Component;
import com.nttdocomo.ui.Label;
import com.nttdocomo.ui.Button;
import com.nttdocomo.ui.TextBox;
import com.nttdocomo.ui.ListBox;
import com.nttdocomo.ui.MediaImage;
import com.nttdocomo.ui.Image;
import com.nttdocomo.ui.MediaManager;
import com.nttdocomo.ui.ImageLabel;
import com.nttdocomo.ui.ComponentListener;

import com.nttdocomo.io.*;
import javax.microedition.io.*;
import java.io.*;

import com.nttdocomo.ui.KeyListener;
import com.nttdocomo.ui.SoftKeyListener;

/**
* second
*
* @author NAME
*/

public class second extends IApplication {

public void start() {
/*
* The program of IApplication is written here.
*/
Display.setCurrent((Frame)new MainPanel());
}
}

/**
* MainPanel
*
*/
class MainPanel extends Panel implements KeyListener,SoftKeyListener,ComponentListener{
private IApplication app;
private Label w_label;
private ImageLabel w_imagelabel;
private Button w_button1, w_button2, w_button;
private ListBox w_listbox;
private TextBox w_textbox;
private String ww_textbox;

MainPanel() {
app = IApplication.getCurrentApp();

setTitle("Start IApplication");
// パネルに追加
add(new Label("ラベル"));

// メディアイメージを取得
// MediaImage w_media = MediaManager.getImage("resource:///image.gif");
// try {
// w_media.use();
// } catch (ConnectionException ce) {}
// Image w_image = w_media.getImage();
// イメージオブジェクトをもつイメージラベルを作成
// w_imagelabel = new ImageLabel(w_image);
// パネルに追加
// add(w_imagelabel);

// ボタン作成
w_button1 = new Button("ボタン1");
add(w_button1);
w_button2 = new Button("ボタン2");
add(w_button2);

// リストボックス作成 ※ラジオボタンの例
w_listbox = new ListBox(ListBox.RADIO_BUTTON);
w_listbox.append("ラジオボタン1");
w_listbox.append("ラジオボタン2");
// パネルに追加
add(w_listbox);

// テキストボックス
w_textbox = new TextBox("テキストボックス", 20, 1, TextBox.DISPLAY_ANY);
// パネルに追加
add(w_textbox);

// ボタン作成
w_button = new Button("ScratchPad読込");
// パネルに追加
add(w_button);
setSoftLabel(SOFT_KEY_1,"終了");
setSoftLabel(SOFT_KEY_2,"保存");

// イベントリスナーのインスタンス登録
// コンポーネントリスナー
setComponentListener(this);
setSoftKeyListener((SoftKeyListener)this);

setKeyListener((KeyListener)this);
}

// コンポーネントイベント発生時に実行
public void componentAction(Component w_component, int w_type, int w_param){
// "ボタン"が押された時に実行
if(w_type == BUTTON_PRESSED){
if (w_component == w_button) {
load();
}else if (w_component == w_button1) {
w_textbox.setText("ボタン1が押された");
}else if (w_component == w_button2) {
w_textbox.setText("ボタン2が押された");
}
}
}

public void softKeyPressed(int softKey) {
}

public void softKeyReleased(int softKey) {
switch(softKey) {
case SOFT_KEY_1:
app.terminate();
break;
case SOFT_KEY_2:
// テキストボックスからデータを受取
ww_textbox = w_textbox.getText();
// 保存
save();
break;
}
}

public void keyPressed(Panel panel, int key) {
}

public void keyReleased(Panel panel, int key) {
switch (key) {
case Display.KEY_1:
IApplication.getCurrentApp().terminate();
break;
case Display.KEY_2:
break;
case Display.KEY_3:
break;
default:
break;
}
}

//---------------------------------------------------------------------#
// 保存データ読み込み
//---------------------------------------------------------------------#
private void load(){
try{
// scratchpadから、テキストデータを読込
DataInputStream w_datainput =
Connector.openDataInputStream("scratchpad:///0");
ww_textbox = w_datainput.readUTF();
w_datainput.close();
}catch(IOException ie){
System.out.println("load err!!");
}
// データをパネルに表示
w_textbox.setText(ww_textbox);
}

//---------------------------------------------------------------------#
// データ保存
//---------------------------------------------------------------------#
public void save(){
try{
// テキストデータを、scratchpadに書込
DataOutputStream w_dataoutput =
Connector.openDataOutputStream("scratchpad:///0");
w_dataoutput.writeUTF(ww_textbox);
w_dataoutput.close();
}catch(IOException ie) {
System.out.println("save err!!");
}
}
}