Results 1 to 4 of 4
  1. #1
    wbrandon is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default need helping using multiple classes in bluej!

    i am having trouble getting my train to show up from my train class to my driver class. how do i do this?

  2. #2
    wbrandon is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Re: need helping using multiple classes in bluej!

    Java Code:
    public Train(GCanvas myCanvas)
        {
            canvas = myCanvas;
        }
    
        //~ Methods ...............................................................
    
        /**
        * This is a placeholder javadoc comment.
        * @param x explain variable "x"
        * @param y explain variable "y"
        */
        public void drawTrain(double x, double y)
        {
            double trainWidth = 3 * CAR_WIDTH + 4 * CONNECTOR;
            double dx = CAR_WIDTH + CONNECTOR;
            drawEngine(x, y);
            drawBoxcar(x + dx, y, Color.GREEN);
            drawBoxcar2(x + 2 * dx, y, Color.GREEN);
            drawCaboose(x + 3 * dx, y, Color.RED);
    
        }
    
        /**
         * This is a placeholder javadoc comment.
         * @param x explain variable "x"
         * @param y explain variable "y"
         */
        public void drawEngine(double x, double y)
        {
            double x0 = x + CONNECTOR;
            double y0 = y - CAR_BASELINE;
            double top = y0 - CAR_HEIGHT;
            add(new GLine(x, y0, x + CAR_WIDTH + 2 * CONNECTOR, y0));
            drawWheel(x0 + WHEEL_INSET, y - WHEEL_RADIUS);
            drawWheel(x0 + CAR_WIDTH - WHEEL_INSET, y - WHEEL_RADIUS);
            GRect p = new GRect(x0 + SMOKESTACK_INSET, y - CAR_HEIGHT - WHEEL_INSET, SMOKESTACK_HEIGHT, SMOKESTACK_WIDTH);
            GRect r = new GRect(x0, top, CAR_WIDTH, CAR_HEIGHT);
            GRect q = new GRect(x0 + CAR_WIDTH - CAB_WIDTH, y - CAR_HEIGHT - WHEEL_INSET, CAB_WIDTH, CAB_HEIGHT);
            GLine c = new GLine(x, y - CAR_BASELINE, x + CONNECTOR, y0 -(CAR_HEIGHT / 2));
            GLine c2 = new GLine(x0 -(CONNECTOR / 2), y - CAR_BASELINE, x + CONNECTOR, y0 -(CAR_HEIGHT / 2));
            r.setFilled(true);
            r.setFillColor(Color.BLACK);
            p.setFilled(true);
            p.setFillColor(Color.BLACK);
            q.setFilled(true);
            q.setFillColor(Color.BLACK);
            add(c2);
            add(c);
            add(r);
            add(p);
            add(q);
        }
    
        /**
         * This is a placeholder javadoc comment.
         * @param x explain variable "x"
         * @param y explain variable "y"
         * @param color explain variable "color"
         */
        public void drawBoxcar(double x, double y, Color color)
        {
            drawCarFrame(x, y);
            double x0 = x + CONNECTOR;
            double y0 = y - CAR_BASELINE;
            double top = y0 - CAR_HEIGHT;
            add(new GLine(x, y0, x + CAR_WIDTH + 2 * CONNECTOR, y0));
            drawWheel(x0 + WHEEL_INSET, y - WHEEL_RADIUS);
            drawWheel(x0 + CAR_WIDTH - WHEEL_INSET, y - WHEEL_RADIUS);
            GRect r = new GRect(x0, top, CAR_WIDTH, CAR_HEIGHT);
            r.setFilled(true);
            r.setFillColor(Color.GREEN);
            add(r);
            double xRight = x + CONNECTOR + CAR_WIDTH / 2;
            double xLeft = xRight - DOOR_WIDTH;
            double yDoor = y - CAR_BASELINE - DOOR_HEIGHT;
            add(new GRect(xLeft, yDoor, DOOR_WIDTH, DOOR_HEIGHT));
            add(new GRect(xRight, yDoor, DOOR_WIDTH, DOOR_HEIGHT));
        }
        public void drawBoxcar2(double x, double y, Color color)
        {
            drawCarFrame(x, y);
            double x0 = x + CONNECTOR;
            double y0 = y - CAR_BASELINE;
            double top = y0 - CAR_HEIGHT;
            add(new GLine(x, y0, x + CAR_WIDTH + 2 * CONNECTOR, y0));
            drawWheel(x0 + WHEEL_INSET, y - WHEEL_RADIUS);
            drawWheel(x0 + CAR_WIDTH - WHEEL_INSET, y - WHEEL_RADIUS);
            GRect r = new GRect(x0, top, CAR_WIDTH, CAR_HEIGHT);
            r.setFilled(true);
            r.setFillColor(Color.GREEN);
            add(r);
            double xRight = x + CONNECTOR + CAR_WIDTH / 2;
            double xLeft = xRight - DOOR_WIDTH;
            double yDoor = y - CAR_BASELINE - DOOR_HEIGHT;
            add(new GRect(xLeft, yDoor, DOOR_WIDTH, DOOR_HEIGHT));
            add(new GRect(xRight, yDoor, DOOR_WIDTH, DOOR_HEIGHT));
        }
        /**
         * This is a placeholder javadoc comment.
         * @param x explain variable "x"
         * @param y explain variable "y"
         */
        public void drawCaboose(double x, double y, Color color)
        {
            double x0 = x + CONNECTOR;
            double y0 = y - CAR_BASELINE;
            double top = y0 - CAR_HEIGHT;
            add(new GLine(x, y0, x + CAR_WIDTH + 2 * CONNECTOR, y0));
            drawWheel(x0 + WHEEL_INSET, y - WHEEL_RADIUS);
            drawWheel(x0 + CAR_WIDTH - WHEEL_INSET, y - WHEEL_RADIUS);
            GRect o = new GRect(x0 +(CAB_WIDTH / 2) +(WHEEL_RADIUS / 2), y - CAR_HEIGHT - WHEEL_INSET, CUPOLA_WIDTH, CUPOLA_HEIGHT);
            GRect r = new GRect(x0, top, CAR_WIDTH, CAR_HEIGHT);
            r.setFilled(true);
            r.setFillColor(Color.RED);
            o.setFilled(true);
            o.setFillColor(Color.RED);
            add(o);
            add(r);
        }
    
        //Private Methods
    
        /**
        * This is a placeholder javadoc comment.
        * @param x explain variable "x"
        * @param y explain variable "y"
        */
        private void drawCarFrame(double x, double y)
        {
            double x0 = x + CONNECTOR;
            double y0 = y - CAR_BASELINE;
            double top = y0 - CAR_HEIGHT;
            add(new GLine(x, y0, x + CAR_WIDTH + 2 * CONNECTOR, y0));
            drawWheel(x0 + WHEEL_INSET, y - WHEEL_RADIUS);
            drawWheel(x0 + CAR_WIDTH - WHEEL_INSET, y - WHEEL_RADIUS);
            GRect r = new GRect(x0, top, CAR_WIDTH, CAR_HEIGHT);
            r.setFilled(true);
            r.setFillColor(Color.GRAY);
            add(r);
        }
    
        /**
         * This is a placeholder javadoc comment.
         * @param x explain variable "x"
         * @param y explain variable "y"
         */
        private void drawWheel(double x, double y)
        {
    
            double r = WHEEL_RADIUS;
            GOval wheel = new GOval(x - r, y - r, 2 * r, 2 * r);
            wheel.setFilled(true);
            wheel.setFillColor(Color.GRAY);
            add(wheel);
        }
    Last edited by JosAH; 03-30-2013 at 08:09 PM. Reason: added [code] ... [/code] tags

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: need helping using multiple classes in bluej!

    Maybe I'm missing something, but I don't see a Driver class anywhere in the code above.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: need helping using multiple classes in bluej!

    Quote Originally Posted by Fubarable View Post
    I don't see a Driver class anywhere in the code above.
    Rather like Unstoppable (2010 film) - Wikipedia, the free encyclopedia
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 59
    Last Post: 05-22-2011, 08:37 AM
  2. Multiple classes
    By Lund01 in forum New To Java
    Replies: 1
    Last Post: 03-16-2011, 02:58 PM
  3. help with GUI and multiple classes
    By sssss in forum Advanced Java
    Replies: 14
    Last Post: 01-16-2011, 10:08 PM
  4. BlueJ arrow missing betwen two classes
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-29-2009, 12:42 PM
  5. Replies: 1
    Last Post: 04-17-2008, 02:30 PM

Posting Permissions

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