Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: publishing an applet

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default publishing an applet

    hey guys I am Kareem a new member here.

    actually I was trying to publish a simple applet to a web page when I met a problem that the plugin cannot find my class although I put the .jar file in the same path of the html one and this is ma java code:
    package mainpackage;
    import java.awt.Graphics;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
     
    public class ImageMapping extends JApplet {
    	private ImageIcon mapImage;
    	private static final String captions[] = {"you're on icon number 1","you're on icon number 2","you're on icon number 3",
    		"you're on icon number 4","you're on icon number 5",
    		"you're on icon number 6","you're on icon number 7"
    	};
    	public void init () {
    		addMouseListener(
    				new MouseAdapter() {				
    					public void mouseExited (MouseEvent event) {
    						showStatus("you're outside the image!");
    					}
    				}
    		);
     
    		addMouseMotionListener(
    				new MouseMotionAdapter() {
    					public void mouseMoved (MouseEvent event) {
    						showStatus(translateLocation(event.getX(),event.getY()));
    					}
    				}	
    		);	
    		mapImage = new ImageIcon (getClass().getResource("../resource/icons.png"));
    	}
    	public void paint (Graphics g) {	
    		super.paint(g);
    		mapImage.paintIcon(this, g, 0, 0)
    	}
    	public String translateLocation (int x, int y) {	
    		if(x >= mapImage.getIconWidth() || y >= mapImage.getIconHeight()){
    			return "";
    		}
    		double iconWidth = mapImage.getIconWidth()/7.0;
    		int iconNumber = (int) ((double) x/iconWidth);
    		return captions[iconNumber];
    	}
    }

    and this is my html code:
    <html> 
    <head>
    <title> Applet Example </title>
    </head>
    <body>
    <applet code = 
    "mainpackage.ImageMapping.class"
    width = "606" height "90" archive = 
    "imageMaping.jar">
    there's an error
    </applet>
    </body>
    </html>


    actually I don't know what's wrong with my codes, when I open the web page I just find error: click for details, when I check the details a java window just appears and tells :

    Java Plug-in 10.6.2.24
    Using JRE version 1.7.0_06-b24 Java HotSpot(TM) Client VM
    User home directory = C:\Users\DELL
    ----------------------------------------------------
    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>
    ----------------------------------------------------


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: publishing an applet

    Try this instead in your html applet tag code variable: "mainpackage/ImageMapping.class"
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by aussiemcgr View Post
    Try this instead in your html applet tag code variable: "mainpackage/ImageMapping.class"
    I've just tried that and this also does not work with me
    Last edited by Kareem Mesbah; August 24th, 2012 at 04:47 PM.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: publishing an applet

    Ok, well that is one problem. In the html applet tag, you should use "/" instead of ".", since a jar file is really just a zip folder, and each package has its own folder. Or at least that's the way I have my html code for my apps.
    I find it suspicious that you are not receiving any errors in the console. Why do you have the text "there's an error" between your open and close applet tags in your html? I don't know if that would break it or not, just curious.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by aussiemcgr View Post
    Ok, well that is one problem. In the html applet tag, you should use "/" instead of ".", since a jar file is really just a zip folder, and each package has its own folder. Or at least that's the way I have my html code for my apps.
    I find it suspicious that you are not receiving any errors in the console. Why do you have the text "there's an error" between your open and close applet tags in your html? I don't know if that would break it or not, just curious.
    this message should appear when the browser does not support my app.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: publishing an applet

    To elaborate:
    Browsers that support the applet tag will(should) place the applet in position and ignore all markup before the closing applet tag.

    Browsers that do not support the applet tag will(should) still render the markup between the applet tags. Many times this area is used to assist the user in updating/installing, what ever is necessary for it to run.

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by jps View Post
    To elaborate:
    Browsers that support the applet tag will(should) place the applet in position and ignore all markup before the closing applet tag.

    Browsers that do not support the applet tag will(should) still render the markup between the applet tags. Many times this area is used to assist the user in updating/installing, what ever is necessary for it to run.
    it just draws the area of the applet and shows error: click for details. !

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    Strange there is no error message in the contents of the java console that you posted. Are you sure you copied all of its contents?

    Is the class file in the jar file in the mainpackage folder? Use a zip utility to look inside the jar file.

    The code= attribute should have the full classname as its value. The classname parts are separated by .s and does not include .class which is part of the filename, not the classname.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by Norm View Post
    Strange there is no error message in the contents of the java console that you posted. Are you sure you copied all of its contents?

    Is the class file in the jar file in the mainpackage folder? Use a zip utility to look inside the jar file.

    The code= attribute should have the full classname as its value. The classname parts are separated by .s and does not include .class which is part of the filename, not the classname.
    I've noticed that the image does not exist into the jar file also I exported everything, here are you the html code and the jar file included the java code you can try this yourself if you don't mind. (attached)
    Attached Files Attached Files

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    image does not exist into the jar file
    Can you put the image in the jar file? That will be better.
    Can you post the code and html you are using on the forum?

    NOTE: There is a compiler error in the posted code and an error in the posted html page.
    Last edited by Norm; August 25th, 2012 at 08:47 AM. Reason: errors
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by Norm View Post
    Can you put the image in the jar file? That will be better.
    Can you post the code and html you are using on the forum?

    NOTE: There is a compiler error in the posted code and an error in the posted html page.
    I don't know how to include it into the jar file, I am using eclipes and when exporting I check the box "export generated class files and resources"
    about the errors, when I run it from inside eclipse it runs successfully without any problems. please could you tell me what are you code errors you discovered ?

    about posting the codes I already posted them in the first post.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    I copied the code that was posted and it works for me outside of a jar file.
    I don't use your IDE and can't help you with it.
    Look at the section of the forum for your IDE and see if there are posts that tell how to include files in the jar file the IDE creates.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by Norm View Post
    I copied the code that was posted and it works for me outside of a jar file.
    I don't use your IDE and can't help you with it.
    Look at the section of the forum for your IDE and see if there are posts that tell how to include files in the jar file the IDE creates.
    please tell me how could you export it without an IDE, I've exported it according to a video tutorial so I don't know what's wrong.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    What do you mean by "export"? That sounds like a problem with the IDE.
    I use a simple editor with a command line where I can issue the javac command. I copy the html to the same folder as the .class file and open it with a browser. The image file is in a folder inside the folder with the .class and the .html files. No IDE.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by Norm View Post
    What do you mean by "export"? That sounds like a problem with the IDE.
    I use a simple editor with a command line where I can issue the javac command. I copy the html to the same folder as the .class file and open it with a browser. The image file is in a folder inside the folder with the .class and the .html files. No IDE.
    so you mean that there's no need for the .jar file ?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    You should use a jar file to hold the class file and the image file. I don't know how to you can tell the IDE to put all the files you need in the jar file.
    If all the files are in the jar file, then you must use the correct path to be able to read the image file from the jar file.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: publishing an applet

    Quote Originally Posted by Norm View Post
    You should use a jar file to hold the class file and the image file. I don't know how to you can tell the IDE to put all the files you need in the jar file.
    If all the files are in the jar file, then you must use the correct path to be able to read the image file from the jar file.
    got it, thanks for your help I am gonna look for that. I was just asking how could you generate the .jar file including the image without using IDE ?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: publishing an applet

    how could you generate the .jar file including the image without using IDE
    I use the jar command. I write a batch file that contains the jar command for any project that needs to be in a jar file.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Publishing a Java program
    By gordc in forum Java IDEs
    Replies: 3
    Last Post: July 21st, 2012, 04:15 PM
  2. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  3. Replies: 0
    Last Post: November 13th, 2011, 10:27 PM
  4. Replies: 0
    Last Post: October 13th, 2011, 07:42 PM