Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:36:57+00:00 2026-06-13T09:36:57+00:00

I am trying to learn 2D graphics. This code below draws a couple of

  • 0

I am trying to learn 2D graphics. This code below draws a couple of spinning wheels. To get them to refresh, I finally inserted the repaint(1000) in the paint method, but I know that this paints at times when it does not have to.

    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;

        for(int angle=0; angle<360; angle+=90){
            g2.setColor(blue);
            g2.fillArc(100,100,200,200,theta1 + angle,45);
            g2.setColor(red);
            g2.fillArc(100,100,200,200,theta1 + angle + 45,45);
        }

        for(int angle=0; angle<360; angle+=30){
            g2.setColor(green);
            g2.fillArc(250,250,250,250,angle + theta2,15);
            g2.setColor(yellow);
            g2.fillArc(250,250,250,250,angle + theta2 + 15,15);
        }

//        repaint(1000);
   }

    public static void main(String s[]) {
        JFrame f = new JFrame("ShapesDemo2D");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        JApplet applet = new ShapesDemo2D();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
        f.setSize(new Dimension(800,800));
        f.setVisible(true);

        while(true) {
            theta2 += 5;
            theta1 -= 2;

            f.repaint(1000);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }

What I would really like to do is have it refresh after I have made a change. Main has a reference to paint since it created the applet, but the f.repaint() does not appear to do anything. (If I comment out the repaint() in paint, it does not update). What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:36:58+00:00Added an answer on June 13, 2026 at 9:36 am

    It would be to your advantage to have a read through

    • Concurrency in Swing
    • Performing Custom Painting
    • Painting in AWT and Swing
    • How to Use Swing Timers

    I would also have a look at

    • Java Bouncing Ball
    • Java Code for Simple Animation only runs on Windows
    • the images are not loading

    Which all show animation principles and custom graphics in Swing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn pointer math better I wrote this code. The intention was to
Trying to learn a bit about PDO and is going through this tutorial .
Im trying to learn Android graphics & event handeling for a multiplayer game. As
I'm trying to learn some graphics programming using C. What would be the best
trying to learn and practice arrays but I have a problem with this small
I'm trying to learn 3d graphics programming through Learning Modern 3D Graphics Programming by
I am trying to learn XML and I know this is a problem with
I was looking at some Cappuccino code (trying learn a little bit of it)
I am trying to write a code to generate a graph like this: http://www.mathgoodies.com/lessons/graphs/images/line_example1.jpg
I'm trying to learn Java from this book The Art and Science of Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.