《Java游戏开发》1.ppt

  1. 1、本文档共106页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
《Java游戏开发》1

添加一个颜色选择窗口 (1)创建一个createSidebar方法来生成含颜色选项下拉框和一个清除applet窗体的按钮的辅助窗口。 private void createSidebar() { // 对于颜色数组中的每一个 ColorDescription , // 提取其文本 // 并将它加入选项列表 … // 创建 clear window 按钮 … // 创建 frame … } 添加一个颜色选择窗口 (2)实现ItemListener接口, 对颜色选项下拉框的颜色选取进行事件处理 public void itemStateChanged(ItemEvent e) { … } (3)实现ActionListemer接口,对清除applet窗体的按钮进行事件响应 public void actionPerformed(ActionEvent e) { … } paint()方法 在Java中的awt包里,Component类(构件类)中定义了一个方法: paint(Graphics g){ } (1)参数g是一个图形类(Graphics)对象,它由系统自动生成,不需要用户程序来实例化。 (2)由参数g来调用Graphics类中的图形处理方法 (3)paint()方法是自动调用的,当构件首次显示或显示需要更新时调用。 (4)如果调用repaint()方法,将导致update()方法的自动调用,update()的调用将首先用背景色清除画面,然后调用paint()方法 Graphics类输出图形 在paint()方法中由g来调用: 1.直线的输出: public void paint(Graphics g) { g.drawLine(50,60,100,120); g.drawLine(30,50,30,50); } 矩形的输出 1 无填充的矩形: drawRect(int x, int y, int width, int height) //x,y为矩形左上角坐标,width,height为矩形的宽和高 2有填充的矩形 fillRect(int x, int y, int width, int height) 3无填充的圆角矩形 drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) //arcWidth,arcHeight为圆角弧的横向和纵向直径 4有填充的圆角矩形 fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)draw3DRect(int x, int y, int width, int height, boolean raised) //raised:true/false 5 有凸出/凹下的三D矩形 fill3DRect(int x, int y, int width, int height, boolean raised) 画出的六种矩形 椭圆的输出 1 无填充的椭圆 drawOval(int x, int y, int width, int height) 2 无填充的椭圆 fillOval(int x, int y, int width, int height) //如果width和height的值相等,将画出圆形 3画弧 drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) //startAngle,弧开始位置的角度 //arcAngle,弧转过的角度:逆时钟方向转为正,顺时钟方向转为负 画扇形 fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) 示例:public void paint(Graphics g) { g.setColor(Color.blue); g.drawOval(20,20,60,60); g.fillOval(100,20,80,60); g.drawArc(

文档评论(0)

feixiang2017 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档