Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

slider help required(java)

Options
  • 21-04-2004 8:00am
    #1
    Closed Accounts Posts: 1,723 ✭✭✭


    Lads/Lassies,

    I'm in need of some quick help. Basically i have to hand in a final assignment within 5 hours and i am stuck on one thing.

    Basically I need to implement a button in the bottom left hand corner(like windows), and then have a slider adjacent to it(like windows except the taskbar is a slider).

    Now i implemented the button and it basically was the length of the whole "taskbar", then i implemented the slider and this overwrote the button and now the slider is the whole length of the "taskbar".

    Please find the code below and if anybody can tell me what i have done wrong\left out ,it would be very much appreciated.




    public static final int FrameWidth = 500;
    public static final int FrameHeight = 300;

    private int angle = 45;
    private String message = "Angle: " + angle;
    private PinBall PinBall = null;
    private Scrollbar slider = null;


    public static void main( String[] args ) {
    PinWorld cw = new PinWorld();
    cw.setSize(FrameWidth, FrameHeight);
    cw.show();
    }


    PinWorld()
    {
    setLayout(new BorderLayout());

    Button fire = new Button("fire");
    fire.addActionListener(new FireButtonListener());
    add ("South", fire);

    slider = new Scrollbar(Scrollbar.HORIZONTAL, angle, 5, 0, 90);
    slider.addAdjustmentListener(new PinSliderListener());
    add ("South", slider);
    pack();

    slider = new Scrollbar(Scrollbar.VERTICAL, angle, 5, 0, 90);
    slider.addAdjustmentListener(new PinSliderListener());
    add ("West", slider);
    pack();
    }


    private class FireButtonListener implements ActionListener
    {
    public void actionPerformed (ActionEvent e)
    {
    double radianAngle = angle * Math.PI / 180.0;
    double sinAngle = Math.sin(radianAngle);
    double cosAngle = Math.cos(radianAngle);



    I should add that the 'Vertical' Slider is for controlling the angle/direction of the ball and the 'horizontal' slider is for controlling the power/force behind the released ball.
    Its the horizontalslider/button thats causing me problems.

    Again any help appreciated


Comments

  • Closed Accounts Posts: 1,723 ✭✭✭empirix


    bump


    Anybody have any feedback!


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    If the problem is just that they are "overwriting" each other on the screen the change the layout and put them in a grid layout or some such. Also might help to add them to their own JPanels and then put them in the main frame.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    yeah, you are just adding them south.

    Set up a grid layout then add them at the co-ords

    so psuedo code would be

    add(button, 2,1)
    add(slider 2,2)

    sorry I cant write the actual code but Im swamped in work at the minute


  • Closed Accounts Posts: 1,723 ✭✭✭empirix


    cheers - will put me on the right track- just hope i can get it done in time


Advertisement