我希望使用创建的名为 spinnerModel 的值,但似乎不能这样做,我相信我必须将其声明为某种我不确定的类型。我想把它变成双精度,因为它稍后会在程序中使用。我有以下内容,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class UI {
//Need to use the spinnerModel here but cannot :(
private void weightSpinnerMetricStateChanged(ChangeEvent e) {
JSpinner weightSpinnerMetric = (JSpinner) e.getSource();
SpinnerModel spinnerModel = weightSpinnerMetric.getModel();
System.out.println(spinnerModel.getValue());
}
stonesSpinnerImperial = new JSpinner(); //Spinner created here.
stonesSpinnerImperial.setModel(new SpinnerNumberModel(3, 3, 31, 1));
stonesSpinnerImperial.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
stonesSpinnerStateChanged(e);
stonesSpinnerImperialStateChanged(e);
}
});
}