- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to fill colors in shapes using Applet in Java
Problem Description
How to fill colors in shapes using Applet?
Solution
Following example demonstrates how to create an applet which will have fill color in a rectangle using setColor(), fillRect() methods of Graphics class to fill color in a Rectangle.
import java.applet.*; import java.awt.*; public class fillColor extends Applet { public void paint(Graphics g) { g.drawRect(300,150,200,100); g.setColor(Color.yellow); g.fillRect( 300,150, 200, 100 ); g.setColor(Color.magenta); g.drawString("Rectangle",500,150); } }
Result
The above code sample will produce the following result in a java enabled web browser.
A Rectangle with yellow color filled in it will be drawn in the browser.
java_applets.htm
Advertisements