# Write applet program that draw a line

An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. A main method is not invoked on an applet, and an applet class will not define main. Applets are designed to be embedded within an HTML page.  Write an applet that draws a checkerboard. Assume that the size of the applet is by pixels. Each square in the checkerboard is 20 by 20 pixels. The checkerboard contains 8 rows of squares and 8 columns.

The squares are red and black. Here is a tricky way to determine whether a given square is red or black: If the row number and the column number are either both even or both odd, then the square is red.

Otherwise, it is black. Note that a square is just a rectangle in which the height is equal to the width, so you can use the subroutine g. Here is an image of the checkerboard: To run an applet, you need a Web page to display it.

A very simple page will do. Assume that your applet class is called Checkerboard, so that when you compile it you get a class file named Checkerboard.

This is the source code for a simple Web page that shows nothing but your applet. You can open the file in a Web browser or with Sun's appletviewer program. The compiled class file, Checkerboard.

## Applets Mini Project in Java: Animated Moving Car Program

Discussion The basic algorithm is obvious: Draw all the squares in that row Since any given row contains eight squares, one in each column of the checkerboard, we can expand the body of the for loop into another for loop: Draw the square in that row and column Each square is a rectangle with height 20 and width 20, so it can be drawn with the command g.

Before drawing the square, we have to determine whether it should be red or black, and we have to set the correct color with g. So, the algorithm becomes for each row on the checkerboard: Compute x,y for the top-left corner of the square if its a red square: If we assume that the rows are numbered 0, 1, 2, If you number the rows 1, 2, The simpler formula in this and in many similar cases is one reason why computer scientists like to start counting with 0 instead of 1.

The 8 reminds me that I am counting off the eight numbers 0, 1, 2, Again, this is typical computer science style. The only problem remaining is how to determine whether the square is red.

As noted in the exercise, a square is red if row and col are either both even or both odd. Then, the code goes into the body of the paint method of an applet. The syntax of the applet definition must follow the format given in Section 3. The Solution import java. It is assumed that the size of the applet is by pixels.An Applet is a special type of program that is embedded in the webpage to generate the dynamic content and that runs inside the browser and works at the client side.

## Lesson: Getting Started with Graphics (The Java™ Tutorials > 2D Graphics)

The user launches the Java Applet from a web page. write in the command prompt: javac ph-vs.com applet */ Output 6. Draw a line. In this example, we draw a simple ph-vs.com For example, to draw a line, an application calls the following: ph-vs.comne(int x1, int y1, int x2, int y2) In this code (x1, y1) is the start point of the line, and (x2, y2) is the end point of the ph-vs.com://ph-vs.com In Java, write a bunch of classes that will draw a bunch of lines!

Don’t worry you don’t have to write any graphics, as that part is provided in the driver. Each line is drawn based on a math function that takes in a given x coordinate and will return its y ph-vs.com://ph-vs.com  · Many Java applets perform animation, whether it's the classic, cartoon-style animation of Duke waving, program-generated lines such as flowing sine waves, or simply moving static images across the screen.

No comprehensive, direct-manipulation tools exist (yet) for creating Java animations. So it's up to the applet programmer to do all the hard ph-vs.com://ph-vs.com /ph-vs.com Java Applet to Draw Circle or Rectangle Hi,, Just started in Java and I have to code a Java Applet that displays 2 buttons one to draw a circle and the other to draw .

Easy Tutor author of An applet program to draw different shapes is from United ph-vs.com Tutor says. Hello Friends, I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework.

I also guide them in doing their final year projects.

Draw Oval & Circle in Applet Window Example