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 4 of 4

Thread: Passing parameters to an Applet

  1. #1
    Junior Member Fabgio's Avatar
    Join Date
    Feb 2013
    Location
    Padua, Italy
    Posts
    8
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Passing parameters to an Applet

    I am in the throws of passing parameters to an applet using getParameter method. I am completely new to HTML tags.
    Here is the code:
    import java.awt.*;
    import java.applet.*;
    /*
     *
      <applet code="ParamDemo" width=100 height=80>
        <param name=fontName value="Courier">
        <param name=fontSize value="14">
        <param name=leading  value="2">
        <param name=accountEnabled value=true>
    </applet>
     */
    //use ParamDemo
     
    public class ParamDemo extends Applet {
        String fontName;
        int fontSize;
        float leading;
        boolean active;
        public void start(){
            String param;
     
            fontName=getParameter("fontName");
            if (fontName==null)
                fontName="Font Not Found";
     
            param=getParameter("fontsize");
            try{
                if (param !=null)
                    fontSize=Integer.parseInt(param);
                else fontSize=0;
            }catch(NumberFormatException e){
                fontSize=-1;
            }
            param=getParameter("leading");
            try{
                if (param !=null)
                   leading=Float.valueOf(param).floatValue();
                else fontSize=0;
            }catch(NumberFormatException e){
                leading=-1;
        }
            param=getParameter("accountEnabled");
            if(param!=null)
                active=Boolean.valueOf(param).booleanValue();
     
    }
        public void paint(Graphics g){
            g.drawString("Fontname:   "+fontName, 0, 10);
            g.drawString("FontSize:   "+fontSize, 0, 26);
            g.drawString("leading     "+leading, 0, 42);
            g.drawString("AccoumtActive "+active, 0, 58);
        }
    }
    No parameter is being passed to the applet.
    I tried debugging the code but param variable is always set to null. What's wrong?


  2. #2
    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: Passing parameters to an Applet

    Quote Originally Posted by Fabgio View Post
    What's wrong?
    Good question. What does it do? What should it do instead?
    Where does getParameter get information from?... what information is there?... Verify it is present and available to the Applet.

  3. The Following User Says Thank You to jps For This Useful Post:

    Fabgio (July 26th, 2013)

  4. #3
    Junior Member Fabgio's Avatar
    Join Date
    Feb 2013
    Location
    Padua, Italy
    Posts
    8
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Passing parameters to an Applet

    I have just solved the problem. Following your tip I verified the information source was present. So I commented out the HTML block and exported it to an HTML file. So everything works! I made a silly mistake though....Thank you so much!

  5. #4
    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: Passing parameters to an Applet

    Glad you got it working. Thank you for marking your thread solved too

Similar Threads

  1. Replies: 14
    Last Post: March 6th, 2013, 01:54 PM
  2. passing parameters from Applet to JSP
    By haythem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 4th, 2013, 01:06 AM
  3. [SOLVED] Why re-name these method parameters?
    By pict3000 in forum Object Oriented Programming
    Replies: 6
    Last Post: August 9th, 2012, 06:07 AM
  4. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  5. Help using parameters
    By white97 in forum Object Oriented Programming
    Replies: 6
    Last Post: August 9th, 2011, 07:28 PM