1

I would like to create a JSpinner that cycles through the overs in a cricket match.

So the values should go:

0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
2.1, 2.2, 2.3, 2.4, 2.5, 2.6 etc.

SpinnerNumberModel will only allow me to have a regular step of 0.1 which means I have to include 0.7, 0.8, 0.9, 1.0 etc.

So I want to create my own SpinnerModel which dishes out this sequence. I think i've got the previous and next values sorted:

@Override
public Object getNextValue() {
    if( (Double)getValue() == ((numOvers-1) + 0.6) ){
        return null;
    }else if((Double)getValue() % 1 == 0.6){
        return (Double)getValue() + 0.5;
    }else{
        return (Double)getValue() + 0.1;
    }
}

@Override
public Object getPreviousValue() {
    if( (Double)getValue() == 0.1 ){
        return null;
    }else if((Double)getValue() % 1 == 0.1){
        return (Double)getValue() - 0.5;
    }else{
        return (Double)getValue() - 0.1;
    }
}

But I can't work out how I actually set the value in the first place.. (I have to implement getValue() and setValue() as well don't I?)

4

0 に答える 0