1

A java applet to display a rectangle with specified coordinate and colour passed as parameter from the HTML file. I'm able retrieve and set the coordinate's of the rectangle passed as parameters from an html file but i'm unable to set the colour passed as parameter from an html file,how to do this? I have tried this code,but its not working properly.

import java.awt.*;
import java.applet.*;
/* <applet code="ParaRect" width=1200 height=1000>
<param name=x value=100>
<param name=y value=200>
<param name=color value="red">
</applet> */
public class ParaRect extends Applet{
    public void paint(Graphics g){ 
       String x=getParameter("color");
       g.setColor(Color.x);
       g.fillRect(Integer.parseInt(getParameter("x")),Integer.parseInt(getParameter("y")),150,100);
    }
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

0
   ''' 
    import java.awt.*;
    import java.applet.*;
    /* <applet code="ParaRect" width=1200 height=1000>
        <param name=x value=100>
       <param name=y value=200>
       <param name="color" value="FF0000">
       </applet> */
       public class ParaRect extends Applet{  
       public void paint(Graphics g) {
       Color col =  new 
       Color(Integer.parseInt(this.getParameter("color"),16));
       g.setColor(col);

g.fillRect(Integer.parseInt(getParameter("x")),Integer.parseI nt(getParameter("y")),150,100); }
} '''