Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b2f6b311
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
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看板
提交
b2f6b311
编写于
3月 25, 2011
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7027674: /applets/BarChart demo needs to be improved
Reviewed-by: alexp
上级
12e00c83
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
42 addition
and
40 deletion
+42
-40
src/share/demo/applets/BarChart/BarChart.java
src/share/demo/applets/BarChart/BarChart.java
+42
-40
未找到文件。
src/share/demo/applets/BarChart/BarChart.java
浏览文件 @
b2f6b311
/*
* 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,28 +29,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import
java.awt.*
;
/**
* A simple bar chart demo
* @author Sami Shaio
* @modified 06/21/00 Daniel Peek : refactored, comments
*/
@SuppressWarnings
(
"serial"
)
public
class
BarChart
extends
java
.
applet
.
Applet
{
private
static
final
int
VERTICAL
=
0
;
private
static
final
int
HORIZONTAL
=
1
;
private
static
final
int
SOLID
=
0
;
private
static
final
int
STRIPED
=
1
;
private
int
orientation
;
private
String
title
;
private
Font
font
;
private
FontMetrics
metrics
;
private
int
fontHeight
=
15
;
private
int
columns
;
private
int
values
[];
private
Color
colors
[];
...
...
@@ -61,6 +59,7 @@ public class BarChart extends java.applet.Applet {
private
int
barSpacing
=
10
;
private
int
maxValue
=
0
;
@Override
public
void
init
()
{
getSettings
();
...
...
@@ -70,7 +69,7 @@ public class BarChart extends java.applet.Applet {
styles
=
new
int
[
columns
];
colors
=
new
Color
[
columns
];
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
parseValue
(
i
);
parseLabel
(
i
);
parseStyle
(
i
);
...
...
@@ -112,7 +111,7 @@ public class BarChart extends java.applet.Applet {
}
private
void
parseValue
(
int
i
)
{
String
temp
=
getParameter
(
"C"
+
(
i
+
1
));
String
temp
=
getParameter
(
"C"
+
(
i
+
1
));
try
{
values
[
i
]
=
Integer
.
parseInt
(
temp
);
}
catch
(
NumberFormatException
e
)
{
...
...
@@ -124,18 +123,17 @@ public class BarChart extends java.applet.Applet {
}
private
void
parseLabel
(
int
i
)
{
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_label"
);
if
(
temp
==
null
)
{
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_label"
);
if
(
temp
==
null
)
{
labels
[
i
]
=
""
;
}
else
{
labels
[
i
]
=
temp
;
}
maxLabelWidth
=
Math
.
max
(
metrics
.
stringWidth
((
String
)
(
labels
[
i
])),
maxLabelWidth
);
maxLabelWidth
=
Math
.
max
(
metrics
.
stringWidth
(
labels
[
i
]),
maxLabelWidth
);
}
private
void
parseStyle
(
int
i
)
{
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_style"
);
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_style"
);
if
(
temp
==
null
||
temp
.
equalsIgnoreCase
(
"solid"
))
{
styles
[
i
]
=
SOLID
;
}
else
if
(
temp
.
equalsIgnoreCase
(
"striped"
))
{
...
...
@@ -146,7 +144,7 @@ public class BarChart extends java.applet.Applet {
}
private
void
parseColor
(
int
i
)
{
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_color"
);
String
temp
=
getParameter
(
"C"
+
(
i
+
1
)
+
"_color"
);
if
(
temp
!=
null
)
{
temp
=
temp
.
toLowerCase
();
if
(
temp
.
equals
(
"red"
))
{
...
...
@@ -179,6 +177,7 @@ public class BarChart extends java.applet.Applet {
}
}
@Override
public
void
paint
(
Graphics
g
)
{
// draw the title centered at the bottom of the bar graph
g
.
setColor
(
Color
.
black
);
...
...
@@ -192,7 +191,7 @@ public class BarChart extends java.applet.Applet {
g
.
drawString
(
title
,
cx
,
cy
);
// draw the bars and their titles
if
(
orientation
==
HORIZONTAL
)
{
if
(
orientation
==
HORIZONTAL
)
{
paintHorizontal
(
g
);
}
else
{
// VERTICAL
paintVertical
(
g
);
...
...
@@ -213,7 +212,8 @@ public class BarChart extends java.applet.Applet {
// set the Y coordinate for this bar and label
cy
=
getSize
().
height
-
metrics
.
getDescent
()
-
metrics
.
getHeight
()
-
barSpacing
-
((
columns
-
i
-
1
)
*
(
barSpacing
+
barHeight
));
-
barSpacing
-
((
columns
-
i
-
1
)
*
(
barSpacing
+
barHeight
));
// draw the label
g
.
setColor
(
Color
.
black
);
...
...
@@ -269,7 +269,7 @@ public class BarChart extends java.applet.Applet {
// draw the bar
g
.
setColor
(
colors
[
i
]);
if
(
styles
[
i
]
==
STRIPED
)
{
for
(
int
k
=
0
;
k
<=
values
[
i
]
*
scale
;
k
+=
2
)
{
for
(
int
k
=
0
;
k
<=
values
[
i
]
*
scale
;
k
+=
2
)
{
g
.
drawLine
(
cx
,
cy
-
k
,
cx
+
barWidth
,
cy
-
k
);
}
...
...
@@ -285,28 +285,30 @@ public class BarChart extends java.applet.Applet {
}
}
@Override
public
String
getAppletInfo
()
{
return
"Title: Bar Chart \n"
+
"Author: Sami Shaio \n"
+
"A simple bar chart demo."
;
}
@Override
public
String
[][]
getParameterInfo
()
{
String
[][]
info
=
{
{
"title"
,
"string"
,
"The title of bar graph. Default is 'Chart'"
},
{
"scale"
,
"int"
,
"The scale of the bar graph. Default is 10."
},
{
"columns"
,
"int"
,
"The number of columns/rows. Default is 5."
},
{
"orientation"
,
"{VERTICAL, HORIZONTAL}"
,
"The orienation of the bar graph. Default is VERTICAL."
},
{
"c#"
,
"int"
,
"Subsitute a number for #. "
+
"The value/size of bar #. Default is 0."
},
{
"c#_label"
,
"string"
,
"The label for bar #. "
+
"Default is an empty label."
},
{
"c#_style"
,
"{SOLID, STRIPED}"
,
"The style of bar #. "
+
"Default is SOLID."
},
{
"c#_color"
,
"{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
{
"title"
,
"string"
,
"The title of bar graph. Default is 'Chart'"
},
{
"scale"
,
"int"
,
"The scale of the bar graph. Default is 10."
},
{
"columns"
,
"int"
,
"The number of columns/rows. Default is 5."
},
{
"orientation"
,
"{VERTICAL, HORIZONTAL}"
,
"The orienation of the bar graph. Default is VERTICAL."
},
{
"c#"
,
"int"
,
"Subsitute a number for #. "
+
"The value/size of bar #. Default is 0."
},
{
"c#_label"
,
"string"
,
"The label for bar #. "
+
"Default is an empty label."
},
{
"c#_style"
,
"{SOLID, STRIPED}"
,
"The style of bar #. "
+
"Default is SOLID."
},
{
"c#_color"
,
"{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
+
"WHITE, YELLOW, GRAY, DARKGRAY}"
,
"The color of bar #. Default is GRAY."
}
"The color of bar #. Default is GRAY."
}
};
return
info
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录