Converting between applets and applications

80酷酷网    80kuku.com

  applicationConverting 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. 



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: