hi norm,

i tried to set it up back at the paint component. but now the problem is that the delay(3000) seem being ignored and instead the program just proceed with delay(moveDelay) which is the restore of normal movement. thanks.

Don't do it in the paint method. That method should only follow instructions from other methods. Do it in the action listener method.

my logic after repaint, it will call the super paint component g to redo everything and here i set the delay() as normal movement delay. but as above mentioned, the program ignoring the delay(3000).thanks

hi norm,

would you like to see this code :

public Elevator(Elevator_Simulation app) {
        //necessary initialization        

        dy0 = 2;
        up = true;
        firsttime = true;
        loading = false;
        this.app = app;

        //declare the timer
        tm = new Timer(moveTime, this);
        tm.setDelay(moveTime); // this is the delay(moveDelay)
        //start the timer
        tm.start();
    }

this is one of method that having action listener. but when i compile, its moving at still delaying speed but not normal speed.

which that public elevator is the constructor. thanks.

After the loading is completed, you need to set the delay time to that for normal movement.

hi norm,

but the loading boolean is in actionPerformed method not actionlistener. Thanks.

The actionPerformed method is in the ActionListener interface. Those two words sort of refer to the same thing.

hi norm,

how to make the loading complete first?isnt it the same as setting up a new delay?wont it end up the same that will make the elevator moves even slower.

If after finishing loading, you set the delay to MoveTime then the elevator will resume the normal movement speed. The timer will call the action listener method every MoveTime millisecs and that method will change the y position and call repaint which will call paint which will paint the elevator at the new position. MoveTime millisecs later it will happen again and again and again. The elevator will move every MoveTime millisecs.
How does make the elevator move even slower?

hi norm ,

thanks.i already solved the issue already. i think now i will try to implement a slider on the right panel to move according to jSlider. Any feedback on this?thanks.

Glad you got it working.
Good luck on the next part of the project.

Hi norm,

might need your advise in future. thanks.

Hi norm,

How to make the JSlider move according to the speed?need your advise on this.thanks.

Have you read the API doc for the JSlider class? It has a link to a tutorial on how to use Sliders. Read the tutorial and work with the examples given there.

hi norm,

how come when i try to get the value of slider by using system.out.print(), it does not give me a value.does that mean when i slide the slider, it does not have any value?thanks.

Please show your code. I have no idea why you are having a problem.

hi norm,

my bad..i forgot to add the listener to the slider..thats caused it to not showing any reaction. thanks.

hi norm,

in my previous codes, the elevator will keep moving up and down when touching top or bottom floor.

the question is, how do i set it so when 2 buttons are pressed( example floor 2 and floor 5) when elevator reached floor 2, it will go to floor 5 instead of moving down.

need your feedback on the logic.

You need to add logic to determine which way to go after the elevator has stopped. Look at all the "call" buttons and see if any are set and in which direction. Then set the movement direction flag accordingly.

hi norm,

how to see the direction because it will only know how to go up and down (looping)

how to see the direction because it will only know how to go up and down

I thought that the elevator could only go up or down. Are you suggesting it can go in other directions?

hi norm,

yes..it can only go up or down. how to detect that if there are 2 floors pressed, it will detect it and go to that specific floor instead of going up / down first.thanks for the feedback.

Some other things to think about as your model progresses:
When a person enters an elevator he should be able to choose which floor he wants to stop at.
Also some elevators have separate call buttons for going up and for going down.

hi norm,

can elaborate more?hmm..is it the logic for making it know which floor it pressed and go to that specific floor?thanks.

Perhaps you should go to a building that has an elevator and see what buttons an elevator has if you are unfamiliar with how they work.

hi norm,

i figured the logic already. but unsure of the code parts.mind take a look?

When adding features to a program, add them one at a time, test that it works before adding the next one. Take small simple steps will keep the project from getting too confusing.

hi norm,

yep.this is the last part of the puzzle. just need some advice on this part of codes.

if ((app.control.bp[curFloor] == true) && (yco % height == 0)) {

            String line0 = ("Elevator is picking up passenger at floor " +
                    app.control.b[curFloor].getActionCommand().substring(1));
            app.state.setText(line0);      
            stop();
            tm = new Timer(this.drag, this);
            tm.setInitialDelay(this.delay);
            tm.setDelay(this.drag);
            start();
            app.control.bp[curFloor] = false;
            app.control.b[curFloor].setBackground(Color.cyan);

            for(int i = curFloor; i <= 7; i++) {
                if(app.control.bp[i] == false) {
                    System.out.println("go up");
                }
            }
        }

logic for for loop is to check all the buttons pressed and when it finds it, go to that floor.

Sorry, your small piece of code without the full picture is useless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.