Partage
  • Partager sur Facebook
  • Partager sur Twitter

Applet Java

Avec DJNativeSwing-SWT-1-0-1

    5 avril 2011 à 11:05:57

    Bonjour tout le monde,
    Je souhaite réaliser une Applet Java qui ne soit au final qu'un simple navigateur internet (par l'intermédiaire de bibliothèque(s)). Un navigateur dans un navigateur ? Oui je vous l'accorde c'est pas commun mais c'est pour un cas d'utilisation assez spécifique.

    Je me suis donc mis à la tâche. Au final j'ai deux version différentes qui marche toutes les deux sous Eclipse, mais quand je veux l'afficher sur le navigateur, pas moyen. Pour ce que ca intéresse donc, je mets les source de la version la plus susceptible de fonctionner ci dessous :

    La principale
    import chrriis.common.UIUtils;
    import chrriis.dj.nativeswing.swtimpl.NativeInterface;
    import chrriis.dj.nativeswing.swtimpl.NativeInterfaceAppletHandler;
    import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    
    public class SimpleWebBrowserExemple extends JApplet {
    	static {
    		// This is a mandatory call to activate applet support.
    		NativeInterfaceAppletHandler.activateAppletMode();
    		// For this applet, I decided to force the look and feel to the
    		// preferred one.
    		UIUtils.setPreferredLookAndFeel();
    	}
    
    	@Override
    	public void init() {
    		// This is a mandatory call to activate applet support.
    		NativeInterfaceAppletHandler.init(this);
    		// Rest of your init().
    	}
    
    	@Override
    	public void start() {
    		// This is a mandatory call to activate applet support.
    		NativeInterfaceAppletHandler.start(this);
    		// Rest of your start().
    		// For this applet, I decided to open the interface in the start method.
    		NativeInterface.open();
    		// For this applet, I decided to add all content.
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				CreateWebBrowser monWebBrowser = new CreateWebBrowser();
    				getContentPane().add(monWebBrowser, BorderLayout.CENTER);
    			}
    		});
    	}
    
    	@Override
    	public void stop() {
    		// This is a mandatory call to activate applet support.
    		NativeInterfaceAppletHandler.stop(this);
    		// Rest of your stop().
    		// For this applet, I decided to remove all content.
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Container contentPane = getContentPane();
    				contentPane.removeAll();
    				contentPane.invalidate();
    				contentPane.validate();
    			}
    		});
    		// For this applet, I decided to close the interface here.
    		NativeInterface.close();
    	}
    
    	@Override
    	public void destroy() {
    		// This is a mandatory call to activate applet support.
    		NativeInterfaceAppletHandler.destroy(this);
    		// Rest of your destroy().
    	}
    
    }
    


    Classe pour créer le WebBrowser
    import java.awt.BorderLayout;
    
    import javax.swing.BorderFactory;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    
    import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
    
    public class CreateWebBrowser extends JApplet {
    	public CreateWebBrowser() {
    		JPanel webBrowserPanel = new JPanel(new BorderLayout());
    		webBrowserPanel.setBorder(BorderFactory
    				.createTitledBorder("Native Web Browser component"));
    		final JWebBrowser webBrowser = new JWebBrowser();
    		webBrowser.navigate("http://www.google.com");
    		webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
    		add(webBrowserPanel, BorderLayout.CENTER);
    		webBrowser.setMenuBarVisible(false);
    
    	}
    
    }
    


    Le fichier Html test (dans le répertoire du projet Eclipse)
    Surfway
    
    <applet name="SimpleWebBrowserExemple" codebase="bin/" code="SimpleWebBrowserExemple.class" archive="DJNativeSwing.jar,DJNativeSwing-SWT.jar,swt-3.7M5-win32-win32-x86.jar"
            height="300px" width="300px">
    </applet>
    


    Erreur Console Java
    java.lang.RuntimeException: java.lang.NoClassDefFoundError: chrriis/dj/nativeswing/swtimpl/NativeInterfaceAppletHandler
            at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
            at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: chrriis/dj/nativeswing/swtimpl/NativeInterfaceAppletHandler
            at SimpleWebBrowserExemple.<clinit>(SimpleWebBrowserExemple.java:17)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.Class.newInstance0(Unknown Source)
            at java.lang.Class.newInstance(Unknown Source)
            at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
            at java.awt.event.InvocationEvent.dispatch(Unknown Source)
            at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
            at java.awt.EventQueue.access$000(Unknown Source)
            at java.awt.EventQueue$1.run(Unknown Source)
            at java.awt.EventQueue$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
            at java.awt.EventQueue.dispatchEvent(Unknown Source)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: chrriis.dj.nativeswing.swtimpl.NativeInterfaceAppletHandler
            at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
            at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
            at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
            at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 22 more
    Exception : java.lang.RuntimeException: java.lang.NoClassDefFoundError: chrriis/dj/nativeswing/swtimpl/NativeInterfaceAppletHandler




    Dans Eclipse, concernant l'import (fichiers présents dans la librairie ci-dessous) :
    DJNativeSwing.jar
    DJNativeSwing-SWT.jar
    swt-3.7M5-win32-win32-x86.jar

    Librairie DJNativeSwing-SWT-1-0-1.zip : http://sourceforge.net/projects/djproject/files/DJ Native Swing/


    En espérant avoir été le plus claire possible, je reste à l'affut de toute réponse, et si vous avez des questions n'hésitez pas !

    Merci de m'avoir lu !
    • Partager sur Facebook
    • Partager sur Twitter

    Applet Java

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown