2013-03-01から1ヶ月間の記事一覧

20130331【Java Script】サブウィンドウから呼び出し元の情報を取得する

お題 サブウィンドウから呼び出し元の情報を取得する ■呼び出し元 <html><head><script>function winOpen(){ window.open("sub.html","sub");}</script></head><body><form name="sample"><input type="button" value="サンプル" onclick="winOpen()"><input type="hidden" name="num" value="123"><input type="hidden" name="str" value="string"></form></body></html>

20130330 【Java Script】サブウィンドウのオプションを使う

お題 サブウィンドのオプションを使う。 サンプルはツールバーをon/offにするオプション。 ■ソース <html><head><script>function subWin(option){ window.open("sub.html","sub","width=640,height=480,top=0,left=0" +","+option);}</script></head> <body><form><input type="button" value="ツールバーON" onclick="subWin('toolbar=yes')"><br></form></body></html>

20130329 【Java Script】サブウィンドウを表示する

お題 サブウィンドウを表示する ■ソース <html><head><script> function winOpen(){ window.open("../index.html","sub"); } </script></head> <body><form><input type="button" value="サブウィンドウ" onclick="winOpen()"></form></body></html> ポイント window.open("URL","ウィンドウ名")指定したウィンドウ名でサブウィンドウを表示させます

20130328【Java Script】インラインフレームでのリンク指定

お題 インラインフレームに表示するページを変更する ■ソース <html><head><script> function ifr(jpURL){ waku.location = jpURL;} </script></head> <body><a href="JavaScript:ifr('http://○○○')">別ののページへ</a><br> <iframe src="http://▲▲▲" name="waku" width="100%" height="80%"></iframe></body></html> 説明 最初は関数ifrの宣言をしています。 引数jpURLを指定し、ここにリ…

20130327【Java Script】戻れないページ

お題 戻れないページを作る ■ソース <html><head></head><body><script>function goTop(){ location.replace("http://www.yahoo.co.jp/");}</script><form><input type="button" value="サンプル" onclick="goTop()";></form></body></html>

20130326【Java】Bridgeパターン サンプル

お題 Bridgerパターンについて学ぶ。 サンプルコードと説明は結城浩さんのデザインパターン入門より。 ■Displayクラス public class Display { private DisplayImpl impl; public Display(DisplayImpl impl) { this.impl = impl; } public void open(){ impl…

20130325【Java Script】戻る・進む・更新ボタンを作る

お題 戻る・進む・更新ボタンを作る ■ソース <html><head><script> //戻るfunction modoru(){ history.back();} //進むfunction susumu(){ history.forward();} //更新function koshin(){ location.reload();} </script></head> <body><form><input type="button" value="戻る" onclick="modoru()"></form></body></html>

20130324【Java Script】セレクトボックスでナビゲーション作成

お題 セレクトボックスを使って、ナビゲーションを作成する。 ■ソース <html><head><script> var urls = new Array("", // ダミーの項目"http://www.yahoo.co.jp","http://google.co.jp"); function selectNavi(){ var num; num=document.navi.contents.selectedIndex; //最初の</script></head></html>…

20130323【Java Script】パスワード入力によるページ移動

お題 プロンプトにパスワードを入力して、ページ移動をする。 ■ソース <html><head><script> var password;password = prompt("Please enter password",""); if (password == "password"){ location.href = "success.html";} else { alert("Password is invalid");} </script></head><body></body></html> <ポイント…

20130322【Java】Abstract Factoryパターン(おまけ)

お題 20130321【Java】Abstract Factoryパターン(後半)からの続き 別の具体的な工場を追加する。 <最終アウトプット> <html><head><title>LinkPage</title></head><body><h1>LinkPage</h1><table width="80%" border="3"><tr><td><table width="100%" border="1"><tr><td bgcolor="#cccccc" align="center" colspan="2"><b>新聞</b></td></tr><tr><td></td></tr></table></td></tr></table></body></html>

20130321【Java】Abstract Factoryパターン(後半)

お題 20130320【Java】Abstract Factoryパターン(前半)からの続き http://mocomei.hatenablog.com/entry/2013/03/20/220342 ソースコード ■Mainクラス import factory.*; public class Main{ public static void main(String[] args) { if(args.length != …

20130320【Java】Abstract Factoryパターン(前半)

お題 Abstract Factoryパターンについて学ぶ (結城さんのデザインパターン入門の第8章のサンプルプログラムより。下記の説明も一部抜粋) 概要 AbstractFactoryパターンでは、抽象的な工場が登場し、抽象的な部品を組み合わせて抽象的な製品を作ります。つ…

20130319【Java Script】プロンプトを使う

お題 Java Scriptでプロンプトを使う。 ■ソース <html><head></head><body><script> var str; //入力文字を入れる変数 //インプットボックスの表示&入力文字をstrに代入str=prompt("名前を教えて下さい。",""); //strが空の場合の処理if (str=="" || str==null ) str="hoge"; //名前を表示す</body></html>…

20130318 【Java Script】confirmダイアログを使って正誤クイズを作る

お題 confirmダイアログを使って正誤クイズを作る 概要 ダイアログに問題が出力されるのでYES(OK) or NO(キャンセル)で答える。 一問20点とし、5題出題される。 最後に合計点数が表示され、100点であれば合格、それ以外は不合格と表示される。 ■ソー…

20130317【Java】Builderパターン 練習問題

お題 結城さんのデザインパターン入門 7章builderパターンの問題7-2より。 問題 サンプルプログラムのHTMLBuilderクラスでは、makeTitleメソッドを最初に呼び出す必要がありますが、TextBuilderクラスでは、メソッドを呼び出す順序に制限はありません。Build…

20130316 【Java Script】confirmダイアログを使う

お題 confirmダイアログを使う ■ソースコード <html><head</head><body><script> var flg; //真偽を入れる変数の宣言var rand=Math.floor(Math.random()*10) % 3; // 乱数発生 flg=confirm("背景の色を変えてもいいですか?"); //真偽の代入 if (flg==true) { if (rand == 0) { document.bgCo</body></head</head></html>…

20130315 Builderパターン サンプル

お題 Builderパターンについて学ぶ。 (結城さんのデザインパターン入門の第7章より) 概要 ビルディングを建てるとき、まず地盤を固め、骨組みを作り、下から上に少しずつ作っていきます。一般に、複雑な構造を持ったものを作り上げるとき、一気に完成させ…

20130314 Java Script 外部ファイルを使う

お題 Java Scriptで外部ファイルを使う ■modi.js (外部ファイル) function koshin(){ var hiduke=document.lastModified; document.write(hiduke);} ■index.html(外部ファイルを使う側) <head> <script type="text/javascript" src="modi.js"></script></head> <body><script> koshin(); </script></body> <実行結果> 03/14/2013 23:59:05 (index.htmlの…

20130313 Java Script  条件式を使う

お題 Java Scriptで条件式を使う。 サンプルはif分 ■ソースコード <html><head></head> <body><script> var n=10; if ( n > 5 ) { alert("5より大きいです!");} </script></body></html> <実行結果>

20130312 Java Script 関数を使う②

お題 Java Scriptで関数を使う②(引数あり版) ■ソースコード <html><head><script> function jijyo(a,b,c){ return a*b*c; } </script></head> <body><script>document.write("3の3乗は"+jijyo(3,3,3)+"です。<br>");document.write("5の3乗は"+jijyo(5,5,5)+"です。");</script></body></html> <実行結果> 3の3乗は27です。5の3乗は…

20130311 Java Script 関数を使う

お題 Java Scriptで関数を使う ■サンプルコード <html><head><script> function aisatu(){ alert("おはよう"); alert("こんにちは"); alert("こんばんは");} </script></head> <body><form><input type="button" value="ボタン1" onclick="aisatu()"><br><input type="button" value="ボタン2" onclick="aisatu()"></form></body></html> どちらのボタンを押しても同じアラートが表示…

20130310 Java Script 変数

お題 Java Scriptで変数を扱う <script> var n; n=1;document.write(n+"<br>");n=n+2;document.write(n+"<br>");n++;document.write(n+"<br>"); </script>

20130309 Prototype サンプル

お題 デザインパターンのPrototypeのサンプルを書く。 結城さんのデザインパターン入門 6章より。 <概要> Prototypeとはクラスからインスタンスを作るのではなく、インスタンスからインスンタスを作るとのこと。原型となるインスタンスを元に新しいインス…

20130308 Java Script 変数

お題 Java Scriptで変数を扱う varで宣言。 <script> var num1=10;var num2=5; alert( num1 + num2 );alert( num1 - num2 );alert( num1 * num2 );alert( num1 / num2 ); </script> ちなみに、数字 + 文字列 文字列 + 文字列でもいけるらしい。

20130307 Java Script 文字を表示させる

お題 Java Scriptで文字を表示させる。 ■ソース <script>document.write("<b>10+20</b>の答えは");document.write(10+20);document.write("です!");</script> <結果> 10+20の答えは30です! document.write()という部分が、文字を表示する命令 document.writeは数字の計算も…

20130306 java script alert

お題 java scriptでalertを出力する。 ■index.html <script>alert("ようこそ!");</script> デバッグで使ったりするらしい。

20130305 checkbox

お題 HTMLでcheckboxを使用する場合の、jsp及び、servletの書き方 (strutsのmultiboxを使う必要がでてきそうなので基礎のおさらい。) ■index.jsp <%@ page pageEncoding="Windows-31J" contentType="text/html; charset=Windows-31J" %> <html><head><title>checkboxtest</title></head><body> <h1>よう</h1></body></html>…

20130304 TreeMap

import java.util.TreeMap;import java.util.Iterator; public class TreeMapSample { public static void main(String args[]) { //TreeMapデータを作成 TreeMap<String, String> tm = new TreeMap<String, String>(); tm.put("D", "DDD"); tm.put("A", "AAA"); tm.put("C", "CCC"); tm.put(</string,></string,>…

20130303 singleton 問題

結城さんのデザインパターン入門5章のsingletonの問題5-2より。 ●問題5-2インスタンスの個数が3個に限定されているクラスTripleを作ってください。インスタンスには0,1,2という番号がついており、getlnstance(inti d)でid番のインスタンスが得られるものと…

はじめに

一日、最低一ステップかかさずコーディングすることを目標にするぶろぐ。 言語は基本Javaで内容は気まぐれです。宜しくお願いします。