Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
eae7f2e0
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eae7f2e0
编写于
3月 25, 2011
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7027683: /applets/GraphicsTest demo needs to be improved
Reviewed-by: alexp
上级
6123d99f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
310 addition
and
334 deletion
+310
-334
src/share/demo/applets/GraphicsTest/AppletFrame.java
src/share/demo/applets/GraphicsTest/AppletFrame.java
+49
-50
src/share/demo/applets/GraphicsTest/GraphicsTest.java
src/share/demo/applets/GraphicsTest/GraphicsTest.java
+261
-284
未找到文件。
src/share/demo/applets/GraphicsTest/AppletFrame.java
浏览文件 @
eae7f2e0
/*
* Copyright (c) 1997, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -29,8 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import
java.awt.Frame
;
import
java.awt.Event
;
...
...
@@ -38,26 +36,30 @@ import java.awt.Dimension;
import
java.applet.Applet
;
import
java.awt.AWTEvent
;
// Applet to Application Frame window
class
AppletFrame
extends
Frame
{
/**
* Applet to Application Frame window
*/
@SuppressWarnings
(
"serial"
)
class
AppletFrame
extends
Frame
{
public
static
void
startApplet
(
String
className
,
String
title
,
String
args
[])
{
String
args
[])
{
// local variables
Applet
a
;
Dimension
appletSize
;
try
{
try
{
// create an instance of your applet class
a
=
(
Applet
)
Class
.
forName
(
className
).
newInstance
();
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
catch
(
InstantiationException
e
)
{
return
;
}
catch
(
IllegalAccessException
e
)
{
return
;
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
catch
(
InstantiationException
e
)
{
return
;
}
catch
(
IllegalAccessException
e
)
{
return
;
}
// initialize the applet
a
.
init
();
...
...
@@ -77,27 +79,24 @@ class AppletFrame extends Frame
f
.
setSize
(
appletSize
);
// show the window
f
.
show
(
);
f
.
setVisible
(
true
);
}
// end startApplet()
// constructor needed to pass window title to class Frame
public
AppletFrame
(
String
name
)
{
public
AppletFrame
(
String
name
)
{
// call java.awt.Frame(String) constructor
super
(
name
);
}
// needed to allow window close
public
void
processEvent
(
AWTEvent
e
)
{
@Override
public
void
processEvent
(
AWTEvent
e
)
{
// Window Destroy event
if
(
e
.
getID
()
==
Event
.
WINDOW_DESTROY
)
{
if
(
e
.
getID
()
==
Event
.
WINDOW_DESTROY
)
{
// exit the program
System
.
exit
(
0
);
}
}
// end handleEvent()
}
// end class AppletFrame
src/share/demo/applets/GraphicsTest/GraphicsTest.java
浏览文件 @
eae7f2e0
/*
* Copyright (c) 1997, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -29,22 +29,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import
java.awt.*
;
import
java.util.*
;
import
java.awt.event.*
;
import
java.applet.Applet
;
@SuppressWarnings
(
"serial"
)
class
GraphicsPanel
extends
Panel
{
ActionListener
al
;
ItemListener
il
;
public
GraphicsCards
cards
;
GraphicsPanel
(
EventListener
listener
)
{
al
=
(
ActionListener
)
listener
;
il
=
(
ItemListener
)
listener
;
al
=
(
ActionListener
)
listener
;
il
=
(
ItemListener
)
listener
;
setLayout
(
new
BorderLayout
());
...
...
@@ -78,62 +79,75 @@ class GraphicsPanel extends Panel {
setSize
(
400
,
400
);
}
@Override
public
Dimension
getPreferredSize
()
{
return
new
Dimension
(
200
,
100
);
}
}
@SuppressWarnings
(
"serial"
)
public
class
GraphicsTest
extends
Applet
implements
ActionListener
,
ItemListener
{
implements
ActionListener
,
ItemListener
{
GraphicsPanel
mainPanel
;
@Override
public
void
init
()
{
setLayout
(
new
BorderLayout
());
add
(
"Center"
,
mainPanel
=
new
GraphicsPanel
(
this
));
}
@Override
public
void
destroy
()
{
remove
(
mainPanel
);
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
String
arg
=
e
.
getActionCommand
();
if
(
"next"
.
equals
(
arg
))
{
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
next
(
mainPanel
.
cards
);
}
else
if
(
"previous"
.
equals
(
arg
))
{
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
previous
(
mainPanel
.
cards
);
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
next
(
mainPanel
.
cards
);
}
else
if
(
"previous"
.
equals
(
arg
))
{
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
previous
(
mainPanel
.
cards
);
}
}
@Override
public
void
itemStateChanged
(
ItemEvent
e
)
{
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
show
(
mainPanel
.
cards
,(
String
)
e
.
getItem
());
((
CardLayout
)
mainPanel
.
cards
.
getLayout
()).
show
(
mainPanel
.
cards
,
(
String
)
e
.
getItem
());
}
public
static
void
main
(
String
args
[])
{
AppletFrame
.
startApplet
(
"GraphicsTest"
,
"Graphics Test"
,
args
);
}
@Override
public
String
getAppletInfo
()
{
return
"An interactive demonstration of some graphics."
;
}
}
// end class GraphicsTest
@SuppressWarnings
(
"serial"
)
class
GraphicsCards
extends
Panel
{
public
GraphicsCards
()
{
setLayout
(
new
CardLayout
());
add
(
"Arc"
,
new
ArcCard
());
add
(
"Oval"
,
new
ShapeTest
(
new
OvalShape
()
)
);
add
(
"Polygon"
,
new
ShapeTest
(
new
PolygonShape
()
)
);
add
(
"Rect"
,
new
ShapeTest
(
new
RectShape
()
)
);
add
(
"RoundRect"
,
new
ShapeTest
(
new
RoundRectShape
()
)
);
add
(
"Oval"
,
new
ShapeTest
(
new
OvalShape
())
);
add
(
"Polygon"
,
new
ShapeTest
(
new
PolygonShape
())
);
add
(
"Rect"
,
new
ShapeTest
(
new
RectShape
())
);
add
(
"RoundRect"
,
new
ShapeTest
(
new
RoundRectShape
())
);
}
}
// end class GraphicsCards
@SuppressWarnings
(
"serial"
)
class
ArcCard
extends
Panel
{
public
ArcCard
()
{
setLayout
(
new
GridLayout
(
0
,
2
));
add
(
new
ArcPanel
(
true
));
...
...
@@ -144,7 +158,9 @@ class ArcCard extends Panel {
}
// end class ArcCard
@SuppressWarnings
(
"serial"
)
class
ArcDegreePanel
extends
Panel
{
boolean
filled
;
public
ArcDegreePanel
(
boolean
filled
)
{
...
...
@@ -163,34 +179,32 @@ class ArcDegreePanel extends Panel {
int
a2
=
step
;
int
progress
=
0
;
g
.
setColor
(
c1
);
for
(;
(
a1
+
a2
)
<=
360
;
a1
=
a1
+
a2
,
a2
+=
1
)
{
for
(;
(
a1
+
a2
)
<=
360
;
a1
=
a1
+
a2
,
a2
+=
1
)
{
if
(
g
.
getColor
()
==
c1
)
{
g
.
setColor
(
c2
);
}
else
{
}
else
{
g
.
setColor
(
c1
);
}
if
(
filled
)
{
g
.
fillArc
(
x
,
y
,
w
,
h
,
a1
,
a2
);
}
else
{
}
else
{
g
.
drawArc
(
x
,
y
,
w
,
h
,
a1
,
a2
);
}
progress
=
a1
+
a2
;
progress
=
a1
+
a2
;
}
// end for
if
(
progress
!=
360
)
{
if
(
filled
)
{
g
.
fillArc
(
x
,
y
,
w
,
h
,
a1
,
360
-
progress
);
}
else
{
}
else
{
g
.
drawArc
(
x
,
y
,
w
,
h
,
a1
,
360
-
progress
);
}
}
// end if
}
// end arcSteps()
@Override
public
void
paint
(
Graphics
g
)
{
Rectangle
r
=
getBounds
();
...
...
@@ -218,159 +232,137 @@ class ArcDegreePanel extends Panel {
}
// end class ArcDegreePanel
@SuppressWarnings
(
"serial"
)
class
ArcPanel
extends
Panel
{
boolean
filled
;
public
ArcPanel
(
boolean
filled
)
{
this
.
filled
=
filled
;
}
public
void
paint
(
Graphics
g
)
{
@Override
public
void
paint
(
Graphics
g
)
{
Rectangle
r
=
getBounds
();
g
.
setColor
(
Color
.
yellow
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
0
,
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
0
,
45
);
}
g
.
setColor
(
Color
.
green
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
90
,
-
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
90
,
-
45
);
}
g
.
setColor
(
Color
.
orange
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
135
,
-
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
135
,
-
45
);
}
g
.
setColor
(
Color
.
magenta
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
225
,
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
225
,
45
);
}
g
.
setColor
(
Color
.
yellow
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
225
,
-
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
225
,
-
45
);
}
g
.
setColor
(
Color
.
green
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
135
,
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
135
,
45
);
}
g
.
setColor
(
Color
.
orange
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
45
,
-
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
-
45
,
-
45
);
}
g
.
setColor
(
Color
.
magenta
);
if
(
filled
)
{
if
(
filled
)
{
g
.
fillArc
(
0
,
0
,
r
.
width
,
r
.
height
,
315
,
45
);
}
else
{
}
else
{
g
.
drawArc
(
0
,
0
,
r
.
width
,
r
.
height
,
315
,
45
);
}
}
// end paint()
}
// end class ArcPanel
abstract
class
Shape
{
abstract
class
Shape
{
abstract
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
);
abstract
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
);
}
class
RectShape
extends
Shape
{
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
class
RectShape
extends
Shape
{
@Override
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
drawRect
(
x
,
y
,
w
,
h
);
}
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
@Override
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
fillRect
(
x
,
y
,
w
,
h
);
}
}
class
OvalShape
extends
Shape
{
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
class
OvalShape
extends
Shape
{
@Override
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
drawOval
(
x
,
y
,
w
,
h
);
}
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
@Override
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
fillOval
(
x
,
y
,
w
,
h
);
}
}
class
RoundRectShape
extends
Shape
{
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
class
RoundRectShape
extends
Shape
{
@Override
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
drawRoundRect
(
x
,
y
,
w
,
h
,
10
,
10
);
}
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
@Override
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
g
.
fillRoundRect
(
x
,
y
,
w
,
h
,
10
,
10
);
}
}
class
PolygonShape
extends
Shape
{
class
PolygonShape
extends
Shape
{
// class variables
Polygon
p
;
Polygon
pBase
;
public
PolygonShape
()
{
public
PolygonShape
()
{
pBase
=
new
Polygon
();
pBase
.
addPoint
(
0
,
0
);
pBase
.
addPoint
(
10
,
0
);
...
...
@@ -381,37 +373,33 @@ class PolygonShape extends Shape
pBase
.
addPoint
(
0
,
0
);
}
void
scalePolygon
(
float
w
,
float
h
)
{
void
scalePolygon
(
float
w
,
float
h
)
{
p
=
new
Polygon
();
for
(
int
i
=
0
;
i
<
pBase
.
npoints
;
++
i
)
{
p
.
addPoint
(
(
int
)
(
pBase
.
xpoints
[
i
]
*
w
),
(
int
)
(
pBase
.
ypoints
[
i
]
*
h
)
);
for
(
int
i
=
0
;
i
<
pBase
.
npoints
;
++
i
)
{
p
.
addPoint
((
int
)
(
pBase
.
xpoints
[
i
]
*
w
),
(
int
)
(
pBase
.
ypoints
[
i
]
*
h
));
}
}
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
@Override
void
draw
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
Graphics
ng
=
g
.
create
();
try
{
ng
.
translate
(
x
,
y
);
scalePolygon
(
(
float
)
(
(
float
)
w
/
(
float
)
10
),
(
float
)
(
(
float
)
h
/
(
float
)
20
)
);
scalePolygon
(((
float
)
w
/
10
f
),
((
float
)
h
/
20
f
));
ng
.
drawPolygon
(
p
);
}
finally
{
ng
.
dispose
();
}
}
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
@Override
void
fill
(
Graphics
g
,
int
x
,
int
y
,
int
w
,
int
h
)
{
Graphics
ng
=
g
.
create
();
try
{
ng
.
translate
(
x
,
y
);
scalePolygon
(
(
float
)
(
(
float
)
w
/
(
float
)
10
),
(
float
)
(
(
float
)
h
/
(
float
)
20
)
);
scalePolygon
(((
float
)
w
/
10
f
),
((
float
)
h
/
20
f
));
ng
.
fillPolygon
(
p
);
}
finally
{
ng
.
dispose
();
...
...
@@ -420,22 +408,22 @@ class PolygonShape extends Shape
}
class
ShapeTest
extends
Panel
{
@SuppressWarnings
(
"serial"
)
class
ShapeTest
extends
Panel
{
Shape
shape
;
int
step
;
public
ShapeTest
(
Shape
shape
,
int
step
)
{
public
ShapeTest
(
Shape
shape
,
int
step
)
{
this
.
shape
=
shape
;
this
.
step
=
step
;
}
public
ShapeTest
(
Shape
shape
)
{
public
ShapeTest
(
Shape
shape
)
{
this
(
shape
,
10
);
}
@Override
public
void
paint
(
Graphics
g
)
{
Rectangle
bounds
=
getBounds
();
...
...
@@ -443,35 +431,22 @@ class ShapeTest extends Panel
Color
color
;
for
(
color
=
Color
.
red
,
cx
=
bounds
.
x
,
cy
=
bounds
.
y
,
cw
=
bounds
.
width
/
2
,
ch
=
bounds
.
height
;
for
(
color
=
Color
.
red
,
cx
=
bounds
.
x
,
cy
=
bounds
.
y
,
cw
=
bounds
.
width
/
2
,
ch
=
bounds
.
height
;
cw
>
0
&&
ch
>
0
;
cx
+=
step
,
cy
+=
step
,
cw
-=
(
step
*
2
),
ch
-=
(
step
*
2
),
color
=
ColorUtils
.
darker
(
color
,
0.9
)
)
{
cx
+=
step
,
cy
+=
step
,
cw
-=
(
step
*
2
),
ch
-=
(
step
*
2
),
color
=
ColorUtils
.
darker
(
color
,
0.9
))
{
g
.
setColor
(
color
);
shape
.
draw
(
g
,
cx
,
cy
,
cw
,
ch
);
}
for
(
cx
=
bounds
.
x
+
bounds
.
width
/
2
,
cy
=
bounds
.
y
,
cw
=
bounds
.
width
/
2
,
ch
=
bounds
.
height
;
for
(
cx
=
bounds
.
x
+
bounds
.
width
/
2
,
cy
=
bounds
.
y
,
cw
=
bounds
.
width
/
2
,
ch
=
bounds
.
height
;
cw
>
0
&&
ch
>
0
;
cx
+=
step
,
cy
+=
step
,
cw
-=
(
step
*
2
),
ch
-=
(
step
*
2
)
)
{
cx
+=
step
,
cy
+=
step
,
cw
-=
(
step
*
2
),
ch
-=
(
step
*
2
))
{
if
(
g
.
getColor
()
==
Color
.
red
)
{
g
.
setColor
(
Color
.
blue
);
}
else
{
}
else
{
g
.
setColor
(
Color
.
red
);
}
...
...
@@ -480,16 +455,18 @@ class ShapeTest extends Panel
}
// end paint()
}
// end class ShapeTest
class
ColorUtils
{
static
Color
brighter
(
Color
c
,
double
factor
)
{
return
new
Color
(
Math
.
min
((
int
)(
c
.
getRed
()
*(
1
/
factor
)),
255
),
Math
.
min
((
int
)(
c
.
getGreen
()*(
1
/
factor
)),
255
),
Math
.
min
((
int
)(
c
.
getBlue
()
*(
1
/
factor
)),
255
)
);
return
new
Color
(
Math
.
min
((
int
)
(
c
.
getRed
()
*
(
1
/
factor
)),
255
),
Math
.
min
((
int
)
(
c
.
getGreen
()
*
(
1
/
factor
)),
255
),
Math
.
min
((
int
)
(
c
.
getBlue
()
*
(
1
/
factor
)),
255
)
);
}
static
Color
darker
(
Color
c
,
double
factor
)
{
return
new
Color
(
Math
.
max
((
int
)(
c
.
getRed
()
*
factor
),
0
),
Math
.
max
((
int
)(
c
.
getGreen
()*
factor
),
0
),
Math
.
max
((
int
)(
c
.
getBlue
()
*
factor
),
0
)
);
return
new
Color
(
Math
.
max
((
int
)
(
c
.
getRed
()
*
factor
),
0
),
Math
.
max
((
int
)
(
c
.
getGreen
()
*
factor
),
0
),
Math
.
max
((
int
)
(
c
.
getBlue
()
*
factor
),
0
)
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录