Fill part of the circle with color

Hi experts, i'm creating a fuel-like gauge. How do i fill part of the circle with color? I wanted to fill from 'E' till '1/2' is red color.

Attached is my codes.
import java.awt.*;
import javax.swing.*;
 
public class FuelGaugeDisplay extends JPanel 	
{
	int targetValue = 0;
	int value 		= 0;
	int degreesPerSecond = 1;
	Dimension Size;
	double gaugeWidth;
	double gaugeHeight;
	int    centerX = (int)(gaugeWidth/2.0);
	int    centerY = (int)(gaugeHeight/2.0);
	double zeroAngle = 225.0;
	double maxAngle  = -45; 
	double range = zeroAngle - maxAngle;
	
	public FuelGaugeDisplay (Dimension size) 
	{
		Size = size;
		gaugeWidth 	= Size.width  * 0.75;
		gaugeHeight = Size.height * 0.75;
		centerX = (int)(gaugeWidth/2.0);
		centerY = (int)(gaugeHeight/2.0);
		setSize(Size);
		setMaximumSize(Size);
		setPreferredSize(Size);
	}
	
	private void paintTheBackground( Graphics g) {
		g.setColor(Color.black);
		g.fillRect(0, 0, Size.width, Size.height);
		g.setColor(Color.black);
		g.fillOval(0, 0, (int)gaugeWidth, (int)gaugeHeight);
		// now the lines and the arcs on the gauge
		g.setColor( Color.lightGray);
		g.drawLine(centerX, centerY, (int) gaugeWidth -25, (int)gaugeHeight-25);
		g.drawLine(centerX, centerY, 23, (int)gaugeHeight-25);
		g.setColor( Color.white);
		g.drawArc( 10, 10, (int)gaugeWidth-20, (int)gaugeHeight-20, -45, 270);
		g.setColor( Color.red);
		g.drawString("E", centerX - 45, centerY + 55);
		g.setColor( Color.yellow);
		g.drawString("1/2", centerX - 5, centerY - 50);
		g.setColor( Color.green);
		g.drawString("F", centerX + 35, centerY + 55);
		
	}	
	
	public void paintComponent(Graphics g)
	{
		Color oldColor;
		oldColor = g.getColor();
		paintTheBackground( g);
 
		g.setColor(Color.orange);
		int x1 = centerX, 	
		    x2 = x1, 
		    y1 = centerY, 	
		    y2 = y1;
		double angleToUse = 360.0;
	    x2 += (int)( Math.cos(Math.toRadians(angleToUse))*centerX-10);
	    y2 -= (int)( Math.sin(Math.toRadians(angleToUse))*centerY-10);
		g.drawLine(x1, y1, x2, y2 );
		g.setColor(Color.white);
		g.drawString("FUEL", centerX - 10, centerY + 30);
		g.setColor(oldColor);
	}
	
	public static void main (String[] args)
	{
		JFrame f = new JFrame();
		JPanel panel = new FuelGaugeDisplay(new Dimension(200,200));
		f.setSize(200,200);
		f.add(panel);
		f.setVisible(true);
	}
	
 
}

Open in new window

selina3110Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bart CremersJava ArchitectCommented:
You can use g.fillArc for that:
        g.setColor(Color.RED);
        g.fillArc(10, 10, (int) gaugeWidth - 20, (int) gaugeHeight - 20,90,135);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
selina3110Author Commented:
Thanks! that's what im looking for
0
evil_lady_DiaCommented:
why not use jFreechart? They have gauges that are ready to use.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.