/*
* ShapePanel.java
*
* Created on 2007年6月15日, 下午4:08
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package huaban;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Vector;
import javax.swing.JPanel;
public class ShapePanel extends JPanel implements MouseListener,MouseMotionListener{
int x,y;
int x1,y1;
int x2,y2;
int a,b;
int m1,n1;
int m2,n2;
boolean pressed;
Vector vector;
quxian quxian1;
int state;
Color color1;
color cl;
String sr;
/** Creates a new instance of ShapePanel */
public ShapePanel(color cl){
pressed = false;
this.cl = cl;
color1 = this.getBackground();
this.setVisible(true);
x = 0;y = 0;
x1 = 0; y1 = 0;
x2 = 0; y2 = 0;
a = 0; b = 0;
m1 = 0; m2 = 0;
n1 = 0; n2 = 0;
state = 0;
vector = new Vector();
}
public void set(int i){
state = i;
}
public void mouseClicked(MouseEvent e) {
x = e.getX();
y = e.getY();
if(state == 5 && !sr.equals(null)){
character ch = new character();
ch.setstring(sr);
ch.setpoint(x,y);
ch.setcolor(cl.getstate());
ch.setstate(5);
vector.add(ch);
repaint();
}
}
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
x1 = e.getX();
y1 = e.getY();
x2 = e.getX();
y2 = e.getY();
if(state == 2){
quxian1 = new quxian();
quxian1.setpoint(x,y,2);
}
}
public void mouseReleased(MouseEvent e) {
x2 = e.getX();
y2 = e.getY();
if(state == 1){
zhixian line = new zhixian();
line.setString(x,y,x2,y2);
line.setstate(1);
line.setcolor(cl.getstate());
vector.add(line);
}
if(state == 2){
quxian1.add(x2,y2);
quxian1.setcolor(cl.getstate());
vector.add(quxian1);
}
if(state == 3){
int m,n;
yuan circle = new yuan();
if(x2 > x){
m = x;
}
else{
m = x2;
}
if(y2 > y){
n = y;
}
else{
n = y2;
}
int r = (int)Math.sqrt((x2 - x)*(x2 - x) + (y2 - y)*(y2 - y));
circle.setyuan(m,n,r);
circle.setstate(3);
circle.setcolor(cl.getstate());
vector.add(circle);
}
if(state == 4){
int m ,n;
if(x2 - x > 0){
a = x2 - x;
m = x;
}
else{
a = x - x2;
m = x2;
}
if(y2 - y > 0){
b = y2 - y;
n = y;
}
else{
b = y - y2;
n = y2;
}
juxing ju = new juxing();
ju.setjuxing(m,n,a,b);
ju.setstate(4);
ju.setcolor(cl.getstate());
vector.add(ju);
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
x1 = x2;
y1 = y2;
x2 = e.getX();
y2 = e.getY();
switch(state ){
case 1 :
repaint();
break;
case 2 :
quxian1.add(x2,y2);
repaint();
break;
case 3 :
m1 = m2; n1 = n2;
if(x2 > x){
m2 = x;
}
else{
m2 = x2;
}
if(y2 > y){
n2 = y;
}
else{
n2 = y2;
}
a = (int)Math.sqrt((x1 - x)*(x1 - x) + (y1 - y)*(y1 - y));
b = (int)Math.sqrt((x2 - x)*(x2 - x) + (y2 - y)*(y2 - y));
repaint();
break;
case 4 :
m1 = m2; n1 = n2;
if(x2 > x){
m2 = x;
}
else{
m2 = x2;
}
if(y2 > y){
n2 = y;
}
else{
n2 = y2;
}
repaint();
}
}
public void mouseMoved(MouseEvent e) {
}
public void paint(Graphics g){
if(state == 0){
Draw(g);
}
if(state == 1){
if(pressed){
Draw(g);
pressed = false;
}
else{
g.setColor(color1);
g.drawLine(x,y,x1,y1);
Draw(g);
g.setColor(cl.getstate());
g.drawLine(x,y,x2,y2);
}
}
if(state == 2){
if(pressed){
Draw(g);
pressed = false;
}
else{
g.setColor(cl.getstate());
g.drawLine(x1,y1,x2,y2);
}
}
if(state == 3){
if(pressed ){
Draw(g);
pressed = false;
}
else{
g.setColor(color1);
g.drawOval(m1,n1,a,a);
Draw(g);
g.setColor(cl.getstate());
g.drawOval(m2,n2,b,b);
}
}
if(state == 4){
if(pressed){
Draw(g);
pressed = false;
}
else{
g.setColor(color1);
g.drawRect(m1, n1, Math.abs(x1 - x), Math.abs(y1 - y));
Draw(g);
g.setColor(cl.getstate());
g.drawRect(m2, n2, Math.abs(x2 - x), Math.abs(y2 - y));
}
}
if(state == 5){
if(pressed){
Draw(g);
pressed = false;
}
else{
Draw(g);
g.setColor(cl.getstate());
g.drawString(sr,x,y);
}
}
}
private void Draw(Graphics h){
shape shape2;
zhixian line1;yuan cir;juxing xing;quxian qu;
h.setColor(Color.RED);
for(int i = 0; i < vector.size(); i++){
shape2 = (shape)vector.get(i);
switch(shape2.state){
case 1 :
line1 = (zhixian)shape2;
h.setColor(line1.getcolor());
h.drawLine(line1.getdot().getx(),line1.getdot().getY(),line1.getdot1().getx(),line1.getdot1().getY());
break;
case 2 :
qu = (quxian)shape2;
h.setColor(qu.getcolor());
point point3,point2;
point2 = qu.getdot();
for(int j = 1; j < qu.getVector().size(); j++){
point3 = point2;
point2 = (point)qu.getVector().get(j);
h.drawLine(point2.getx(),point2.getY(),point3.getx(),point3.getY());
}
break;
case 3 :
cir = (yuan)shape2;
h.setColor(cir.getcolor());
h.drawOval(cir.getdot().getx(),cir.getdot().get
没有合适的资源?快使用搜索试试~ 我知道了~
huaban.rar_java huaban
共61个文件
gif:23个
class:13个
java:13个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 117 浏览量
2022-09-19
14:40:15
上传
评论
收藏 49KB RAR 举报
温馨提示
采用基础Java语言实现的一个类似于Windows中的画图程序。
资源推荐
资源详情
资源评论
收起资源包目录
huaban.rar (61个子文件)
huaban
zifu.GIF 898B
1.13.GIF 837B
1.7.GIF 833B
1.9.GIF 825B
1.3.GIF 833B
2.2.GIF 833B
1.5.GIF 825B
juxing1.GIF 898B
1.4.GIF 826B
1.10.GIF 834B
test
build.xml 3KB
1.8.GIF 840B
wenjian2.dat 651B
manifest.mf 85B
src
huaban
Drawpanel.java 1KB
quxian.java 723B
character.java 579B
gongju.java 2KB
point.java 621B
Traigel.java 898B
menubar.java 4KB
juxing.java 615B
color.java 4KB
shape.java 929B
yuan.java 559B
ShapePanel.java 8KB
zhixian.java 699B
wenjian.dat 631B
1.12.GIF 847B
2.1.GIF 833B
1.6.GIF 826B
1.2.GIF 826B
zhixian1.GIF 881B
nbproject
build-impl.xml 26KB
private
private.xml 211B
private.properties 157B
project.xml 576B
genfiles.properties 626B
project.properties 2KB
sanjiaoxing1.GIF 905B
Thumbs.db 26KB
tuoyuan.GIF 906B
duobianxing1.GIF 901B
1.11.GIF 826B
1.1.GIF 818B
wuhao.dat 5KB
1.14.GIF 850B
build
classes
huaban
color.class 3KB
shape.class 1KB
quxian.class 913B
yuan.class 690B
point.class 711B
Traigel.class 1016B
menubar.class 4KB
juxing.class 739B
zhixian.class 831B
Drawpanel.class 1KB
ShapePanel.class 6KB
gongju.class 2KB
character.class 757B
quxian1.gif 887B
共 61 条
- 1
资源评论
钱亚锋
- 粉丝: 90
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功