<!
DOCTYPE HTML
>
<
html
>
<
head
>
<
title
></
title
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=utf-8"
/>
<!--
<script src="http://www.cnblogs.com/libs/MicrosoftAjax/MicrosoftAjax.js" type="text/javascript"></script>
-->
<
script
src
="http://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"
type
="text/javascript"
></
script
>
<
script
type
="text/javascript"
>
Type.registerNamespace(
"
jweaving.tutorials
"
);
jweaving.tutorials.Style
=
function
() {
};
jweaving.tutorials.Style.prototype
=
{
NORMAL :
1
,
BOLD :
2
,
ITALIC :
3
,
UNDERLINE :
4
}
jweaving.tutorials.Style.registerEnum(
"
jweaving.tutorials.Style
"
);
jweaving.tutorials.TextBlock
=
function
(name, text) {
this
._name
=
name;
this
._text
=
text;
this
._color
=
"
#000000
"
;
this
._style
=
"
normal
"
;
};
jweaving.tutorials.TextBlock.prototype
=
{
getName :
function
() {
return
this
._name
},
getText :
function
() {
return
this
._text
},
getColor :
function
() {
return
this
._color
},
setColor :
function
(color) {
this
._color
=
color
},
getStyle :
function
() {
return
this
._style
},
setStyle :
function
(style) {
this
._style
=
style
},
write :
function
() {
if
(
this
._style
==
jweaving.tutorials.Style.BOLD) {
document.write(String.format(
'
<div><b name="{0}" style="color:{1};" >{2}</b></div>
'
,
this
._name,
this
._color,
this
._text));
}
else
if
(
this
._style
==
jweaving.tutorials.Style.ITALIC) {
document.write(String.format(
'
<div><i name="{0}" style="color:{1};" >{2}</i></div>
'
,
this
._name,
this
._color,
this
._text));
}
else
if
(
this
._style
==
jweaving.tutorials.Style.UNDERLINE) {
document.write(String.format(
'
<div><u name="{0}" style="color:{1};" >{2}</u></div>
'
,
this
._name,
this
._color,
this
._text));
}
else
{
document.write(String.format(
'
<div name="{0}" style="color:{1};" >{2}</div>
'
,
this
._name,
this
._color,
this
._text));
}
}
}
jweaving.tutorials.TextBlock.registerClass(
'
jweaving.tutorials.TextBlock
'
);
jweaving.tutorials.Button
=
function
(name, text) {
this
._name
=
name;
this
._text
=
text;
};
jweaving.tutorials.Button.prototype
=
{
getName :
function
() {
return
this
._name
},
getText :
function
() {
return
this
._text
},
toString :
function
() {
return
'
name:
'
+
this
._name
+
'
,
'
+
'
text:
'
+
this
._text;
}
}
jweaving.tutorials.Button.registerClass(
'
jweaving.tutorials.Button
'
);
jweaving.tutorials.IAction
=
function
() {
}
jweaving.tutorials.IAction.Prototype
=
{
show :
function
() {
},
execute :
function
(textBlock) {
}
}
jweaving.tutorials.IAction.registerInterface(
'
jweaving.tutorials.IAction
'
);
jweaving.tutorials.StyleButton
=
function
(name, text, style) {
jweaving.tutorials.StyleButton.initializeBase(
this
, [name, text]);
this
._style
=
style;
}
jweaving.tutorials.StyleButton.prototype
=
{
getStyle :
function
() {
return
this
._style
},
setStyle :
function
(style) {
this
._style
=
style;
},
toString :
function
() {
return
jweaving.tutorials.StyleButton.callBaseMethod(
this
,
'
toString
'
)
+
'
,
'
+
'
style:
'
+
this
._style;
},
show :
function
() {
alert(
'
样式
'
+
this
._style);
},
execute :
function
(textBlock) {
textBlock.setStyle(
this
._style);
}
}
jweaving.tutorials.StyleButton.registerClass(
'
jweaving.tutorials.StyleButton
'
, jweaving.tutorials.Button, jweaving.tutorials.IAction);
jweaving.tutorials.ColorButton
=
function
(name, text, style, color) {
jweaving.tutorials.ColorButton.initializeBase(
this
, [name, text, style]);
this
._color
=
color;
}
jweaving.tutorials.ColorButton.prototype
=
{
getColor :
function
() {
return
this
._color
},
setColor :
function
(color) {
this
._color
=
color;
},
toString :
function
() {
return
jweaving.tutorials.ColorButton.callBaseMethod(
this
,
'
toString
'
)
+
'
,
'
+
'
color:
'
+
this
._color;
},
show :
function
() {
alert(
'
颜色
'
+
this
._color);
},
execute :
function
(textBlock) {
jweaving.tutorials.ColorButton.callBaseMethod(
this
,
'
execute
'
, [textBlock]);
textBlock.setColor(
this
._color);
}
}
jweaving.tutorials.ColorButton.registerClass(
'
jweaving.tutorials.ColorButton
'
, jweaving.tutorials.StyleButton);
</
script
>
</
head
>
<
body
>
<
div
>
<
p
></
p
>
<
input
id
="Button1"
value
="Check Type"
type
="button"
onclick
="return OnButton1Click()"
/>
<
input
id
="Button2"
value
="Check Inheritance"
type
="button"
onclick
="return OnButton2Click()"
/>
<
input
id
="Button3"
value
="Check Interface"
type
="button"
onclick
="return OnButton3Click()"
/>
</
div
>
<
script
type
="text/javascript"
language
="JavaScript"
>
var
cb
=
new
jweaving.tutorials.ColorButton();
var
cbt
=
jweaving.tutorials.ColorButton;
var
a
=
new
Array(jweaving.tutorials.Button, jweaving.tutorials.StyleButton, jweaving.tutorials.ColorButton, jweaving.tutorials.IAction, Sys.IContainer);
function
OnButton1Click() {
for
(
var
i
=
0
; i
<
a.length; i
++
) {
if
(a[i].isInstanceOfType(cb)) {
alert(cbt.getName()
+
"
is a
"
+
a[i].getName()
+
"
.
"
);
}
else
alert(cbt.getName()
+
"
is not a
"
+
a[i].getName()
+
"
.
"
);
}
}
function
OnButton2Click() {
for
(
var
i
=
0
; i
<
a.length; i
++
) {
if
(cbt.inheritsFrom(a[i])) {
alert(cbt.getName()
+
"
inherits from
"
+
a[i].getName()
+
"
.
"
);
}
else
alert(cbt.getName()
+
"
does not inherit from
"
+
a[i].getName()
+
"
.
"
);
}
}
function
OnButton3Click() {
for
(
var
i
=
0
; i
<
a.length; i
++
) {
if
(Type.isInterface(a[i])) {
if
(cbt.implementsInterface(a[i])) {
alert(cbt.getName()
+
"
implements the
"
+
a[i].getName()
+
"
interface.
"
);
}
else
alert(cbt.getName()
+
"
does not implement the
"
+
a[i].getName()
+
"
interface.
"
);
}
else
alert(a[i].getName()
+
"
is not an interface.
"
);
}
}
</
script
>
</
body
>
</
html
>