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

  • Home
  • SEARCH
  • 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 8638703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:48:16+00:00 2026-06-12T10:48:16+00:00

Hello I am using the Java Swing timer for a candle to let it

  • 0

Hello I am using the Java Swing timer for a candle to let it burn. everything works well except the end part when the candle is almost burned down to bottom. the timer should stop when the size is smaller then lets say 15.. Now I made some code and it seems that the if/else statement I made is beeing ignored completely.. Can someone tell me what I do wrong?

below you can see my code: ( p.s. the getCandleSize method now brings the length from 500 to 10 > 0 and then i get negative values )

package h04SelfBurnCandle;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import h02aKaars.DrawCandle;

public class CandlePanel extends JPanel implements ActionListener {

private boolean aan = true;
private int lengte = 500;
private int x;
private int y;
private int speed = 10;
private final int WACHTTIJD = 100; // wachttijd voor de timer

public CandlePanel() {

    javax.swing.Timer autoburn = new javax.swing.Timer(WACHTTIJD,this);

    autoburn.start();

}

DrawCandle candle = new DrawCandle();

@Override
public void paintComponent(Graphics g) {

    super.paintComponent(g);
    x = 10;
    y = getHeight() - (lengte + 10);

    for(int i=0; i < 5; i++) {

        if(lengte > 15){

        candle.drawCandle(g, x, y, lengte, aan);

        }
        else {

            candle.drawCandleBurned(g, x, y, lengte);

        }

        x = x + 70;

        System.out.println(lengte);

    }

}

public int getCandleSize() {

    do {
        lengte -= speed;
    }
    while(lengte > 15);

    return lengte;
}

@Override
public void actionPerformed(ActionEvent e) {

    getCandleSize();
    //System.out.println(lengte);
    repaint();

}

}
  • 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-12T10:48:17+00:00Added an answer on June 12, 2026 at 10:48 am

    When getCandleSize() gets called but it’s going to result in lengte being reduced instantly to 10. What you want is probably more like:

    public int getCandleSize() {
        if(lengte > 15)
            lengte -= speed;
        else
            autoburn.stop();
    
        return lengte;
    }
    

    Note: You will need to change autoburn from a local to a class member.

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

Sidebar

Related Questions

Hello, I am using Java Swing and I want to close a window on
new to Laravel (coming from Java spring), while using Route::get('/', function() { return Hello
Hello,I'd like to ask you two questions. (I am using java and jedis) I
I have a hello-world style java ee application using maven3 glassfish3 and javaee6. I
Hello I am trying to send a push message to my device using Java.
hello i have a basic client-server system running using java sockets. my problem is,
Hello I'm using this sample in Java to try to load OpenStreetMaps Offline tiles,
Hello I am writing a GUI application on Java 1.6 with Swing. I have
Hello I am having problems when using the Scala Swing library in version 2.8
I am from Java Swing background. May I know why using XML to create

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.