Reputation: 67
For my project, I am trying to create a circular progress bar to show how many points the user has. I currently have the following code to create the circle.
public void Paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
g2.translate(80, 80);
g2.rotate(Math.toRadians(270));
Arc2D arc = new Arc2D.Float(Arc2D.PIE);
arc.setFrameFromCenter(new Point(0, 0), new Point(80, 80));
arc.setAngleStart(1);
arc.setAngleExtent(-totalPoints*3.6);
g2.setColor(Color.red);
g2.draw(arc);
g2.fill(arc);
}
I am also trying to create it from another file. Should I create a JPanel or can I add it to a label? Also if I use a panel how can I add it using code?
I am using gridbag to set locations and I am not using the drag and drop function to create the JFrame and JPanels that Netbeans has.
Upvotes: 0
Views: 389
Reputation: 7267
I'm assuming that you're creating a custom component, something like this:
public class CircleProgress extends JComponent {
In which case to use this in another Swing class, you'd treat it as any other Component
, for example:
CircleProgress progress = new CircleProgress();
...
Panel p = new Panel();
p.setLayout(new BorderLayout());
p.add(progress, BorderLayout.CENTER);
It would be strange to add it to a Label
, rather than a Panel
.
Upvotes: 1