Results 1 to 3 of 3

Thread: Problem with getParameter from HTMl file using param tag

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    Problem with getParameter from HTMl file using param tag

    Hi I need help plese, could any one tell me how to Pass in avirable from the HTML file using the PARAM tag. Also, pass in parameters to specify the font and colour of the text that is drawn to the screen. I did creat an Applet to demostrate it but doesn't displeay the the name said Hello null insteat of hello Ali.

    Code:
    public class DrawName extends java.applet.Applet {
        String name;
        Color color;
         Font font;
        /** Initialization method that will be called after the applet is loaded
         *  into the browser.
         */
        public void init() {
           
          name = getParameter("name");  
          //color= getParameter("color");
          //font= getParameter("font");
            
        }
       
        // TODO overwrite start(), stop() and destroy() methods
    
        public void paint(Graphics g) {
            
            //g.setColor(color);
            g.drawString("Hello" + name ,50,30);
            
        }
    }
    HTML Code:
    <HTML>
    <HEAD>
       <TITLE>Applet HTML Page</TITLE>
    </HEAD>
    <BODY>
    <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
    
    <P>
    <APPLET codebase="classes" code="DrawName.class" width=350 height=200>
        <param name="name" value="Ali">
    </APPLET>
    </P>
    
    <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
    </BODY>
    </HTML>
    
    Last edited by omarali; Oct 9th, 2007 at 06:57 PM.

  2. #2
    New Member
    Join Date
    Oct 2007
    Location
    Netherlands
    Posts
    4

    Re: Problem with getParameter from HTMl file using param tag

    Code:
    public class DrawName extends java.applet.Applet {
        private String name;
        private Color color;
         Font font;
        /** Initialization method that will be called after the applet is loaded
         *  into the browser.
         */
        public void init( String name ) {
           
          name = getParameter("name");  
          //color= getParameter("color");
          //font= getParameter("font");
            
        }
    Try this, i don't now if its work because i don't work with applets but normally this will work..

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Problem with getParameter from HTMl file using param tag

    Just like markb1986 said, you can use the getParameter method to read param values. and here's an example:
    HTML Code:
    <html>
    
    <body>
    
    <applet code="MyApplet.class" style="width: 800px; height: 600px;">
    	<param name="name" value="My name">
    </applet>
    
    </body>
    
    </html>
    Code:
    public class MyApplet extends JApplet {
    
        @Override
        public void init() {
            String name = getParameter("name");
    
            if (name != null && !name.isEmpty()) {
                JOptionPane.showMessageDialog(null, name, "Name", JOptionPane.PLAIN_MESSAGE);
            }
        }
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width