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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:59:32+00:00 2026-06-05T20:59:32+00:00

Can I make a slider control in LWUIT, that mean a bar that can

  • 0

Can I make a slider control in LWUIT, that mean a bar that can user move to control some value ?

please if anyone can help by example or tutorial I will be appreciated

  • 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-05T20:59:34+00:00Added an answer on June 5, 2026 at 8:59 pm

    i have done this with motion component
    and which i will provide you

    public MotionComponent(final Image background, final Image button,
                final int x, final int minX, final int maxX, final boolean
                useStops, final int numStops, final int time) {
            this.background = background;
            this.button = button;
            this.minX = minX;
            this.maxX = maxX;
            this.useStops = useStops;
            this.numStops = numStops;
            this.time = time;
            positionX = (maxX - minX) / 2;
            this.moveToPoint = this.minX;
    
            this.getStyle().setBgTransparency(0);
    
            if (this.maxX < this.minX) {
                int tmp = this.minX;
                this.minX = this.maxX;
                this.maxX = tmp;
            }
    
            if (button != null) {
                this.maxX += (button.getWidth() / 2);
                this.minX += (button.getWidth() / 2);
            }
        }
    
        public void setStepSize(int step) {
            this.stepSize = step;
        }
    
        public int getStepSize() {
            return stepSize;
        }
    
    
    
        protected Dimension calcPreferredSize() {
            //Style style = getStyle();
            Dimension dimension = null;
            dimension = new Dimension(background.getWidth(), 36);
    
            return dimension;
        }
    
        public void initComponent() {
            getComponentForm().registerAnimated(this);
        }
    
        public void paint(Graphics g) {
    
    
            if (background != null) {
                g.drawImage(background, getX(), 
                        (getHeight() - background.getHeight()) / 2);
            }
            if (button != null) {
                g.drawImage(button, positionX + button.getWidth()/2,
                        (getHeight() - button.getHeight()) / 2);
            }
    
        }
    
        public void keyPressed(int keyCode) {
            super.keyPressed(keyCode);
            switch (Display.getInstance().getGameAction(keyCode)) {
            case Display.GAME_DOWN:
            case Display.GAME_UP:
                break;
            case Display.GAME_LEFT:
            case Display.GAME_RIGHT:
                if (useStops && motionX == null) {
                    System.out.println("key pressed motion");
                    motionX = Motion.createSplineMotion(positionX,
                            getDestPoint(positionX, numStops, minX, maxX,
                                    Display.getInstance().getGameAction(keyCode)), time);
                    motionX.start();
                } else {
                    if (motionX == null) {
                        motionX = Motion.createSplineMotion(positionX,
                                moveStep(positionX, stepSize,
                                        Display.getInstance().getGameAction(keyCode), minX, maxX), time);
                        motionX.start();
                    }
                }
                System.out.println("key pressed");
                break;
            default:
                System.out.println("key default");
                return;
            }
        }
    
        public void keyRepeated(int keyCode) {
            super.keyRepeated(keyCode);
            switch (Display.getInstance().getGameAction(keyCode)) {
            case Display.GAME_DOWN:
            case Display.GAME_UP:
                break;
            case Display.GAME_LEFT:
            case Display.GAME_RIGHT:
                if (useStops && motionX == null) {
                    motionX = Motion.createSplineMotion(positionX,
                            getDestPoint(positionX, numStops, minX, maxX,
                                    Display.getInstance().getGameAction(keyCode)), time);
                    motionX.start();
                }
                System.out.println("key Repeated");
                break;
            default:
                return;
            }
        }
    
        private int moveStep(int x, int stepSize, int keyCode, int min, int
                max) {
            if (keyCode == Display.GAME_LEFT) {
                if (x > min) {
                    if (x - stepSize < min) {
                        return min;
                    } else {
                        return x - stepSize;
                    }
                } else {
                    return min;
                }
            } else {
                if (x < max) {
                    if (x + stepSize > max) {
                        return max;
                    } else {
                        return x + stepSize;
                    }
                } else {
                    return max;
                }
            }
        }
    
        /**
         * returns a normalized value
         * @return
         */
         public float getValue() {
            return ((positionX - minX) / (maxX - minX));
        }
    
        public void pointerPressed(int x, int y) {
            Rectangle absoluteBounds  = new Rectangle(getAbsoluteX(), getAbsoluteY(), getBounds().getSize());
            if (absoluteBounds.contains(x, y)) {
                System.out.println("pointerPressed " + x + " y " + y);
                if (x != positionX) {
                    if (motionX == null) {
                        if (x < minX) {
                            motionX = Motion.createSplineMotion(positionX,
                                    minX, time);
                        } else if (x > maxX) {
                            motionX = Motion.createSplineMotion(positionX,
                                    maxX, time);
                        } else {
                            motionX = Motion.createSplineMotion(positionX, x,
                                    time);
                        }
                        motionX.start();
                    } else {
                        // do what?
                    }
                }
            }else{
                System.out.println("pointerPressed pointerPressed else " + x + " y " + y);
                System.out.println("getBounds() x " + getBounds().getX() + ", y " + getBounds().getY() + ", w " + getBounds().getSize().getWidth() + ", h " + getBounds().getSize().getHeight());
            }
        }
        int draggedX, draggedY;
    
        public void pointerDragged(int x, int y) {
            Rectangle absoluteBounds  = new Rectangle(getAbsoluteX(), getAbsoluteY(), getBounds().getSize());
            if (absoluteBounds.contains(x, y)) {
                System.out.println("pointerDragged " + x + " y " + y);
                draggedX = x;
                draggedY = y;
                if (motionX != null) {
                    //motionX.getValue()
                } else {
                    positionX = x;
    
                    if (positionX < minX) {
                        positionX = minX;
                    }
    
                    if (positionX > maxX) {
                        positionX = maxX;
                    }
                }
            } else {
                System.out.println("pointerDragged " + x + " y " + y);
                System.out.println("pointerReleased ");
                //when it exits bounds, call pointerReleased with the last
                pointerReleased(draggedX, draggedY);
            }
        }
    
        private int getDestPoint(int x, int numStops, int min, int max, int
                direction) {
            if (numStops < 2) {
                if (direction == Display.GAME_LEFT) {
                    return min;
                } else {
                    return max;
                }
            }
            int distance = (max - min) / (numStops - 1);
    
            if (direction == Display.GAME_LEFT) {
                return moveToStopPoint(x - distance, numStops, min, max);
            } else {
                return moveToStopPoint(x + distance, numStops, min, max);
            }
        }
    
        private int moveToStopPoint(int x, int numStops, int min, int max) {
            int distance = max - min;
    
            // will either go to min or max.
            if (numStops < 2) {
                if (x > min + (distance / 2)) {
                    return max;
                } else {
                    return min;
                }
            }
            float averageDistance = distance / (numStops - 1); // 5 stops,
    
            if (x > max) {
                return max;
            }
    
            if (x > min && x <= (min + (int) (averageDistance / 2))) {
                return min;
            } else if (x < max && x >= (max - (int) (averageDistance / 2))) {
                return max;
            } else {
                for (int i = 0; i < numStops; i++) {
                    int currentMin = min + (int) (i * averageDistance);
                    if (x >= currentMin && x < currentMin + (int)
                            averageDistance / 2) {
                        return currentMin;
                    } else if (x >= currentMin + (int) averageDistance / 2 &&
                            x < currentMin + (int) averageDistance) {
                        return currentMin + (int) averageDistance;
                    }
                }
            }
            return min;
        }
    
        public void pointerReleased(int x, int y) {
            Rectangle absoluteBounds  = new Rectangle(getAbsoluteX(), getAbsoluteY(), getBounds().getSize());
            if (absoluteBounds.contains(x, y)) {
                System.out.println("pointerReleased " + x + " y " + y);
                if (useStops) {
                    if (x > maxX) {
                        x = maxX;
                    }
                    if (x < minX) {
                        x = minX;
                    }
    
                    if (motionX != null) {
                        motionX =
                            Motion.createSplineMotion(motionX.getValue(),
                                    moveToStopPoint(motionX.getValue(), numStops, minX, maxX), time);
                    } else {
                        motionX = Motion.createSplineMotion(x,
                                moveToStopPoint(x, numStops, minX, maxX), time);
                    }
                    motionX.start();
                }
            } else {
                // outside bounds. Should be caught previously with
            }
        }
    
        public boolean animate() {
            boolean val = false;
            if (motionX != null) {
                positionX = motionX.getValue();
                if (motionX.isFinished()) {
                    motionX = null;
                }
                val = true;
            }
            return val;
        }
    }
    

    the out put of the above code is this and i think this is want you are searching. User can move the button left and right
    Pranav

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

Sidebar

Related Questions

How can I make a nice view slider (that is following the motion of
Well im trying to make my own basic Slider control just so i can
How can I make the slider track a bit thicker with CSS ?
How can i make sure that several divs are slided up? Right now I
How can make a link within a facebox window that redirects it to another
I can make a variable's name from two variables' value: $a = 'tea'; $b
I can make a log in for easily, so that's not the problem. What
I know you can make the slider go vertical, but is there a way
How can I make the slider stop playing once it reaches the final slide?
I am trying to make a CPTableColumn that can change values without having to

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.