简单画图程序设计文档格式.docx

上传人:b****1 文档编号:5121333 上传时间:2023-05-04 格式:DOCX 页数:57 大小:39.01KB
下载 相关 举报
简单画图程序设计文档格式.docx_第1页
第1页 / 共57页
简单画图程序设计文档格式.docx_第2页
第2页 / 共57页
简单画图程序设计文档格式.docx_第3页
第3页 / 共57页
简单画图程序设计文档格式.docx_第4页
第4页 / 共57页
简单画图程序设计文档格式.docx_第5页
第5页 / 共57页
简单画图程序设计文档格式.docx_第6页
第6页 / 共57页
简单画图程序设计文档格式.docx_第7页
第7页 / 共57页
简单画图程序设计文档格式.docx_第8页
第8页 / 共57页
简单画图程序设计文档格式.docx_第9页
第9页 / 共57页
简单画图程序设计文档格式.docx_第10页
第10页 / 共57页
简单画图程序设计文档格式.docx_第11页
第11页 / 共57页
简单画图程序设计文档格式.docx_第12页
第12页 / 共57页
简单画图程序设计文档格式.docx_第13页
第13页 / 共57页
简单画图程序设计文档格式.docx_第14页
第14页 / 共57页
简单画图程序设计文档格式.docx_第15页
第15页 / 共57页
简单画图程序设计文档格式.docx_第16页
第16页 / 共57页
简单画图程序设计文档格式.docx_第17页
第17页 / 共57页
简单画图程序设计文档格式.docx_第18页
第18页 / 共57页
简单画图程序设计文档格式.docx_第19页
第19页 / 共57页
简单画图程序设计文档格式.docx_第20页
第20页 / 共57页
亲,该文档总共57页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

简单画图程序设计文档格式.docx

《简单画图程序设计文档格式.docx》由会员分享,可在线阅读,更多相关《简单画图程序设计文档格式.docx(57页珍藏版)》请在冰点文库上搜索。

简单画图程序设计文档格式.docx

健身 

食疗 

治病 

中医 

减肥 

经穴 

亚健康

生活·

情感 

哲理 

家居 

母婴 

美食 

美容 

百宝箱

文教·

社会 

读书 

人文 

历史 

教育 

职场 

电脑

简单的画图程序(转载)

jhl666666收录于2011-01-16阅读数:

查看

收藏数:

公众公开 

原文来源 

tags:

java图像编程

修改 

以文找文 

推荐给好友

如何对文章标记,添加批注?

一共有10个类,其中GBase和HBase分别是图元的基类和操作基类,比较重要的类是GraphicList和PointerHandler,这个是图形操作主要类,DefaultGraphic是矩形,Line是线,目前只做了这么两个图形,对应还有操作类(句柄),DrawPanel是画布,没什么重要的,只是分配了操作图元的句柄而以,好了,废话少说,看代码:

DrawPanel.java

=================================================================

packagedrawing;

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.JFrame;

importdrawing.Handler.*;

importjavax.swing.JPanel;

/**

*<

p>

Title:

<

/p>

*

Description:

Copyright:

Copyright(c)2005<

Company:

*@authornotattributable

*@version1.0

*/

publicclassDrawPanelextendsJPanelimplementsMouseListener,

MouseMotionListener{

publicGraphicsListgraphicsList;

publicintActiveTool;

publicCursorCursor;

HBase[]tools=newHBase[(int)HandlerType.NumberOfDrawTools];

publicDrawPanel(){

graphicsList=newGraphicsList();

tools=newHBase[(int)HandlerType.NumberOfDrawTools];

tools[(int)HandlerType.Pointer]=newPointerHandler();

tools[(int)HandlerType.DefaultGraphics]=newHBase();

tools[HandlerType.Line]=newLineHandler();

setDoubleBuffered(true);

addMouseListener(this);

addMouseMotionListener(this);

ActiveTool=HandlerType.Pointer;

setBackground(Color.white);

}

/*由mousePressed(),mouseReleased()取得示拖曳的开始与结束坐标*/

publicvoidmousePressed(MouseEvente){

if(e.getButton()==e.BUTTON1)

tools[(int)ActiveTool].OnMouseDown(this,e);

publicvoidmouseReleased(MouseEvente){

tools[(int)ActiveTool].OnMouseUp(this,e);

publicvoidmouseEntered(MouseEvente){}

publicvoidmouseExited(MouseEvente){}

publicvoidmouseClicked(MouseEvente){

if(e.getClickCount()==2){

if(e.getButton()==e.BUTTON1){

ActiveTool=HandlerType.DefaultGraphics;

}else{

ActiveTool=HandlerType.Line;

/*mouseMoved(),mouseDragged()取得鼠标移动的每一个坐标,并调用repaint()方法*/

publicvoidmouseMoved(MouseEvente){

tools[(int)ActiveTool].OnMouseMove(this,e);

repaint();

publicvoidmouseDragged(MouseEvente){

tools[(int)ActiveTool].OnMouseDrag(this,e);

publicvoidupdate(Graphicsg){

g.setColor(Color.white);

g.fillRect(0,0,getWidth(),getHeight());

paint(g);

publicvoidpaint(Graphicsg){

if(graphicsList!

=null){

graphicsList.Draw(g);

DrawNetSelection(g);

/**

*DrawNetSelection

*

*@paramgGraphics

*/

privatevoidDrawNetSelection(Graphicsg){

g.setColor(Color.BLACK);

if(NetRectangle!

=null&

&

DrawNetRectangle)

g.drawRect(NetRectangle.x,NetRectangle.y,NetRectangle.width,

NetRectangle.height);

*setDrawNetRectangle

*@parambboolean

booleanDrawNetRectangle=false;

publicvoidsetDrawNetRectangle(booleanb){

DrawNetRectangle=b;

publicbooleanIsDrawNetRectangle(){

returnDrawNetRectangle;

*setNetRectangle

*@paramrectangleRectangle

RectangleNetRectangle;

publicvoidsetNetRectangle(Rectanglerectangle){

NetRectangle=rectangle;

publicRectanglegetNetRectangle(){

returnNetRectangle;

publicstaticvoidmain(String[]args){

newDrawTool();

}

===========================================================================

DrawTool.java(显示窗体)

============================================================================

importjava.awt.Toolkit;

importjavax.swing.SwingUtilities;

importjavax.swing.UIManager;

importjava.awt.Dimension;

importjava.awt.BorderLayout;

importjavax.swing.JButton;

publicclassDrawToolextendsJFrame{

JPanelcontentPane;

BorderLayoutborderLayout1=newBorderLayout();

DrawPaneldrawpanel=newDrawPanel();

publicDrawTool(){

try{

setDefaultCloseOperation(EXIT_ON_CLOSE);

jbInit();

}catch(Exceptionexception){

exception.printStackTrace();

*Componentinitialization.

*@throwsjava.lang.Exception

privatevoidjbInit()throwsException{

contentPane=(JPanel)getContentPane();

contentPane.setLayout(borderLayout1);

setSize(newDimension(400,300));

setTitle("

糊涂仙"

);

show();

contentPane.add(drawpanel,java.awt.BorderLayout.CENTER);

=========================================================================

GraphicList.java

==========================================================================

importjava.util.ArrayList;

importjava.awt.Graphics;

importdrawing.Graphics.GBase;

importjava.awt.Point;

importjava.awt.Rectangle;

importdrawing.Graphics.DefaultGraphic;

publicclassGraphicsList{

ArrayListgraphicslist=newArrayList();

publicGraphicsList(){

publicvoidDraw(Graphicsg){

for(inti=0;

i<

graphicslist.size();

i++){

GBaseo=(GBase)graphicslist.get(i);

o.Draw(g);

publicvoidAdd(GBaseo){

graphicslist.add(0,o);

publicvoidRemove(GBaseo){

o.OnDelete();

graphicslist.remove(o);

if(oinstanceofDefaultGraphic){

((DefaultGraphic)o).getJoinLines().size();

if(graphicslist.contains(((DefaultGraphic)o).getJoinLines().

get(i)))

graphicslist.remove(((DefaultGraphic)o).getJoinLines().get(

i));

((DefaultGraphic)o).getSplitLines().size();

if(graphicslist.contains(((DefaultGraphic)o).getSplitLines().

graphicslist.remove(((DefaultGraphic)o).getSplitLines().

get(

publicintsize(){

returngraphicslist.size();

publicvoidClear(){

graphicslist.clear();

publicbooleanContains(GBaseo){

returngraphicslist.contains(o);

publicGBaseget(intindex){

if(index>

=graphicslist.size())

returnnull;

return(GBase)graphicslist.get(index);

///<

summary>

///选中图元的总数

///<

/summary>

publicintgetSelectionCount(){

intn=0;

if(o.IsSelected())

n++;

returnn;

///获取选中的图元

paramname="

index"

>

<

/param>

returns>

/returns>

publicGBaseGetSelectedObject(intindex){

intn=-1;

if(n==index)

returno;

///选中矩形范围内的所有图元

rectangle"

publicvoidSelectInRectangle(Rectanglerectangle){

UnselectAll();

if(o.IntersectsWith(rectangle))

o.setSelected(true);

///取消选中所有图元

publicvoidUnselectAll(){

o.setSelected(false);

///选中所有图元

publicvoidSelectAll(){

///删除选中的图元

publicbooleanDeleteSelection(){

booleanresult=false;

intn=graphicslist.size();

for(inti=n-1;

i>

=0;

i--){

if(((GBase)graphicslist.get(i)).IsSelected()){

Objectoe=graphicslist.get(i);

if(graphicslist.contains(oe)){

((GBase)oe).OnDelete();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2