·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » Converting between applets and applications

Converting between applets and applications

类别: JAVA教程  评论数:0 总得分:0
Converting between applets and applicationsTo convert an Application to Applet: Create an HTML page with an applet tag to invoke the applet. Delete the main method. Alter the class header so that it extends Applet rather than Frame. Add the import for the library class Applet. Change the name of the constructor method from the name of the class to init. Add an invocation of a method to set the layout of widgets in the applet window.This is typically:setLayout(new BorderLayout());To convert a Applet to Application:Change the name of the init method to the name of the class. This is now the constructor method for the class. Delete the word void in the header for this method, since a constructor method has no return type. Alter the class header so that it extends Frame rather than Applet. Create a new method called main, with the header public static void main(String[] args).  This is now the constructor method should create a Frame object as an instance of the class. So, if the class is called MyClass, the main method should be:public static void main(String[] args){    MyClass f = new MyClass();    f.setSize(300, 200);    f.setVisible(true);}Delete the import for the class Applet, since it now redundant.Add a method windowClosing to handle the event which is the user clicking on the close window button. This also involves adding implements WindowListener and this.addWindowListener(this); in order to register the event handler.Add an invocation of a method to set the layout of widgets in the frame.This is typically:setLayout(new FlowLayout());Make sure that the applet does not use any of the methods that are special to the Applet class - methods including getAudioClip, getCodeBase, getDocumentBase, GetImage. 


-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1