-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFractalSettingNumber.java
47 lines (40 loc) · 1.21 KB
/
FractalSettingNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* An implementation of FractalSetting, is a number.
*/
public class FractalSettingNumber extends FractalSetting {
private final String mLabel;
private int mValue;
private final SpinnerNumberModel mSpinnerModel;
FractalSettingNumber(Fractal fractal, SpinnerNumberModel spinnerModel, String label) {
super(fractal);
mLabel = label;
mSpinnerModel = spinnerModel;
mValue = (int) spinnerModel.getValue();
}
public int getValue() {
return mValue;
}
public void setInitialValue(int value) {
mSpinnerModel.setValue(value);
mValue = value;
}
@Override
String getLabel() {
return mLabel;
}
@Override
JComponent buildJComponent() {
JSpinner spinner = new JSpinner(mSpinnerModel);
spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
mValue = (int) spinner.getValue();
mFractal.invalidate();
}
});
return spinner;
}
}