Monday, January 16, 2012

School bus Java Programming

The following is a solution to a question asking you to draw a school bus using java. I put some people in the windows and other stuff as well. The only thing that I couldn't get right in this assignment, is getting the text to appear as I wanted it. The rest of the Java School bus is correct.

It is an applet, not an application, so it needs and accompanying HTML file, I'll try and find the file and upload it.


//************************************************
// SchoolBus.java
// CS151A, Assignment 3 Question #1
// Picture of a School Bus
//************************************************
import java.awt.*;     // import basic graphic components
import javax.swing.*;  // import advanced graphics components

public class SchoolBus extends JApplet
{

    public void paint(Graphics page)
    {
        //Sky//
        page.setColor(Color.blue);
        page.fillRect(0,0,1000,700);

        //Grass//
        page.setColor(Color.green);
        page.fillRect(0,550,1000,150);

        //Bus Body//
        page.setColor(Color.yellow);
        page.fillRect(200,200,750,300);
        page.fillRect(50,320,300,180);

        //Wheels//
        page.setColor(Color.black);
        page.fillOval(120,450,100,100);
        page.fillOval(800,450,100,100);

        //Sun//
        page.setColor(Color.yellow);
        page.fillOval(-20,-20,90,90);

        //Road//
        page.setColor(new Color(105,105,105));
        page.fillRect(0,550,1000,50);

        //Windows//
        page.setColor(new Color(190,190,190));
        page.fillRect(200,210,60,100);
        page.fillRect(300,210,80,100);
        page.fillRect(400,210,80,100);
        page.fillRect(500,210,80,100);
        page.fillRect(600,210,80,100);
        page.fillRect(700,210,80,100);
        page.fillRect(800,210,80,100);
        page.fillRect(900,210,50,100);

        //Text: School Bus//
        page.setColor(Color.black);
        page.drawString("School Bus",500,400);
    }
}

No comments:

Post a Comment