Results 1 to 5 of 5
  1. #1
    JungM is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default Java Applet please help!

    I am a new to Java and I am having problems with Applets.
    I am also a Mac OsX Snow Leopard user
    when I try to run this applet on Google Chrome, Firefox or any browser,
    all it displays is the html that I wrote in the html document... Not the applet itself.
    Also, I have checked this numerous times, and I believe that there aren't any errors in the java code.
    __________________________________________________ _____
    Java Code:
    import java.awt.*;
    
    public class BlankApplet extends javax.swing.JApplet {
    	String parameter1;
    	String parameter2;
    	String parameter3;
    	
    	public void init() {
    		parameter1= getParameter("adjective1") ;
    		parameter2= getParameter("adjective2") ;
    		parameter3= getParameter("adjective3") ;
    	}
    	
    	public void paint(Graphics screen) {
    		screen.drawString("The " + parameter1
    			+ " " + parameter2 + " fox "
    			+ "jumped over the "
    			+ parameter3 + " dog.", 5, 50);
    	}
    }
    --------------------------------------------------------------------------------------------------------
    the html file

    XML Code:
    <html>
    <body>
    <applet code="BlankApplet.class" height=80 width=500>
    <param name="adjective1" value="fast">
    <param name="adjective2" value="brown">
    <param name="adjective3" value="lazy">
    </applet>
    </body>
    </html>
    when I open the html file, it doesn't show 'the quick brown fox leapt over the lazy dog" but shows
    the html code
    <html>
    <body>
    <applet.....
    instead

    in other words, it doesn't work.
    PLEASE HELP
    Last edited by Fubarable; 08-06-2011 at 06:58 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your code as posted works for me suggesting that it's not a code problem but rather how you're using it. Is the Java class in a package or in the default package? Is your Java class file (not the .java file) located in the same directory as your html files? Does your HTML file have the ".html" extension? Are you opening it with an internet browser?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    Also look in the browser's java console for any error messages.

    Java Code:
    code="BlankApplet[COLOR="red"].class[/COLOR]"
    Some browsers look for the class.class file in the BlankApplet folder with this code=. Try removing the .class

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    It won't solve this problem, but you should never override the paint() method like that. Forgetting the super.paint() can cause problems.

    You shold use a JLabel and add the label to the applet.

    If you really need custom painting the extend JPanel or JComponent and override the paintComponent() method.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    when I open the html file, it doesn't show 'the quick brown fox leapt over the lazy dog" but shows
    the html code
    <html>
    <body>
    <applet.....
    instead
    It looks like you've saved the html as a text file. Does the filename have the correct extension (MacOS does identify file types by extension, doesn't it?)

    db

Similar Threads

  1. need help converting java program into a java applet
    By i'mhighdef in forum Java Applets
    Replies: 3
    Last Post: 05-04-2011, 11:55 PM
  2. Java Applet to Applet communication
    By jsman in forum Java Applets
    Replies: 3
    Last Post: 04-05-2011, 02:23 PM
  3. applet class inside java.applet.* or java.awt.*
    By Manish87 in forum Java Applets
    Replies: 1
    Last Post: 09-27-2010, 02:15 PM
  4. Replies: 3
    Last Post: 07-23-2008, 08:07 AM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Tags for this Thread

Posting Permissions

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