Converting between applets and applications

Converting between applets and applications
To convert an Application to Applet:
  1. Create an HTML page with an applet tag to invoke the applet.
  2. Delete the main method.
  3. Alter the class header so that it extends Applet rather than Frame.
  4. Add the import for the library class Applet.
  5. Change the name of the constructor method from the name of the class to init.
  6. 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:
  1. 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.
  2. Alter the class header so that it extends Frame rather than Applet.
  3. 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);
}
  1. Delete the import for the class Applet, since it now redundant.
  2. 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.
  3. 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.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值