1、第十章第十章JavaAppletJavaApplet基本概念HTML标记文字的字体颜色与大小绘图动画加载声音与图像1第十章第十章JavaAppletJavaAppletJAVA程序分为ApplicationAppletApplet不能单独运行,必须嵌入到浏览器中所以除写好Applet程序后,还必须建立一个Html文件在标记
2、ava.applet.*;Importjava.AWT.*publicclassExam10_1extendsApplet{publicvoidpaint(Graphicsg){g.drawString("Helloworld",130,100);}}
3第十章第十章JavaAppletJavaApplet4第3、十章第十章JavaAppletJavaAppletAppletinit()start()stop()destyoy()paint()repaint()update()5第十章第十章JavaAppletJavaAppletimportjava.applet.*;importjava.awt.*;publicclassExam10_2extendsApplet{StringBufferbuffer=newStringBuffer();publicvoidinit(){disp("初始化...");}publicvoi
4、dstart(){disp("开始...");}publicvoidstop(){disp("停止...");}publicvoiddestroy(){disp("清除...");}voiddisp(Stringstr){System.out.println(str);buffer.append(str);repaint();}publicvoidpaint(Graphicsg){g.drawString(buffer.toString(),130,100);}}6第十章第十章JavaAppletJavaAppl
5、et字符串,字符和字节输出g.drawString(Stringstr,intx,inty)g.drawChars(charch[],intoffset,intnum,intx,inty)g.drawBytes(byteby[],intoffset,intnum,intx,inty)7第十章第十章JavaAppletJavaAppletimportjava.applet.*;importjava.awt.*;publicclassExam10_3extendsApplet{Stringstr="displayst
6、ring(显示字符串)";charch[]={'显','示','S','t','r','i','n','g'};byteby[]={97,'','B','Y','T','E'};publicvoidpaint(Graphicsg){g.drawString(str,80,80);g.drawChars(ch,0,8,110,120);g.drawBytes(by,0,6,120,160);}}8第十章第十章JavaAppletJavaApplet改变文字的字体,颜色与大小创建Font对象Font的构造函数有三个参
7、数StringfontNameintstyleBOLDITALICPLAINintsizeg.setFont(Fontf);getFamily()getName()getSize()9第十章第十章JavaAppletJavaAppletimportjava.applet.*;importjava.awt.*;publicclassExam10_4extendsApplet{Fontf1=newFont("华文新魏",Font.BOLD,24);Fontf2=newFont("宋体",Font.ITALIC,24)
8、;Fontf3=newFont("华文隶书",Font.PLAIN,24);Stringstr="displaystring(显示字符串)";charch[]={'显','示','S','t','r','i','n','g'};byteby[]={97,'','B','Y','T','E'};publicvoidpaint(Graphicsg){g.setFont(f1)