0

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.

0

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

0

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

0

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.

0

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

0

hi norm,

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

0

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

0

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.

0

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?

0

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.

0

Hi norm,

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

0

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.

0

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.

0

hi norm,

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

0

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.

0

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.

0

hi norm,

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

0

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?

0

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.

0

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.

0

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.

0

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.

0

hi norm,

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

0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.