| <Prev |
■テキストフィールドを極める
基本プロジェクトを作成します。作成方法はひな型プロジェクトを作るを見てください。
textfield2としてプロジェクトを作成しました。
MainMenu.nibのJapaneseをダブルクリックしてnibファイルを編集します。

window を少し小さくして、TextFieldとButtonを配置します。

名前を付けます
windowは"wi"

textFieldは"tf"

buttonは"bu"
としました。
buttonのイベントハンドラのclickedにチェックを入れ、ScriptのApprication.applescriptにチェックを入れます。

「EditScript」ボタンを押して下さい。
STEP1 枠をつけたり消したりする
text fieldの用語辞書を参照して下さい。
http://www.oomori.com/applescript/00000121/00004424.html
borderedが枠のプロパティです。
R/Oとなっているプロパティは読み出しのみで変更はできません。
プロパティborderedを変更します。
コードを記入して以下のようにして下さい。


|
on clicked theObject -- step1 tell text field "tf" of window "wi" -- 枠をつけたり消したり if bordered then --枠があるか -- ある場合 set bordered to false --枠なしにする else set bordered to true --枠なしにする end if end tell end clicked |
ビルドして実行して下さい。
ボタンを押すと枠がついたり消えたりしますね。



STEP2
用語辞書を参照して下さい。
http://www.oomori.com/applescript/00000121/00004424.html
プロパティのところに<inheritance>というのがあります。
となりにはcontrolと書いてあります。
get <inheritance>と書いてもエラーが出るし、
これはなんでしょうか
これは、controlのプロパティが使えるよ!ということなのです。
controlのクラスを見てみましょう。
用語辞書を参照して下さい。
http://www.oomori.com/applescript/00000121/00004413.html
プロパティが並んでいます。
これがText Fieldでも使えるということなのです。
早速使ってみましょう
application.applescriptの全てを以下のように書き換えて下さい。
|
on clicked theObject --step2 tell text field "tf" of window "wi" --枠をつけたり消したり if bordered then --枠があるか --ある場合 set bordered to false --枠なしにする set contents to "枠無し" --controlのプロパティcontentsを使った else --無い場合 set bordered to true --枠ありにする set contents to "枠あり" --controlのプロパティcontentsを使った end if end tell end clicked |
ビルドして実行して下さい。
ボタンを押すと文字が入力されましたね。


contentsというプロパティは「中身」ということで、text fieldの場合は表示される文字になります。
さて、controlのプロパティにも<inheritance>があります。viewクラスのプロパティが使えるということです。
viewクラスのプロパティ
http://www.oomori.com/applescript/00000121/00004396.html
早速使ってみましょう
application.applescriptの全てを以下のように書き換えて下さい。

|
on clicked theObject --step3 tell text field "tf" of window "wi" --枠をつけたり消したり if bordered then --枠があるか --ある場合 set bordered to false --枠なしにする set contents to "枠無し" --controlのプロパティcontentsを使った set tool tip to "枠無し" --viewのプロパティcontentsを使った else --無い場合 set bordered to true --枠ありにする set contents to "枠あり" --controlのプロパティcontentsを使った set tool tip to "枠あり" --viewのプロパティcontentsを使った end if end tell end clicked |
ビルドして実行して下さい。
ボタンを押した後、text fieldの上にマウスカーソルを持っていき、2〜3秒するとTool tipsが表示されます。


viewのプロパティにも<inheritance>があります。responderクラスのプロパティが使えるということです。
responderクラスのプロパティ
http://www.oomori.com/applescript/00000121/00004322.html

responderのプロパティにも<inheritance>があります。itemクラスのプロパティが使えるということです。
itemクラスのプロパティ
http://www.oomori.com/applescript/00000121/00004320.html

itemのプロパティにも<inheritance>がありますがitemになっていますので、ここで終わっています。
つながりを見てみると、
item-responder-control-text field
となっています。
このような関係はinheritance(継承)と呼ばれています。
また、text fieldはcontrolのサブクラス
controlはtext fieldのスーパークラスと言います。
おまけ、あまり意味はないですが、こんなこともできます。
application.applescriptの全てを以下のように書き換えて下さい。

|
on clicked theObject --step4 tell text field "tf" of window "wi" repeat with i from 1 to 360 set bounds rotation to i end repeat end tell end clicked |




回転したりなんかします。
2002.1.12 (C)Satoshi Oomori