




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、西安邮电大学(计算机学院)java程序设计课内实豔报告实验名称专业名称:软件工程班 级:1201学生姓名:学号(8位指导教师:实验日期:2014年5月26 口一实验目的及实验环境理解applet生命周期模型及运行原理,掌握applet设计方法,能结合以 前知识,综合应用,实现实用价值的小应用程序。二.实验内容1. 运行jdkdemo中的示例程序,加强对applet的理解。2. 设计一个applet,完成将小写数字货币转换成大写形式。如输入189.56, 输岀文本框显示:壹佰捌拾玖元伍角陆分。3. 设计一个applet,完成数字时钟功能。三.方案设计使用box类布局小应用程序第一题 public
2、 void init() string blinkfrequency = getparameter('1 speed"); delay = (blinkfrequency = null) ? 400:(1000 / integer.parselnt(blinkfrequency); labelstring = getparameter(n 1 b 1");if (labelstring = null) labelstring = ” blink”;font font = new java.awt.font(nseriffont.plain, 24); setfont
3、(font);第二题 public void actionperformed(actionevent e) try string str = jtfd.gettext();double money= double.parsedouble(str); jtfu.settext(tormb(money); catch (exception ex) joptionpane.showmessagedialog(null, ex);第三题 public void run() thread me = thread.currentthread();while (timer = me) try thread.
4、sleep(loo); catch (interruptedexception e) repaintq;1. 正常测试数据(3组)及运行结果;水圄小应用程序查看器:blink忑=|回iw小应用程序blink已启动小应用程序。小写189.56犬写壹佰捌拾玖元伍角陆分change已启动小应用程序。圄 小应用理序奁看器:cloclcds i回iqmt 小应用程序星期三五月28 13:24:22 2014已启动小应用程序。五.总结1. 实验过程中遇到的问题及解决办法;在使用box吋不熟悉它的方法,不知道该如何使用2. 对设计及调试过程的心得体会。对applet的编程不熟悉,该多看看书,查查api六.附
5、录:源代码(电子版)import java.awt.color;import java.awt.dimension;import java.awt.font;import java.awt.fontmetrics;import java.awt.graphics;import java.util.stringtokenizer;import java.util.timer;import java.util.timertask;public class blink extends java.applet.applet private static final long serialversion
6、uid = -775844794477507646l; private timer timer;private string labelstring;private int delay;public void init() string blinkfrequency = getparameter(11 speedn;delay = (blinkfrequency = null) ? 400:(1000/ integerparselnt(blinkfequency);labelstring = getparameter(ulbr,);if (labelstring = null) labelst
7、ring = “blink”;font font = new java.awt.font(nseriffont.plain, 24); setfont(font);public void start() timer = new timer();time匚schedule(new timertask() public void run() repaint();, delay, delay);public void paint(graphics g) int fontsize = g.getfont().getsize();int x = 0, y = fontsize, space;int re
8、d = (int) (50 * math.random();int green = (int) (50 * math.random();int blue = (int) (256 * math.random(); dimension d = getsize();g.setcolor(color.black);fontmetrics fm = g.getfontmetrics();space = fmtringwidthc1 ");for (stringtokenizer t = new stringtokenizer(labelstring);t.hasmoretokens();)
9、string word = t.nexttoken();int w = fm.stringwidth(word) + space;讦(x + w > d.width) x = 0;y += fontsize;if (math.random() < 0.5) g.setcolor(new java.awt.color(red + y * 30) % 256, (green + x / 3) % 256, blue); else g.setcolor(getbackground();g.drawstring(word, x, y);x += w;public void stop() t
10、ime 匚 cancel。;public string getappletinfo() return "title: blinkernm+ ''author: arthur van hoffnn+ "displays multicolored blinking text."public string getparameterinfo() string pinfo = "speed", "string", "the blink frequency"), ”string”,”the text
11、to blink.“ , ;return pinfo;2.import java.awt.container;import j ava.awt.event.actionevent;import java.awt.event.actionlistener;import javax.swing.box;import javax.swing.japplet;import javax.swing-jbutton;import javax.swing.jlabel;import javax.swing. joptionpane;import javax.swing. jtextfield;public
12、class changermb extends j applet implements actionlistener private jtextfield jtfd;private jtextfield jtfu;private jbutton jbtn = new jbutton(hchangeh);public void init()container con = this.getcontentpane();jtfd = new jtextfield();jtfu = new jtextfield();jbtn = new jbutton(nchangeh);box bl = box.cr
13、eatehorizontalbox();b 1 .add(box.createhorizontalstrut( 10);bl.add(new jlabel("小写");bl.add(jtfd);b 1 .add(box.createhorizontalstrut( 10);box b2 = box.createhorizontalbox();b2.add(box.createhorizontalstrut(10);b2.add(new jlabel("大写");b2.add(jtfu); b2.add(box.createhorizontalstrut(
14、l 0);box b3 = box.createhorizontalbox();b3.add(box.createhorizontalstrut(10);b3.add(jbtn);box b = box.createverticalbox();b.add(box.createverticalstrut(30);b.add(bl);b.add(box.createverticalstrut(30);b.add(b2);b.add(boxxreateverticalstrut(30);b.add(b3); con.add(b);jbtn.addactionlistener(this);public
15、 void actionperformed(actionevent e) try string str = jtld.gettext();double money= double.parsedouble(str); jtfu.settext(tormb(money); catch (exception ex) joptionpane.showmessagedialog(null ex);(©=,zw)=vqoeidan3s0 h 二 nsai (w=x$g».)=vu。皂dm 二 ns 七 h 二 nsu (».x腿脚.)=vumdan3sal n 二 nsu (
16、t3丈脚.mvqomde 邑 nsai h 13总hns 七 + r二寸 s + 三 +c=s n 二 ns® o at 7 ()qw)u3i:s)lvewhs n c 三一 二+o£m虽hsv 二o h 二w)oj r n 二 nsai hues "(3000.0 + 00- *&uoe)puno£ew)jounnaohubs nbs sues二匕efah莖.b efak雨f efah殳禎«茶n寸s二elp二 m.囊 m.r.rs审»顾fe «廉n is)(aquolu 2qnop)cqstolonu 匸-s 21
17、3s。二 qndvwoot 三n.eaa匸 odlu- qleqsneaertiodul 一heuuod3eq2duqslx0eae匸 0dl= "s2qdejdaedae二 oduq muo4>-e0£t:oduq uoooqaureaatioduj 一 xqiddv.loiddedaertiodul 一hnsal am-alr.«,u«mvqo£dp 三 nsp h 二 nsy r阻.=slk)=vgo£dan3s0 h 二 nspnscdjp:a'»is口 2r)=v20p一 dal.二 nsai n _
18、1kw=)=vq0£danwsp nw ww)=vuoeidan3sp n 氏帥.)=veidm=nsai n w 脚帥=)=<裟且 danssal n - 2y)=vuozdan-nsal h - ww=)=vqondarunsai h ow)=vq0eidan3sp h 一 «w.)=vuoeidan3sai h - lk)=vuoqdan3sa! n w 口鮒.-)=vgw_dan_nsaih -nsai nsoj nsp nscdj nsuj nsai nsoj nsp nsuj nsuj nsupublic class clock extends apple
19、t implements runnable private volatile thread timer;private int lastxs, lastys, lastxm,lastym, lastxh, lastyh;private simpledateformat formatter;private string lastdate;private font clockfacefont;private date currentdate;private color handcolor;private color numbercolor;private int xcenter = 80, yce
20、nter = 55;public void inii() lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;formatter = new simpledateformat(heee mmm dd hh:mm:ss yyyyh, locale.getdefault();currentdate = new date();lastdate = formatter.format(currentdate);clockfacefont = new font("serif', font.plain, 14); handcolo
21、r = color, blue;numbercolor = color.darkgray;16); catch (nullpointerexception e) catch (numberformatexception e) try handcolor = new color(intege匚parseirh(ge(parameter(”fgcoloitj,16);)catch (nullpointerexception e) catch (numberformatexception e) try numbercolor = new color(integer.parseint(getparam
22、eter(hfgcolor2n),16); catch (nullpointerexception e) catch (numberformatexception e) resize(200, 200);public void update(graphics g) int xh, yh, xm, ym, xs, ys;int s = 0, m = 10, h 二 10;string today;currentdate = new date();formatte 匚 applypattem( hsh);try s = intege r.parseint(formamer.fonnat(curre
23、ntdate);)catch (numberformatexception n) s = 0;formatter.applypattern(hm");try m = intege r*.parscini(foirnahe 匚 foirnat(currcn(date); catch (numberformatexception n) m = 10;)formatte i*.applypattem(”h”);try h = intege 匚 parseint(formatter.f(mmat(currentdate); catch (numberformatexception n) h
24、= 10;xs = (int) (math.cos(s * math.pi / 30 math.pi / 2) * 45 + xcenter); ys = (int) (math.sin(s * math.pi / 30 - math.pi / 2) * 45 + ycenter); xm = (int) (math.cos(m * math.pi / 30 math.pi / 2) * 40 + xcenter); ym = (int) (math.sin(m * math.pi / 30 math.pi / 2) * 40 + ycenter); xh = (int) (math.cos(
25、h * 30 + m / 2) * math.pi /180- math.pi / 2) *30+ xcenter);yh = (int) (math.sin(h * 30 + m / 2) * math.pi / 180 - math.pi / 2) *30+ ycenter);formatter.applypattern("eee mmm dd hh:mm:ss yyyym); today = formatte 匚 foutiamcuitentdate);g.setfont(clockfacefont);g.setcolor(getbackground();if (xs != lastxs | ys != lastys) g.drawline(xcenter, ycenter, lastxs, lastys); g.drawstring(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 长江师范学院《管理技能与创新实践》2023-2024学年第二学期期末试卷
- 桂林旅游学院《微机原理与接口技术(3)》2023-2024学年第二学期期末试卷
- 苏州城市学院《书法(一)》2023-2024学年第二学期期末试卷
- 东华理工大学《汽车发展史》2023-2024学年第二学期期末试卷
- 2025届四川省新高考教研联盟高三上学期八省适应性联考模拟演练考试(二)历史试卷
- 合肥城市学院《建筑施工安全》2023-2024学年第二学期期末试卷
- 2024-2025学年上海市松江区高三上学期期末质量监控考试历史试卷
- 长春大学旅游学院《高分子材料改性原理及技术》2023-2024学年第二学期期末试卷
- 林州建筑职业技术学院《化工制图与AutoCAD》2023-2024学年第二学期期末试卷
- 华东交通大学《中国现当代文学二》2023-2024学年第二学期期末试卷
- 学校提高《规范书写水平、传承汉字文化》活动方案3篇
- 幕墙施工现场安全检查方案
- 2023年4月2日湖北事业单位联考C类《职业能力倾向测验》试题
- 新课标背景下“教学评一体化”评的策略
- 儿童儿童矮身材临床诊治矮身材临床诊治
- 早产儿护理查房课件图
- 2.3.1直线与平面垂直的判定(公开课)省公开课获奖课件说课比赛一等奖课件
- 03S702钢筋混凝土化粪池-标准图集
- Unit 2 Bridging Cultures Reading for writing 课件-高中英语(2019)选择性必修第二册
- 滴定管的使用
- 砌筑工理论试题库
评论
0/150
提交评论