爱心技术专栏专题

rtingbetweenappletsandapplications

摘录:java基础 来源:java基础 加入时间:2006年08月19日
摘要:
rtingbetweenappletsandapplications
rting between applets and applications
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 e…

转载:转载请保留本信息,本文来自
http://www.51dibs.com
/html/2006/article/info16/a_14110a2329e073a0.htm

rtingbetweenappletsandapplications

站点:爱心种子小博士 关键字:rtingbetweenapplet

   
rting between applets and applications
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. 

客户服务中心信箱:[email protected] [email protected] 网站地图

声明

合作伙伴: