Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
bf5c4b92
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看板
提交
bf5c4b92
编写于
3月 24, 2011
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7027680: /applets/DrawTest demo needs to be improved
Reviewed-by: rupashka
上级
b834c127
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
44 deletion
+81
-44
src/share/demo/applets/DrawTest/DrawTest.java
src/share/demo/applets/DrawTest/DrawTest.java
+81
-44
未找到文件。
src/share/demo/applets/DrawTest/DrawTest.java
浏览文件 @
bf5c4b92
/*
* 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,27 +29,46 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import
java.awt.event.*
;
import
java.awt.*
;
import
java.applet.*
;
import
java.applet.Applet
;
import
java.awt.BorderLayout
;
import
java.awt.Checkbox
;
import
java.awt.CheckboxGroup
;
import
java.awt.Choice
;
import
java.awt.Color
;
import
java.awt.Component
;
import
java.awt.Dimension
;
import
java.awt.FlowLayout
;
import
java.awt.Frame
;
import
java.awt.Graphics
;
import
java.awt.Panel
;
import
java.awt.Point
;
import
java.awt.Rectangle
;
import
java.awt.event.ItemEvent
;
import
java.awt.event.ItemListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseMotionListener
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Vector
;
public
class
DrawTest
extends
Applet
{
@SuppressWarnings
(
"serial"
)
public
class
DrawTest
extends
Applet
{
DrawPanel
panel
;
DrawControls
controls
;
@Override
public
void
init
()
{
setLayout
(
new
BorderLayout
());
panel
=
new
DrawPanel
();
controls
=
new
DrawControls
(
panel
);
add
(
"Center"
,
panel
);
add
(
"South"
,
controls
);
add
(
"South"
,
controls
);
}
@Override
public
void
destroy
()
{
remove
(
panel
);
remove
(
controls
);
...
...
@@ -63,22 +82,28 @@ public class DrawTest extends Applet{
f
.
add
(
"Center"
,
drawTest
);
f
.
setSize
(
300
,
300
);
f
.
s
how
(
);
f
.
s
etVisible
(
true
);
}
@Override
public
String
getAppletInfo
()
{
return
"A simple drawing program."
;
}
}
@SuppressWarnings
(
"serial"
)
class
DrawPanel
extends
Panel
implements
MouseListener
,
MouseMotionListener
{
public
static
final
int
LINES
=
0
;
public
static
final
int
POINTS
=
1
;
int
mode
=
LINES
;
Vector
lines
=
new
Vector
();
Vector
colors
=
new
Vector
();
int
x1
,
y1
;
int
x2
,
y2
;
int
mode
=
LINES
;
List
<
Rectangle
>
lines
=
new
ArrayList
<
Rectangle
>
();
List
<
Color
>
colors
=
new
ArrayList
<
Color
>
();
int
x1
,
y1
;
int
x2
,
y2
;
@SuppressWarnings
(
"LeakingThisInConstructor"
)
public
DrawPanel
()
{
setBackground
(
Color
.
white
);
addMouseMotionListener
(
this
);
...
...
@@ -87,16 +112,16 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public
void
setDrawMode
(
int
mode
)
{
switch
(
mode
)
{
case
LINES:
case
POINTS:
this
.
mode
=
mode
;
break
;
default
:
throw
new
IllegalArgumentException
();
case
LINES:
case
POINTS:
this
.
mode
=
mode
;
break
;
default
:
throw
new
IllegalArgumentException
();
}
}
@Override
public
void
mouseDragged
(
MouseEvent
e
)
{
e
.
consume
();
switch
(
mode
)
{
...
...
@@ -106,8 +131,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break
;
case
POINTS:
default
:
colors
.
add
Element
(
getForeground
());
lines
.
add
Element
(
new
Rectangle
(
x1
,
y1
,
e
.
getX
(),
e
.
getY
()));
colors
.
add
(
getForeground
());
lines
.
add
(
new
Rectangle
(
x1
,
y1
,
e
.
getX
(),
e
.
getY
()));
x1
=
e
.
getX
();
y1
=
e
.
getY
();
break
;
...
...
@@ -115,9 +140,11 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint
();
}
@Override
public
void
mouseMoved
(
MouseEvent
e
)
{
}
@Override
public
void
mousePressed
(
MouseEvent
e
)
{
e
.
consume
();
switch
(
mode
)
{
...
...
@@ -128,8 +155,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break
;
case
POINTS:
default
:
colors
.
add
Element
(
getForeground
());
lines
.
add
Element
(
new
Rectangle
(
e
.
getX
(),
e
.
getY
(),
-
1
,
-
1
));
colors
.
add
(
getForeground
());
lines
.
add
(
new
Rectangle
(
e
.
getX
(),
e
.
getY
(),
-
1
,
-
1
));
x1
=
e
.
getX
();
y1
=
e
.
getY
();
repaint
();
...
...
@@ -137,12 +164,13 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
}
}
@Override
public
void
mouseReleased
(
MouseEvent
e
)
{
e
.
consume
();
switch
(
mode
)
{
case
LINES:
colors
.
add
Element
(
getForeground
());
lines
.
add
Element
(
new
Rectangle
(
x1
,
y1
,
e
.
getX
(),
e
.
getY
()));
colors
.
add
(
getForeground
());
lines
.
add
(
new
Rectangle
(
x1
,
y1
,
e
.
getX
(),
e
.
getY
()));
x2
=
-
1
;
break
;
case
POINTS:
...
...
@@ -152,23 +180,27 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint
();
}
@Override
public
void
mouseEntered
(
MouseEvent
e
)
{
}
@Override
public
void
mouseExited
(
MouseEvent
e
)
{
}
@Override
public
void
mouseClicked
(
MouseEvent
e
)
{
}
@Override
public
void
paint
(
Graphics
g
)
{
int
np
=
lines
.
size
();
/* draw the current lines */
g
.
setColor
(
getForeground
());
for
(
int
i
=
0
;
i
<
np
;
i
++)
{
Rectangle
p
=
(
Rectangle
)
lines
.
elementA
t
(
i
);
g
.
setColor
(
(
Color
)
colors
.
elementA
t
(
i
));
for
(
int
i
=
0
;
i
<
np
;
i
++)
{
Rectangle
p
=
lines
.
ge
t
(
i
);
g
.
setColor
(
colors
.
ge
t
(
i
));
if
(
p
.
width
!=
-
1
)
{
g
.
drawLine
(
p
.
x
,
p
.
y
,
p
.
width
,
p
.
height
);
}
else
{
...
...
@@ -185,9 +217,12 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
}
@SuppressWarnings
(
"serial"
)
class
DrawControls
extends
Panel
implements
ItemListener
{
DrawPanel
target
;
@SuppressWarnings
(
"LeakingThisInConstructor"
)
public
DrawControls
(
DrawPanel
target
)
{
this
.
target
=
target
;
setLayout
(
new
FlowLayout
());
...
...
@@ -222,33 +257,35 @@ class DrawControls extends Panel implements ItemListener {
add
(
shapes
);
}
@Override
public
void
paint
(
Graphics
g
)
{
Rectangle
r
=
getBounds
();
g
.
setColor
(
Color
.
lightGray
);
g
.
draw3DRect
(
0
,
0
,
r
.
width
,
r
.
height
,
false
);
int
n
=
getComponentCount
();
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
Component
comp
=
getComponent
(
i
);
if
(
comp
instanceof
Checkbox
)
{
Point
loc
=
comp
.
getLocation
();
Dimension
d
=
comp
.
getSize
();
g
.
setColor
(
comp
.
getForeground
());
g
.
drawRect
(
loc
.
x
-
1
,
loc
.
y
-
1
,
d
.
width
+
1
,
d
.
height
+
1
);
g
.
drawRect
(
loc
.
x
-
1
,
loc
.
y
-
1
,
d
.
width
+
1
,
d
.
height
+
1
);
}
}
}
public
void
itemStateChanged
(
ItemEvent
e
)
{
if
(
e
.
getSource
()
instanceof
Checkbox
)
{
target
.
setForeground
(((
Component
)
e
.
getSource
()).
getForeground
());
}
else
if
(
e
.
getSource
()
instanceof
Choice
)
{
String
choice
=
(
String
)
e
.
getItem
();
if
(
choice
.
equals
(
"Lines"
))
{
target
.
setDrawMode
(
DrawPanel
.
LINES
);
}
else
if
(
choice
.
equals
(
"Points"
))
{
target
.
setDrawMode
(
DrawPanel
.
POINTS
);
}
@Override
public
void
itemStateChanged
(
ItemEvent
e
)
{
if
(
e
.
getSource
()
instanceof
Checkbox
)
{
target
.
setForeground
(((
Component
)
e
.
getSource
()).
getForeground
());
}
else
if
(
e
.
getSource
()
instanceof
Choice
)
{
String
choice
=
(
String
)
e
.
getItem
();
if
(
choice
.
equals
(
"Lines"
))
{
target
.
setDrawMode
(
DrawPanel
.
LINES
);
}
else
if
(
choice
.
equals
(
"Points"
))
{
target
.
setDrawMode
(
DrawPanel
.
POINTS
);
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录