Jump to content

Madi

Ultra Members
  • Posts

    1,139
  • Joined

  • Last visited

Posts posted by Madi

  1. E:D:I:T

    heres my horrible code, were suppose to draw something and i can get everything but the speakers to show up

     

    // Crash.java

    import java.util.Random;

    import java.util.*;

    import java.awt.*;

    import java.applet.*;

     

     

    public class Crash extends Applet

    {

    public void paint(Graphics g)

    {

     

      Mac mac = new Mac(g,150,100,500,300);

    }

    }

     

    class Mac extends Computer

      private int tX; //Top X coordinate

      private int tY; // Top  Y coordinate

        private int width; // width of the computer

        private int height; // height of the computer

        Speakers speakers;

     

        public Mac(Graphics g, int x, int y, int w, int h)

          super(g,x,y,w,h);

        tX = x;

        tY = y;

        width = w;

        height = h;

        speakers = new Speakers(g,x,y,w,h);

       

       

    }

     

    }

     

    class Computer

       

    private int tX;

    private int tY;

    private int mW; //Monitor width

    private int mH;//Monitor height

    private int sX; //screen X

    private int sY;//screen Y

    private int sW;//screen width

    private int sH;//screen height

        Keyboard keyboard;

       

    public Computer(Graphics g,int x,int y,int w,int h)

     

        tX = x;

        tY = y;

        mW = w;

        mH = h;

        sX = x+50;

          sY = y+15;

          sW = w-100;

          sH = h-30;

          keyboard = new Keyboard(g,x,y,w,h);

          drawMonitor(g);

        drawScreen(g);

     

       

        }

        public void drawMonitor(Graphics g)

        {   

          g.drawRect(tX,tY,mW,mH);

        }

        public void drawScreen(Graphics g)

        {   

          g.drawRect(sX,sY,sW,sH);

        } 

     

    }

     

     

       

    class Speakers extends Mac

    {

    private int lX;//left speaker x

    private int lY;//left speaker y

    private int rX; // right speaker x

    private int rY; //right speaker y

    private int sW;//speaker width

    private int sH;//speaker width

     

     

    public Speakers(Graphics g,int x,int y,int w,int h)

    {

     

      super(g,x,y,w,h);

     

      lX=x+400;

      lY=y+400;

        sW=w-10;

      sH=h-10;

        drawSpeakers(g);

    }

     

    public void drawSpeakers(Graphics g)

    {

      g.drawRect(10,10,10,10);

    }

     

    }

     

     

     

    class Keyboard

    private int kX; //keyboard x

    private int kY; //keyboard y

    private int kW; //keyboard width

    private int kH; //keyboard height

    Random rndInt = new Random();

     

        public Keyboard(Graphics g,int x,int y,int w,int h)

        {

            kX= x-10;

        kY= y+300;

        kW= w+20;

        kH= h-200;

        //  drawCrash(g);

          drawKeyboard(g);

           

        }

        public void drawKeyboard(Graphics g)

        { 

        g.drawRect(kX,kY,kW,kH);

        }

       

      /*/ public void drawCrash(Graphics g)

        {

          int k;

        for(k=1;k <= 1;k--)

        { 

        int a = rndInt.nextInt(255);

        int b = rndInt.nextInt(255);

        int c = rndInt.nextInt(255);

        Color myRed = new Color(a,b,c);

        g.setColor(myRed);

        g.drawRect(200,115,400,270);

        g.fillRect(200,115,400,270); 

        }

        }

        /*/

       

     

     

    }

  2. Ok im freaking stuck with my Java lab and i need help lol, im suppose to show 2 examples of inheritance, and 2 levels of composition, does anyone know how to do this? ill post my stupid code if some one does....

×
×
  • Create New...