How To Draw A Rectangle Java
Answer:
drawOval( 100-50, 300-l, 2*50, 2*50 )
Of course the method would work if you lot did the arithmetic and put the results in the method call.
Drawing Rectangles
import java.swing.JApplet; import java.awt.*; // assume that the drawing expanse is 150 past 150 public grade SquareAndRectangle extends JApplet { final int areaSide = 150 ; final int width = 100, elevation = l; public void paint ( Graphics gr ) { gr.setColor( Colour.white ); gr.fillRect( 0, 0, 150, 150 ); gr.setColor( Colour.blue ); // outline the cartoon area gr.drawRect( 0, 0, areaSide-1, areaSide-1 ); // draw interior rectangle. gr.drawRect( areaSide/2 - width/2 , areaSide/2 - superlative/two, width, tiptop ); } }
To draw a rectangle, use the drawRect()
method of a Graphics object. This method looks like:
drawRect(int 10, int y, int width, int height)
It draws the outline of a rectangle using the current pen colour. The left and right edges of the rectangle are at ten and x + width respectively. The top and bottom edges of the rectangle are at y and y + height respectively.
This method is also used to describe a square. This applet draws a rectangle effectually the unabridged drawing area, and then puts some other rectangle in the eye.
Here is what it draws on your screen:
In drawing the outer square, the value 1 was subtracted from its width and height so that the edges would exist within the drawing expanse.
Source: https://chortle.ccsu.edu/java5/notes/chap36/ch36_7.html
Posted by: moultrieheadee.blogspot.com
0 Response to "How To Draw A Rectangle Java"
Post a Comment