ArrayListのオブジェクトへaddして、それをIteratorで回し1つずつ処理する、よく見かけるパターン。
//Test.java
package test;
import java.util.Iterator;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<SampleTbl> list = new ArrayList<SampleTbl>();
for (int i=0; i<10; i++) {
SampleTbl tbl = new SampleTbl();
tbl.setNo(i);
tbl.setProduct_id("ABC_"+i);
list.add(tbl);
}
Iterator<SampleTbl> i = list.iterator();
while(i.hasNext()) {
SampleTbl tbl = (SampleTbl)i.next();
System.out.print("No=>" + tbl.getNo() + " / ");
System.out.println("ProductId=>" + tbl.getProduct_id() );
}
}
}
値を格納するクラスも作成。
//SampleTest.java
package test;
public class SampleTbl {
private int no;
private String product_id;
/* no */
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
/* product_id */
public String getProduct_id() {
return product_id;
}
public void setProduct_id(String product_id) {
this.product_id = product_id;
}
}
■補足
Test.javaではwhileを使ってhasNext()を回しましたが、forを使ってもできます。
//Test.java パターン2
package test;
import java.util.Iterator;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<SampleTbl> list = new ArrayList<SampleTbl>();
for (int i=0; i<10; i++) {
SampleTbl tbl = new SampleTbl();
tbl.setNo(i);
tbl.setProduct_id("ABC_"+i);
list.add(tbl);
}
for (Iterator<SampleTbl> i = list.iterator(); i.hasNext();) {
SampleTbl tbl = (SampleTbl) i.next();
System.out.print("No=>" + tbl.getNo() + " / ");
System.out.println("ProductId=>" + tbl.getProduct_id() );
}
}
}
状況に応じて使い分けましょう。
Javaでスリープ処理をしたい場合、Thread.sleep()を使用します。
現在実行中のスレッドを、指定されたミリ秒数の間、スリープ (一時的に実行を停止) させます。
/** Sleepのサンプルコード */ class SleepSample { public static void main(String[] args) throws InterruptedException { SleepClass s = new SleepClass(); Thread t = new Thread(s); t.start(); } } class SleepClass implements Runnable { public void run() { System.out.println("Sleep Start"); try { Thread.sleep(3000); //ミリ秒単位で設定 } catch (InterruptedException e) { System.out.println(e); } System.out.println("Sleep End"); } }
キオスクモードとは、ブラウザのウィンドウをナビゲーション用のスクロールバーだけがある全画面表示にすることです。
これによりユーザー側がブラウザのメニューなどに触る事を阻止することが出来ます。クローズドな環境にして納品したい場合おいては有効な手段となるでしょう。
ツールバーやメニューバーを触られてはいけない場合や、右上の閉じるボタン、最小化ボタンを押されては不味い運用状況において役立ちます。
(実際こういう要件をクライアントから提示され鬱になったことが・・・)
//キオスクモードの例 "C:\Program Files\Internet Explorer\IEXPLORE.EXE" -K "http://www.yahoo.co.jp"
「ファイル名を指定して実行」より上記コマンドを貼り付けてください。-Kが肝です。Yahooのウェブサイトが全画面表示されます。
閉じる場合はalt+F4やCtrl+wで閉じます。ユーザーに勝手に閉じられては不味い場合には、Javascriptでaltキーやファンクションキー、Ctrlキーを無効化すればOKです。
このコマンドのショートカットを作成しておけば、それをクリックするだけ全画面表示になります。
このキオスクモードは2chのニュー速で質問した際に教えてもらったものです。ぽまいらありがとう。
対象のスレ:客「使いづれぇ」→SE「はぁ…」→客「Excelみたいにならないの?」→SE「(涙目)」
399 : 料理評論家(樺太):2007/10/03(水) 12:19:06 ID:2sCmDmIB0 WEBアプリなんだけど客から、 「右上の閉じるボタンを無効化しろ」と言われて涙目なんだけど、おまえらどうしてる? (IE6ベースで、右上の×ボタン無効化)
この質問を投下した後のスレの反応が面白かった。やっぱ考えることはみんな同じですよね。「仕様です」で逃げたいよなぁ・・・
しかし、スレタイが哀愁を誘いますね。よくあることなんで余計に・・・・・orz
ラジオボタンの数だけ処理を繰り返すJavascriptのサンプル。
http://blog-imgs-29.fc2.com/c/e/p/cepheid/for_loop.html
サンプル1ではdocument.result.radioButton.lengthでnameがradioButtonとなっているものの数を数えてforループしている。
//サンプル1
function sample1(){
if(document.result.radioButton.length) {
//ラジオボタンの数を取得
var cnt = document.result.radioButton.length;
alert("ラジオボタンの数:"+cnt);
for (var i = 0; i < cnt; i++) {
if (document.result.radioButton[i].checked) {
retValue = document.result.radioButton[i].value;
break;
}
}
} else {
alert("ラジオボタンが1個のみ");
if(document.result.radioButton.checked) {
retValue = document.result.radioButton.value;
}
}
return retValue;
}
サンプル2ではdocument.getElementsByName('radioButton').lengthを使いnameがradioButtonとなっているものの数を数えてforループしている。
//サンプル2
function sample2(){
//ラジオボタンの数を取得
var cnt = document.getElementsByName('radioButton').length;
alert("ラジオボタンの数:"+cnt);
for (var i = 0; i < cnt; i++){
if (document.all("radioButton").item(i).checked) {
retValue = document.all("radioButton").item(i).value;
break;
}
}
return retValue;
}なんか一ヶ月以上更新しないと勝手に広告が投稿されるようでビックリしましたよ。てっきりクラックされたのかと・・・
すごく小さな文字で注意書きが添えられてあって分かりにくいですね。まあ無料で使わせてもらってるんで文句はないんですけど。



