Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 475 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
FloodFill method in Java

Hi,
Somebody please guide me whether there is any floodfill method in java? I have made a polygon using g.drawLine(...). Now i want to fill that polygon.
Color greenColor= new Color(0, 255, 0);
g.drawLine(0,250,250,250);
//g.drawLine(250,250,280,479);
g.drawLine(250,250,280,479);
//g.drawLine(280,479,0,479);
g.drawLine(280,479,0,479);
//g.drawLine(0,479,0,250)
g.drawLine(0,479,0,250);
In Visual C++, I was doing it:
pDC->FloodFill(30,270,RGB(0,255,0));
Somebody please tell me about the replacement of this command in JAVA.
Zulfi.
Best Answer
-
Hi,
Thanks for your guidance. It worked.
Color greenColor= new Color(0, 255, 0);
g.setColor(greenColor);
/*g.drawLine(0,250,250,250);
//g.drawLine(250,250,280,479);
g.drawLine(250,250,280,479);
//g.drawLine(280,479,0,479);
g.drawLine(280,479,0,479);
//g.drawLine(0,479,0,250)
g.drawLine(0,479,0,250);*/
int xpoints[] = {0, 250, 280, 0, 0};
int ypoints[] = {250, 250, 479, 479, 250};
int npoints = 5;
g.fillPolygon(xpoints, ypoints, npoints);
Zulfi.
Answers
-
In java we don't need FloodFill.
You could have looked up the Type of g in the public Java API. There you could have found the fill(Shape) method which does your requirement in one step.
bye
TPD
-
Hi,
Thanks for your guidance. It worked.
Color greenColor= new Color(0, 255, 0);
g.setColor(greenColor);
/*g.drawLine(0,250,250,250);
//g.drawLine(250,250,280,479);
g.drawLine(250,250,280,479);
//g.drawLine(280,479,0,479);
g.drawLine(280,479,0,479);
//g.drawLine(0,479,0,250)
g.drawLine(0,479,0,250);*/
int xpoints[] = {0, 250, 280, 0, 0};
int ypoints[] = {250, 250, 479, 479, 250};
int npoints = 5;
g.fillPolygon(xpoints, ypoints, npoints);
Zulfi.
-
As I already mentioned in my reply to your other thread I suggest you go through The Java Tutorials trail for 'Getting Started with Graphics'.
It shows you, with WORKING code, how to draw and fill in Java.
https://docs.oracle.com/javase/tutorial/2d/basic2d/
Lesson: Getting Started with Graphics
The Java 2D API is powerful and complex. However, the vast majority of uses for the Java 2D API utilize a small subset of its capabilities encapsulated in the
java.awt.Graphics
class. This lesson covers the most common needs of applications developers. Less common needs are described later in the Advanced topics in the Java 2D API. Most methods of theGraphics
class can be divided into two basic groups: Draw and fill methods, enabling you to render basic shapes, text, and images Attributes setting methods, which affect how that drawing and filling appears Methods such assetFont
andsetColor
define how draw and fill methods render.There are MANY such tutorials on the web that will make it much easier to learn how to use the graphics functionality.