|
||||||||||||||||
. . . . . |
Java For Kids Tutorial 6
| Intro |
Begin |
if/else |
Loops |
Arrays |
Graphics |
Animation |
Mouse |
Game |
Real |
Methods |
Class |
Class 2 |
Applet |
MouseClick |
Thread |
Button |
Java GRAPHICSThe first step in making graphics shapes in Java is to set the color. After that you can draw the shape and then you must select another color to draw any further shapes of a different color. Basic shapes include rectangles and circles. Selecting a colorColors are selected by using the setColor method. Its basic form is : setColor(color) ;
Look in the JUDO help files for a list of usable colors.
Some are : red orange yellow green blue purple black white etc.. setBackgroundColor(color) ; Do it now !
void main() {
setBackgroundColor(black) ;
}
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com Drawing Shapes using JavaAll the shapes require pixel co-ordinates to create their size and position relative to the window they are drawn in. These are created according to their x, y positions.
To draw a rectangle, you will need to give the top-left x and y points and the width and height . drawRectangle(x , y , width , height);
Note that the x, y co-ordinates are the top-left corner. All numbers must be int's. drawRectangle(100,100, 200,200);
Lets do it !
void main() {
setBackgroundColor(red);
setColor(blue);
drawRectangle(100,100,300,150);
}
Here is what you should get . Amazing !
Try a circle ! Here is the template, where x, y are the top-left co-ordinates: drawCircle( x, y, radius)
Exercise: setColor(green); drawCircle(100,200,50); Notice that the shapes that we have drawn are only outlines and are not filled in. To draw filled shapes use : fillRectangle(x, y, width, height); fillCircle(x, y, radius); fillOval(x, y, width, height); Lets draw a self portrait !
void main() {
setBackgroundColor(yellow);
// body
setColor(red);
fillRectangle(100,100,50,50);
// arms
setColor(green);
fillRectangle(25,100,75,10);
fillRectangle(150, 100,75,10);
// legs
fillRectangle(100,150,10,75);
fillRectangle(140,150,10,75);
// head
setColor(blue);
fillCircle(100,50,50);
}
Here it is . Wow !
Java Exercise:
Java drawString methoddrawString paints a string of text at the point given. Here is the template, where String is the text to be written and x, y the coordinates of the bottom-left of the text: drawString(String , x , y ); e.g. # 1 String name = "Steve"; drawString(name, 35, 25); e.g. #2
drawString("This is text", 15, 35);
Sooo, Lets make our logo:
void main() {
setBackgroundColor(white);
setColor(black);
fillRectangle(100,100,100,100);
setColor(white);
drawString("Java For Kids" , 150,120);
setColor(red);
drawRectangle(100,100,100,100);
}
Java Exercises:
Some Answers
void main() {
setBackgroundColor(black);
setColor(white);
// front
fillRectangle(100,100,300,100);
// roof
drawLine(100,100,250,25);
drawLine(250,25,400,100);
// windows
setColor(blue);
fillRectangle(125,125,20,20);
fillRectangle(355,125,20,20);
// door
setColor(red);
fillRectangle(240,150, 30,50);
}
Row of Circles
void main() {
// declare width , height of window
int width;
int height;
int gap;
// declare number of circles in a row
int cnum = 40;
// get width and height of window
width = getDrawingWidth();
// divide width by number of circles you want = radius x 2
gap = width/cnum;
// loop for number of circles
for(int counter = 0; counter < cnum ; counter++)
{
// draw a circle at count * radius
setColor(red);
fillCircle(counter*gap,0,gap);
//end loop
}
}
|
|
||||||||||||||
|
| Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Forum | Games | free backgrounds | Resume | Flash Animations | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | store | advertisers | . . |
||||||||||||||||