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 8471001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:40:33+00:00 2026-06-10T16:40:33+00:00

I am trying to animate a triangle when two triangles have been clicked twice.

  • 0

I am trying to animate a triangle when two triangles have been clicked twice. As soon as I click them twice triangle 0 starts moving until moveX reaches 20, while(moveX < 20), but then it doesn’t seem to reach a terminated state, it doesn’t go inside : if(t.getState() == Thread.State.TERMINATED), any ideas?

public class secondFrame extends JFrame implements Runnable {

}


public secondFrame(ChallengesDialog dialog) {

    component = new secFrameDrawComponent();
    createComponent();

    Thread t = new Thread(this);
    t.start();
}

private void createComponent() {

    sGen = new shapeGenerator(434, 231);

    createT();
}

class AddComponentListener implements MouseListener {

    public void mouseClicked(MouseEvent event) {


    for(int i = 0; i < count; i++) {
        if (component.getTri(i).contains(event.getX(), event.getY())) {
            component.setShapeFill("triangle", i);
            component.repaint();    

            countColors(i);

            setChallenge();
        }
...
MouseListener listener = new AddComponentListener();
component.addMouseListener(listener);                       

public void setChallenge() {

    //two red triangles
    if(challenge == 1 && triColorCount[1] == 2) {
        Thread t = new Thread(component);
        t.start();

        System.out.println("Thread's state: " + t.getState());

        if(t.getState() == Thread.State.TERMINATED) {
            //Unreachable
            System.out.println("Thread completed");
        }                   
    }
}
...

public void run() {

    while(threadFlag) { 
        ..
        timeLabel.setText("Elapsed time: " + elapsedTime);
        ..                      
    }
 }

public class secFrameDrawComponent extends JComponent implements Runnable {

    public void modTriangle(int x, int y) {

        sGen.setTriangleOffset(x, y);

        triangle[0] = sGen.getTriangle();
    }

    public void paintComponent(Graphics g) {

        Graphics2D g2 = (Graphics2D)g;

        draw(g2);       
    }

    public void run() {

        while(moveX < 20) {

            moveX+= 1;
            modTriangle(moveX, 0);
            repaint();

            try {
                Thread.sleep(170);
            } catch (InterruptedException e) {  
                e.printStackTrace();
            }
            System.out.println("moveX = " + moveX);
        }
        System.out.println("Thread completed exec");        
    }

    public void draw(Graphics2D g2) {

        g2.setStroke(new BasicStroke(2));

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);


        modTriangle(moveX, 0);
        g2.draw(triangle[0]);
        g2.draw(triangle[1]);
    }
  • 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-10T16:40:35+00:00Added an answer on June 10, 2026 at 4:40 pm

    Take a closer look at what you are doing. You start a new thread then immediately check if it’s terminated. Of course it won’t be, it takes a while until it’s done with the animation. If you want to wait until a thread finishes, use the join() function. Note however, that will block the calling thread until the the thread you are “joining” has finished.

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

Sidebar

Related Questions

I'm trying to animate object. I use keyframe animation: I have two vertex buffers
I am trying to animate the dealing of cards. Currently I have two cards,
I'm trying to animate the div within an list item with a click event
I am trying to animate the blinking between two images on an imageview to
I am trying to animate a div moving 200px horizontally in JavaScript. The code
I am trying to animate a div when the user click the button. Each
I am trying to animate the Fill property of a path. What I have
I'm trying to animate a triangle around a given point. I want the shape
Im trying to animate one elment after another, but I have some troubles with
i'm trying to animate an object in several steps across the screen until it

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.