Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem with Replacing the Integer Value

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Thanked 0 Times in 0 Posts

    Question Problem with Replacing the Integer Value

    Hello good day everyone!

    I have a problem with this game I found in the internet. I want to makethis game a little bit better by adding some features.

    So my problem is when im changing the value of the delay to "3" it wont change.

    Because the lower the delay value, the faster the ball go in the game. So I want it to change when the totalBricks <= 25.

    This is the code.

    public class Gameplay extends JPanel implements KeyListener, ActionListener{
    private boolean play = false;
    private int score = 0;
    public int totalBricks = 30;
    public Timer timer;
    public int delay = 7;
    private int playerX = 310;
    private int ballposX = 120;
    private int ballposY = 350;
    private int ballXdir = -1;
    private int ballYdir = -2;
    private Maps map;
    public Gameplay() {
        map = new Maps(3, 10);
        timer = new Timer(delay, this);
                if(totalBricks <= 25){
                    delay = 3;

    As you can see, in the public gameplay section. I wrote "if(totalBricks <= 25){ delay = 3; }.

    But still its not working.

    If you have any other questions, please do not hesitate to ask me.

    Thanks advance and God Bless!!!!!
    Last edited by tmxstar; October 21st, 2018 at 03:24 AM. Reason: Typo

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,429 Times in 2,380 Posts

    Default Re: Problem with Replacing the Integer Value

    its not working
    Please explain.

    The code to set delay's value is in the constructor which means it is only executed when the constructor is executed.
    If totalBricks is changed anywhere else in the code then the if test you have added needs to be where totalBricks' value is changed.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Problem with String (and integer) conversion!
    By tonynsx in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 7th, 2013, 01:44 PM
  2. Problem with replacing substring in a file
    By justyStepi in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 7th, 2013, 03:36 PM
  3. Integer.parseInt problem
    By 3therk1ll in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 28th, 2013, 05:28 AM
  4. HELP: I have problem casting from Vector to Integer in Java
    By tintin in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 17th, 2011, 12:39 PM
  5. Hex to Integer Problem
    By TempSpectre in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2010, 06:01 AM

Tags for this Thread