Originally Posted by
Suic
yes indeed, drawInterface() is what draws the interface and all it's components/children, but there should be a instance for each slider, think about it if i have 2 interfaces that use the slider components, they would share the same properties(minValue, maxValue, defaultValue, sprites) and the current value of the slider itself, which would be a problem because i'd want to use the slider for different things, eg interface 1 uses it to control brightness of the client and the other uses it to control the music volume of the client, if it was 1 instance, they both would share the same value in which case changing one of the sliders would affect the value of all sliders.
edit: by patching i meant modifying the fields directly outside the constructor/an instance method
interesting, from almost every article that i read, it's usually used when you creating the object requires complex proccesses
Something like this is what I had in mind
Code:
/**
* Create a widget slider instance
*/
private WidgetSlider slider = new WidgetSlider();
/**
* Prevent the slider from being initialised twice
*/
private WidgetSlider() {
}
/**
* Construct a slider
* @Param min The minimum value
* @Param max The maximum value
* @Param default The default value
* @Param background The background
* @Param handle The handle
*/
private WidgetSlider(int min, int max, int default, SimpleImage background, SimpleImage handle) {
this.min = min;
this.max = max;
this.default = default;
this.background = background;
this.handle = handle;
}
/**
* Return the single instance of widget slider
* @Return The slider
*/
public static WidgetSlider createSlider() {
return slider;
}
I wouldn't say that's complex.
But you are right if you do have an interface with multiple needs for a slider it wouldn't really work. This would be more efficient for single use interfaces because it would reuse same instance, perhaps you could incorporate both for completion?
Fyi they wouldn't share the same values as you are resetting them everytime it is drawn However if you need two sliders on one interface they would share.