当前位置导航:炫浪网>>网络学院>>网页制作>>JSP教程

Converting 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. 
相关内容
赞助商链接