2

I think I'll just start with the code that's giving me the problem.

class AnimationPanel extends JPanel
{   
    OfficeLoad load;
    Timer timer = new Timer();

    private static final long serialVersionUID = 1L;
    public AnimationPanel()
    {
        setBackground(new Color(240, 240, 240));
        setBorder(null);
        setOpaque(false);
        setBounds(10, 143, 400, 21);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        load  = new OfficeLoad(g);
    }
    ...
    }

...

final Color WHITE = Color.WHITE;
public OfficeLoad(Graphics g)
{
    Graphics2D g2 = (Graphics2D)g.create();

    g2.setPaint(WHITE);
    g2.fill(new Ellipse2D.Double(30, 1, 5, 5));
    g.fillOval(40, 1, 5, 5);
    g.fillOval(50, 1, 5, 5);
    g.fillOval(60, 1, 5, 5);
    g.fillOval(70, 1, 5, 5);
    g.setColor(new Color(0, 102, 51));
    g.fillRect(0, 0, 10, 21);
}

Both when I use g.fillOval() and when I use g2.fill(new Ellipse2D()) it turns out as a square. Just for some extra information, I'm, just for fun of course, trying to replicate the excel 2013 splash screen when it's starting up. This part is for the loading dots underneath the "Excel". I already made it with a gif, which was much easier, but my friend challenged me to use the paint, repaint, and so forth. But I can't really do that, unless they turn up as circles rather than squares... Any help would be appreciated. :)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Ethan Brouwer
  • 975
  • 9
  • 32
  • 3
    Does it work when you enable antialiasing with `g2.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);`? – halex Apr 03 '13 at 11:13

2 Answers2

2

Thank you Halex! :D For everyone that didn't look at his comment, Halex gave this following answer.

Does it work when you enable antialiasing with g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

It did. Thanks! :D

Community
  • 1
  • 1
Ethan Brouwer
  • 975
  • 9
  • 32
  • For nicer circles and other ellipses, you might want to also `g.setRenderingHint( RenderingHints. KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE)`, see http://stackoverflow.com/a/31221395/1143274 – Evgeni Sergeev Jul 05 '15 at 02:17
1

First of all I advice to not make a new OfficeLoad object everytime you paint you can either save the officeload object or make a static void in the OfficeLoad so you don't need the object at all.

also you will need antialiassing

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Daan Luttik
  • 2,781
  • 2
  • 24
  • 37
  • I'm not making a new object. The new object at the beginning is just to set it up, and then there is another method that I left out that is part of OfficeLoad called paintLoad that repaints the objects. The timers will be taken care of in the AnimationPanel though. – Ethan Brouwer Apr 03 '13 at 11:34
  • 1
    You make a new OfficeLoad object every time paintComponent is called this happens not only if you call a repaint but also if for instance your JFrame is moved or the bounds are changed. If you want to do it only at initialization move the line from paintComponent to the constructor. – Daan Luttik Apr 03 '13 at 11:36
  • Good Point. Thanks for that. :) – Ethan Brouwer Apr 03 '13 at 11:47