| Start |
|---|
| Example 1: Draw and Fill a Rectangle Using Java This is an Example which print rectangle and fill color in the rectangle.
https://i.stack.imgur.com/dlC5v.jpg (opens new window) Most methods of the Graphics class can be divided into two basic groups:
Code Example: Let us start this with a little example of drawing a rectangle and filling color in it. There we declare two classes, one class is MyPanel and other Class is Test. In class MyPanel we use drawRect( ) & fillRect( ) mathods to draw rectangle and fill Color in it. We set the color by setColor(Color.blue) method. In Second Class we Test our graphic which is Test Class we make a Frame and put MyPanel with p=new MyPanel() object in it.By running Test Class we see a Rectangle and a Blue Color Filled Rectangle. First Class: MyPanel Second Class: Test For More Explanation about Border Layout: https://docs.oracle.com/javase/tutorial/uiswing/layout/border.html (opens new window) paintComponent( )
Graphic2D refers Graphic2D Class Note: The Java 2D API enables you to easily perform the following tasks:
|
Example 2: Drawing and Filling Oval g2.drawOval(int x,int y,int height, int width); g2.fillOval(int x,int y,int height, int width); This method will fill an oval at specified x and y position with given height and width. |
Read Article
https://develop.horje.com/learn/1434/reference