RBL JAVA Tips
Main page
Home
[ Search | Home Page | Index Java tips ]


PrevRetour IndexNext
  • How to change an applet to an application. I use in this sample "read Image" applet and application (tipsImg2 et tipsImg3).

  • tipsImg2.java : Applet source...
  • tipsImg3.java : Application source...

  • Changes...
    • import
        // Event pour la gestion des Evenements et principalement le message EXIT   
        import java.awt.Event ;
        // Toolkit pour le chargement des images   
        import java.awt.Toolkit ;
    • declare
        public class tipsImg3 extends java.applet.Applet {
        // devient 
        public class tipsImg3 extends java.awt.Frame {
      
    • add main function
        public static void main(String args[]) {
        // Event pour la gestion des Evenements et principalement le message EXIT   
              // create frame
      	tipsImg3 tq = new tipsImg3();
              // Init
      	tq.init();
              // Force size
      	tq.resize(100,100);
              // Display
      	tq.repaint();
      	tq.show();
        }
    • add events gestionmain
        public boolean handleEvent(Event evt) {
              // Traitement de l'evenement de fin de programme
               if ( evt.id == evt.WINDOW_DESTROY ) {
                    System.exit(0) ;
                    return true ;
               }
               return false ;
        }
    • others changes
        // Read image
               // Read image
                img =  getImage(getCodeBase(), "./photo.gif") ;
        // Change  
               // Get default Toolkit
                Toolkit toolkit = Toolkit.getDefaultToolkit()  ;
                img =  toolkit.getImage("./photo.gif") ;
      
      





Copyright © 1996..2003, BERTHOU. All right reserved.
Last change : 05 March 2003 18H20