Wednesday, 28 August 2013

Pass the following parameters to Applet: a. Shapes (Rectangle or Oval) b. Style (Hollow or Solid) c. BgColor (R,G,B value) d. FrColor (R,G,B value) e. X f. Y g. Width h. Height

import java.awt.*;
import java.applet.*;

public class PeraComputer extends Applet {

    int xs[] = {100, 220, 160};
    int ys[] = {270, 270, 220};
    String CPUBgColor = new String();
    String CPUFrColor = new String();
    String MouseBgColor = new String();
    String MouseFrColor = new String();
    String KeyBgColor = new String();
    String KeyFrColor = new String();
    String ScreenImage = new String();
    String ScreenFrColor=new String();
    Image img=null;
    int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
  
    public void init() {
        CPUBgColor = getParameter("CPUBgColor");
        CPUFrColor = getParameter("CPUFrColor");
        MouseBgColor = getParameter("MouseBgColor");
        MouseFrColor = getParameter("MouseFrColor");
        KeyBgColor = getParameter("KeyBgColor");
        KeyFrColor = getParameter("KeyFrColor");
        ScreenImage = getParameter("ScreenImage");
        ScreenFrColor=getParameter("ScreenFrColor");
        x1 = CPUBgColor.indexOf(",");
        y1 = CPUBgColor.lastIndexOf(",");
        x2 = CPUFrColor.indexOf(",");
        y2 = CPUFrColor.lastIndexOf(",");
        x3 = MouseBgColor.indexOf(",");
        y3 = MouseBgColor.lastIndexOf(",");
        x4 = MouseFrColor.indexOf(",");
        y4 = MouseFrColor.lastIndexOf(",");
        x5 = KeyBgColor.indexOf(",");
        y5 = KeyBgColor.lastIndexOf(",");
        x6 = KeyFrColor.indexOf(",");
        y6 = KeyFrColor.lastIndexOf(",");
        x7 = ScreenFrColor.indexOf(",");
        y7= ScreenFrColor.lastIndexOf(",");

    }

    public void paint(Graphics g) {
       
        img=getImage(getCodeBase(),ScreenImage);
        g.drawImage(img, 100, 100, this);
        //Monitor
        g.setColor(new Color(Integer.parseInt(ScreenFrColor.substring(0, x7)), Integer.parseInt(ScreenFrColor.substring(x7 + 1, y7)), Integer.parseInt(ScreenFrColor.substring(y7 + 1))));
        g.drawRect(100, 100, 120, 120);
        g.fillPolygon(xs, ys, 3);
        //CPU
        g.setColor(new Color(Integer.parseInt(CPUBgColor.substring(0, x1)), Integer.parseInt(CPUBgColor.substring(x1 + 1, y1)), Integer.parseInt(CPUBgColor.substring(y1 + 1))));
        g.fillRect(270, 100, 70, 170);
        g.setColor(new Color(Integer.parseInt(CPUFrColor.substring(0, x2)), Integer.parseInt(CPUFrColor.substring(x2 + 1, y2)), Integer.parseInt(CPUFrColor.substring(y2 + 1))));
        g.drawRect(270, 100, 70, 170);
        g.fillRect(305,110,30,10);
        g.fillOval(325,125,8,8);
        g.fillOval(287,142,35,35);
        g.fillOval(290,187,30,30);
        g.fillOval(293,227,25,25);
        //KeyBoard
        g.setColor(new Color(Integer.parseInt(KeyBgColor.substring(0, x5)), Integer.parseInt(KeyBgColor.substring(x5 + 1, y5)), Integer.parseInt(KeyBgColor.substring(y5 + 1))));
        g.fillRect(100, 320, 120, 50);
         g.setColor(new Color(Integer.parseInt(KeyFrColor.substring(0, x6)), Integer.parseInt(KeyFrColor.substring(x6 + 1, y6)), Integer.parseInt(KeyFrColor.substring(y6 + 1))));
        g.drawRect(100, 320, 120, 50);
        g.fillOval(110,325,10,10);
        g.fillOval(125,325,10,10);
        g.fillOval(140,325,10,10);
        g.fillOval(155,325,10,10);
        g.fillOval(170,325,10,10);
        g.fillOval(185,325,10,10);
        g.fillOval(200,325,10,10);
        g.fillRect(105,340,10,10);
        g.fillRect(120,340,10,10);
        g.fillRect(135,340,10,10);
        g.fillRect(150,340,10,10);
        g.fillRect(165,340,10,10);
        g.fillRect(180,340,10,10);
        g.fillRect(195,340,10,10);
        g.fillRect(210,340,5,10);
        g.fillRect(105,355,10,10);
        g.fillRect(120,355,10,10);
        g.fillRect(135,355,10,10);
        g.fillRect(150,355,10,10);
        g.fillRect(165,355,10,10);
        g.fillRect(180,355,10,10);
        g.fillRect(195,355,10,10);
        g.fillRect(210,355,5,10);
        //Mouse
        g.setColor(new Color(Integer.parseInt(MouseBgColor.substring(0, x3)), Integer.parseInt(MouseBgColor.substring(x3 + 1, y3)), Integer.parseInt(MouseBgColor.substring(y3 + 1))));
        g.fillRect(245, 335, 30, 25);
        g.fillArc(245, 320, 30, 30, 0, 180);
        g.setColor(new Color(Integer.parseInt(MouseFrColor.substring(0, x4)), Integer.parseInt(MouseFrColor.substring(x4 + 1, y4)), Integer.parseInt(MouseFrColor.substring(y4 + 1))));
        g.drawArc(245, 320, 30, 30, 0, 180);
        g.drawRect(245, 335, 30, 25);
        g.drawRect(258,320,4,15);

    }
}

No comments:

Post a Comment