资源描述:
《面向对象的程序设计(java)做简易图画板》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、北京理工大学珠海学院2014〜2015学年第一学期《面向对象的程序设计(Java)》大作业诚信声明专业:考场是严肃的,作弊是可耻的,对作弊人的处分是严历的。班级:我承诺遵守考场纪律,不存在抄袭及其它违纪行为。考生(承诺人)签字:学号:适用年级专业:2013级信息管理与信息系统专业试卷说明:大作业大作业题目一、摘要:本程序通过JAVA的ActionListener,MouseMotionListener,MouseListener,ItemListener等基本类进行了简革的界面设计,运用了JAVA巾类的继承特性实现了对父类方法的调用,并多次使用CASE语句
2、实现绘图菜单的选择,运用了适配器类简化了监听器类的重写工作。二、关键字:ActionListener,MouseMotionListener,MouseListener,ItemListener三、源代码:importjava,applet.importjava.awt.importjava.awt.event.*;importjava,util•氺;importjavax.swing.*;importjava.awt>geom.*;importjava.io.classPointimplementsSerializable{intx,y;Colorcol
3、;inttool;intboarder;Point(intx,inty,Colorcol,inttool,intboarder){this,x=x;this,y=y;this,col=col;this,tool=tool;this,boarder=boarder;}}classpaintboardextendsFrameimplementsActionListener,MouseMotionListener,MouseListener,IteraListener{intx=-1,y=-1;intcon=1;//画笔大小intEcon=5;//橡皮大小int
4、toolFlag=0;//toolFlag:工具标记"toolFlag工具对应表://(0-画笔);(1--橡皮);(2-清除);//(3—直线);(4—圆);(5—矩形);Colorc=newColor(0,0,0);//画笔颜色BasicStrokesize=newBasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);//画笔粗细Pointcutflag=newPoint(-1,-1,c,6,con);//截断标志Vectorpaintlnfo=null;//点信息向量组intn=1;
5、FilelnputStreampicln=null;FileOutputStreampicOut=null;ObjectInputStreamVIn=null;ObjectOutputStreamVOut=null;//*工具面板一画笔,直线,矩形,多边形,橡皮,清除*/PaneltoolPanel;Buttoneraser,drLine,drCircle,drRect;Buttonclear,pen;ChoiceColChoice,SizeChoice,EraserChoice;Buttoncolchooser;Label颜色,大小B,大小E;//保存功
6、能ButtonopenPic,savePic;FileDialogopenPicture,savePicture;paintboard(Strings){super(s);addMouseMotionListener(this);addMouseListener(this);paintlnfo=newVector();/*各工具按钮及选择项*///颜色选择ColChoice=newChoice();ColChoice.add(〃black〃);ColChoice.add(〃red〃);ColChoice.add(〃blue〃);ColChoice.add(
7、〃green〃);ColChoice.addltemListener(this);//画笔大小选择SizeChoice=newChoice();SizeChoice.add(〃l〃);SizeChoice.add(〃3〃);SizeChoice.add(〃5〃);SizeChoice.add(〃7〃);SizeChoice.add(〃9〃);SizeChoice.addltemListener(this);//橡皮大小选择EraserChoice=newChoice();EraserChoice.add(〃5〃);EraserChoice.add(〃9〃)
8、;EraserChoice.add(〃13〃);EraserCho