

![]() |
![]() |
var superObject = function(){
this.soProperty = "super";
this.soMethod = function(){
alert( "You called method 'soMethod', that is super object." );
}
}
var subObject = function(){}
subObject.prototype = new superObject();
alert( subObject.prototype.soProperty ); // "super"
subObject.soMethod() // "You called method 'soMethod', that is super object."
var superObject1 = function(){
this.soProperty1 = "super1";
this.soMethod1 = function(){
alert( "called soMethod1" );
}
}
var superObject2 = function(){
this.soProperty2 = "super2";
this.soMethod2 = function(){
alert( "called soMethod2" );
}
}
var subObject = function( id ){
this.subObjectId = id;
this.extension1 = superObject1;
this.extension1();
this.extension2 = superObject2;
this.extension2();
}
subObject.prototype = {
subMethod : function(){
alert( "called subMethod" );
}
}
var instance = new subObject( "instance" );
alert( instance.soProperty1 ); // "super1"
instance.soMethod1() // "called soMethod1"
alert( instance.soProperty2 ); // "super2"
instance.soMethod2() // "called soMethod2"
alert( instance.subObjectId ); // "instance"
instance.subMethod(); // "called subMethod"
![]() |
![]() |
![]() |
![]() |
import com.nttdocomo.ui.*;
import com.nttdocomo.io.*;
import com.nttdocomo.system.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class TransportImage extends IApplication {
Panel mainPanel;
Button transportImage;
public void start() {
mainPanel = new Panel();
transportImage = new Button("画像選択");
mainPanel.add(transportImage);
TransportImageListener til = new TransportImageListener();
mainPanel.setComponentListener(til);
Display.setCurrent(mainPanel);
}
class TransportImageListener implements ComponentListener{
public void componentAction(Component c,int type,int param){
if(c == transportImage){
Dialog confirmationDialog = new Dialog(Dialog.DIALOG_YESNO,"確認");
String confirmationText = "画像をサーバーへ送信します。";
confirmationDialog.setText(confirmationText);
int dialogButtonType = confirmationDialog.show();
if(dialogButtonType == Dialog.BUTTON_YES){
try{
ImageStore selectImage = ImageStore.selectEntry();
InputStream imageInputStream = selectImage.getInputStream();
Random rand = new Random();
String sessionId = Integer.toString(rand.nextInt());
byte[] imageByte = new byte[50000]; // 転送ファイルサイズ上限
boolean loopFlag = true; // while文用フラグ
int length = 500;
int readLength = length;
int i = 0;
while(loopFlag){
HttpConnection con = (HttpConnection)Connector.open(
"http://localhost:80/test/IAppliImageTest2.php?sid="+sessionId,
Connector.READ_WRITE,
true);
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("Content-Type","text/plain");
OutputStream out = con.openOutputStream();
if(readLength < length){
String endOfFile = "EndOfFile";
OutputStreamWriter writer = new OutputStreamWriter(out);
writer.write(endOfFile);
writer.close();
readLength = 0;
loopFlag = false;
}else{
int offset = i * length;
readLength = imageInputStream.read(imageByte,offset,length);
out.write(imageByte,offset,length);
out.flush();
out.close();
con.connect();
con.close();
++i;
}
}catch(Exception e){
System.out.println(e.toString());
Dialog errorDialog = new Dialog(Dialog.DIALOG_INFO,"警告");
errorDialog.setText("エラーが発生しました。");
errorDialog.show();
}
}
}
}
}
}
<?php
$session = new session();
mb_internal_encoding('SJIS');
$data = null;
$file_source = fopen('php://input','rb');
while(!feof($file_source)){
$data .= fgetc($file_source);
}
if($data == "EndOfFile"){
$hex = bin2hex($_SESSION["part_of_image"]);
if(preg_match('/^ffd8.*$/',$hex)){
$file_extension = ".jpg";
}elseif(preg_match('/^474946.*$/',$hex)){
$file_extension = ".gif";
}else{
$file_extension = ".dat";
}
$unique = uniqid('image_');
$file_name = $unique . $file_extension;
$image_file = fopen('./image/'.$file_name ,'wb');
fwrite($image_file,$_SESSION["part_of_image"]);
fclose($image_file);
}else{
$_SESSION["part_of_image"] .= $data;
}
fclose($file_source);
class session{
var $sid;
function session(){
$tmp_dir = "./tmp";
session_save_path($tmp_dir);
if($_REQUEST[sid]!=NULL){$this->sid=session_id($_REQUEST[sid]);}
session_start();
$this->sid=session_id();
}
}
?>
![]() |
![]() |
import com.nttdocomo.ui.*;
import com.nttdocomo.io.*;
import java.io.*;
import javax.microedition.io.*;
public class ConnectTest090208 extends IApplication {
Panel panelObject;
Button buttonObject;
SetComponent componentListenerObject;
TextBox textObject;
public void start() {
panelObject = new Panel();
buttonObject = new Button("送信");
textObject = new TextBox("テキストを入力して下さい",20,5,TextBox.DISPLAY_ANY);
// コンポーネントを配置
panelObject.add(textObject);
panelObject.add(buttonObject);
// イベントリスナーを設定
componentListenerObject = new SetComponent();
panelObject.setComponentListener(componentListenerObject);
// パネル表示
Display.setCurrent(panelObject);
}
class SetComponent implements ComponentListener{
public void componentAction(Component c,int type,int param){
// コンポーネント「送信」ボタンが押された時
if(c == buttonObject){
// メッセージ送信確認ダイアログ
int dialogType = Dialog.DIALOG_YESNO;
String dialogTitle = "確認";
Dialog dialogFrame = new Dialog(dialogType,dialogTitle);
dialogFrame.setText("送信します。");
/*
* dialogFrame.show()でダイアログを表示
* Display.setCurrent(dialogFrame)ではダメ
* int dialogButtonTypeで押されたボタンタイプを受け取る
*
*/
int dialogButtonType = dialogFrame.show();
// yesボタンが押された時
if(dialogButtonType == Dialog.BUTTON_YES){
sendData();
}
}
}
public void sendData(){
String textData = textObject.getText();
OutputStream out;
// HttpConnection型のリソースはtry〜catchの中に記述しなければならない。
HttpConnection con = connectToServer();
try{
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("Content-Type","text/plain");
out = con.openOutputStream();
OutputStreamWriter buffer = new OutputStreamWriter(out);
buffer.write(textData);
buffer.close();
out.close();
con.connect();
con.close();
} catch(IOException e){
}
}
public HttpConnection connectToServer(){
HttpConnection con;
OutputStream out;
con = null;
// HttpConnection型のリソースはtry〜catchの中に記述しなければならない。
try{
con = (HttpConnection)Connector.open(
"http://localhost:80/test/IAppliConnectionTest.php/",
Connector.READ_WRITE,
true
);
}
catch(IOException e){
}
return con;
}
}
}
<?php
mb_internal_encoding('SJIS');
$data = "";
$fileSource = fopen('php://input','r');
while(!feof($fileSource)){
$data .= fgetc($fileSource);
}
$to = "receiver@example.com";
$cc = "";
$bcc = "";
$sender = "sender@example";
$subject = "test";
$message = $data;
$header = "From: ".$sender;
mb_send_mail($to,$subject,$message,$header);
?>
![]() |
![]() |
修飾子
iアプリを作ってみたくなってjavaをやり始めた。
修飾子があやふやなのでまとめる事にした。
修飾子一覧 | |
---|---|
public | 全てのクラスから利用可能であることを示す。 |
protected | このクラス内および、同じパッケージ内のクラス類から利用可能。 |
private | このクラス内からのみ利用可能。 |
(なし) | このクラス内および、同じパッケージにあるクラス類、更にこのクラスを継承したクラスからのみ利用可能。 |
abstract | 抽象クラス、または抽象メソッドである事を示す。(クラス、メソッドのみの修飾子) |
static | このクラスのインスタンスを生成せずに直接利用可能であることを示す。 |
final | 変更を禁ずる。 |
クラスに用いる修飾子 | |
public | 全てのクラスから利用可能であることを示す。 |
protected | このクラス内および、同じパッケージ内のクラス類から利用可能。 |
private | このクラス内からのみ利用可能。 |
(なし) | このクラス内および、同じパッケージにあるクラス類、更にこのクラスを継承したクラスからのみ利用可能。 |
abstract | 抽象クラスである事を示す。 |
static | このクラスのインスタンスを生成せずに直接利用可能であることを示す。 |
final | このクラスの継承を禁ずる。 |
メソッドに用いる修飾子 | |
public | 全てのクラスから利用可能であることを示す。 |
protected | このクラス内および、同じパッケージ内のクラス類から利用可能。 |
private | このクラス内からのみ利用可能。 |
(なし) | protectedの範囲に加え更に、このメソッドのクラスを継承したサブクラスから利用可能。 |
abstract | 抽象メソッドである事を示す。 |
static | このクラスのインスタンスを生成せずに直接利用可能であることを示す。 |
final | このメソッドのオーバーライドを禁ずる。 |
フィールドに用いる修飾子 | |
public | 全てのクラスから利用可能であることを示す。 |
protected | このクラス内および、同じパッケージ内のクラス類からのみ利用可能。 |
private | このクラスからのみ利用可能。 |
(なし) | protectedの範囲に加え更に、このフィールドのクラスを継承したサブクラスから利用可能。 |
static | このクラスのインスタンスを生成せずに直接利用可能であることを示す。 |
final | このフィールドの変更を禁ずる。 |
抽象メソッドというのがいまいち。。。
抽象クラスとインターフェースの使い分けもいまいち、、、
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
character_set_client | utf8 |
character_set_connection | utf8 |
character_set_database | utf8 |
character_set_filesystem | binary |
character_set_results | utf8 |
character_set_server | utf8 |
character_set_system | utf8 |
| 管理者ページ | RSS1.0 | Atom0.3 | |
(C) 2019 ブログ JUGEM Some Rights Reserved.
|