Page 1 of 2 12 LastLast
Results 1 to 20 of 30
  1. #1
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default Putting the Applet program on webpage

    Hello...

    I have built an applet program... that runs fine in Eclipse.....

    In the work space of Eclipse, I have a folder on the project name....

    The project folder consists of:

    1- bin folder: That conatins CLASS files of all the classes...
    an applet file "java.policy.applet"
    a folder that conatins images used by the program....

    2- src folder: That contains all the JAVA files of the program.

    3- PROJECT file: named as ".project"
    4- CLASSPATH file: named as ".classpath"


    I want to put this applet on a web page.... any guide lines...????

    Many Thanks for the cooperation...

    Best Regards,
    Sarwar

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    use the applet tag in the html-file, like

    <applet width=200 height=200 code="ClassName.class">

    the easiest way to find your classes is putting the html-file in the same directory of the bins.

  3. #3
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello,

    The project is developed in Eclipse.... and

    Actually I have placed the following things in a folder:

    1- The Applet jar file : Applet_WindSpeedAnalysis.jar
    2- The Applet class file: Applet_windSpeedAnalysis.class
    3- Other class files: all the .class files that project uses.
    4- The external libraries jar files: There are 3 external libraries jar files that project uses:
    commons-csv-20070724.jar
    iText-5.0.4.jar
    krysalis-jCharts-1.0.0-alpha-1.jar


    And here is the html code that I got from some one, and I just modified accordingly.....

    Java Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>WindSpeedAnalysis</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    	
    		<script language="javascript">  
    		function appletStoped() {
    			//alert("Applet Stoped!");
    		}
    	</script>
    
      </head>
      
      <body>
       <applet code = "Applet_WindSpeedAnalysis.class" 
        archive = 'Applet_WindSpeedAnalysis.jar,iText-5.0.4.jar,commons-csv-20070724.jar, krysalis-jCharts-1.0.0-alpha-1.jar'
        width = 880, 
        height = 690 >
        
        </applet>
      </body>
    </html>

    The thing is when I run the executable jar file, it works fine......
    But when I open that html file in mozilla firefox, I get the window and the Applet gui.... fine...

    But there is a button load file on the applet that basically is used to browse to a location in your pc to load a file... and so on....
    That button does not work... No activity is performed even if that button is pressed....



    Is there any other library That i need to include in the html code... or some other thing I am missing.....

    Many Thanks for the cooperations....

    Best Regards,
    Sarwar

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    That button does not work... No activity is performed even if that button is pressed.
    Are there any messages in the browser's java console?
    Add some print out statements in your code to show that the code is being executed.
    The print outs will be in the java console.

  5. #5
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello....

    How to open the console.... because at the moment my html file is opening in web browser...

    I can add print statements in program and can see them in eclipse console...

    But how to open java console...??


    Many Thanks for the reply...

    Best Regards,
    Sarwar

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    how to open java console
    Look at all the menu items and options for your browser. One should refer to the java console.

  7. #7
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello....

    When I try to open java console, nothing appears... not even a console window....

    Is there any other way like cmd ... or ????

    Thanks...

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Try using another browser. What OS and browser are you using?

  9. #9
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hi,


    I am using Mozilla FireFox....

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    What is the OS?

  11. #11
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello....

    I read the java console and it gives the following message:

    Java Code:
    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Logic Energy
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    
    
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\Logic Energy\AppData\Roaming\Microsoft\Windows\Recent read)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkRead(Unknown Source)
    	at java.io.File.exists(Unknown Source)
    	at java.io.Win32FileSystem.canonicalize(Unknown Source)
    	at java.io.File.getCanonicalPath(Unknown Source)
    	at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source)
    	at sun.awt.shell.Win32ShellFolderManager2.getRecent(Unknown Source)
    	at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
    	at sun.awt.shell.ShellFolder.get(Unknown Source)
    	at sun.swing.WindowsPlacesBar.<init>(Unknown Source)
    	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(Unknown Source)
    	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(Unknown Source)
    	at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
    	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(Unknown Source)
    	at javax.swing.JComponent.setUI(Unknown Source)
    	at javax.swing.JFileChooser.updateUI(Unknown Source)
    	at javax.swing.JFileChooser.setup(Unknown Source)
    	at javax.swing.JFileChooser.<init>(Unknown Source)
    	at javax.swing.JFileChooser.<init>(Unknown Source)
    	at OptionPanel$1.actionPerformed(OptionPanel.java:97)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(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)

    Any idea... As I say the executable jar works fine....

    But the nothing happens when the button is pressed on the gui, after the html file is opened in the browser...

    Many Thanks....

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    access denied (java.io.FilePermission C:\Users\Logic Energy\AppData\Roaming\Microsoft\Windows\Recent read)
    Your applet is trying to do something without permission. Applets are restricted to only being able to access resources from where they are loaded from.

    Why are you trying to read files from the C drive inside of an applet?

  13. #13
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello...

    Actually The application loads a CSV data file... and then process it....

    And shows the charts depending on the data file....

    But not from C:

    It can be from any where.... Is the html code or some thing trying to read some file from C:\.... ????

    One more thing... when I execute the jar file.. and then press the button, it takes me to the C:\Usres\logicEnergy\Documents folder.... and then from there i can browse to any where in my pc to load a file....


    Any idea.....???

    Many Thanks

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Applications do not need permission to read files on your PC.
    Applets do need permission to access anything outside of where they were loaded from.

    Why are you trying to read files from the C drive inside of an applet?

    See the error message for the location it was trying to read:
    FilePermission C:\Users\Logic Energy\AppData\Roaming\Microsoft\Windows\Recent read

  15. #15
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    So It means that I should try to read from the same folder where the applet file and other files are...

    The action listener of that button is:

    Java Code:
    button.addActionListener(new ActionListener() {
    
    			public void actionPerformed(ActionEvent arg0) {
    
    				JFileChooser chooser = new JFileChooser();
    				// chooser.setCurrentDirectory(new File("."));
    				chooser.setFileFilter(new FileFilter() {
    					public boolean accept(File f) {
    						return f.getName().toLowerCase().endsWith(".csv")
    								|| f.isDirectory();
    					}
    
    					public String getDescription() {
    						return "*.csv (Comma-separated values) ";
    					}
    				});
    
    				int r = chooser.showOpenDialog(OptionPanel.this);
    
    				if (r == JFileChooser.APPROVE_OPTION) {
    
    					String filename = chooser.getSelectedFile().toString();
    					txtLocation.setText(filename);
    					btnOk.setEnabled(true);
    				}
    			}
    		});

    I think applet is not performing this method....

    Is there any way that I can run this function from the applet when opened in browser...???

    Or should I direct the file reader to point to the same directory where the html and all other files are placed....

    Many Thanks for the cooperation....

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Try it and see. I don't use JFileChooser from an applet because it will fail most of the time.

    Again:
    Why are you trying to read files from the inside of an applet?
    Why not have a desktop app?


    It is possible to give applets permission to read files on a specific PC by changing the .java.policy file on that PC to give the applet the permissions it needs.

  17. #17
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hello,

    The idea is to have an application on the server....

    so that users can access that application via a web browser.... and then the user can load data file in that application to process...

    I have that java.policy file in the same folder where html file and all others jars and class file are placed... and java.policy file is as follws:
    Java Code:
    /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
    /* DO NOT EDIT */
    
    grant {
      permission java.security.AllPermission;
    };
    But It does not allow my to load file even from my pc...


    Many Thanks for reply....

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    The location and the name of the policy file is important.
    It's name is .java.policy (note leading .)
    The location for my file is in the system's owner's folder:
    C:\Documents and Settings\Owner\.java.policy

    You can get the location by executing this: System.getProperty("user.home")

    There is a reference to this file from a policy file in the JRE's folders somewhere.
    Last edited by Norm; 10-04-2010 at 12:39 AM.

  19. #19
    sarwar1234 is offline Member
    Join Date
    Sep 2010
    Posts
    56
    Rep Power
    0

    Default

    Hi Norm,

    I changed the name of the java.policy file to ".java.policy" like we change the name of any file....

    and also placed that file in the location that I get from the method:

    String userHome = System.getProperty("user.home");


    But still I get that window when I run my html in a browser.... The securit concern window pops up...

    Any idea of how to tackle this problem...


    Many Thanks...

    Best Regards,
    Sarwar

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Use the policytool to see if it finds the .java.policy file to be sure it is in the correct folder.
    I don't know any way to have the system tell you if it is using your .java.policy file.

    The securit concern window pops up...
    What window is that?

Page 1 of 2 12 LastLast

Similar Threads

  1. Putting Applet on web with images
    By Peetahzee in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 09:35 PM
  2. Putting image into program
    By SprayAndPray69 in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 04:38 AM
  3. Putting Image into Java applet
    By SprayAndPray69 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 07:14 AM
  4. Need help putting Exceptions in my program.
    By Loop in forum New To Java
    Replies: 6
    Last Post: 10-14-2008, 12:48 AM
  5. print webpage through applet
    By shakti singh in forum Java Applets
    Replies: 1
    Last Post: 07-22-2008, 08:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •