我不知道那是什么原因。也许你可以帮助我
所以在这里编写代码创建一个带有 8 个滑块的框架。
public class MyFrame extends JFrame {
ImagePanel imagePanel;
final int Minimum = 0;
final int Maximum = 10;
final int NumberOfSpheres = 8;
final int NumberOfScales = 10;
MyRandomAccessFile file;
final String[] s = {"Друзья и Окружение",
"Отношения", "Карьера и Бизнес",
"Финансы", "Духовность и Творчество",
"Личностный Рост", "Яркость Жизни", "Здоровье и Спорт"};
private final Color[] colors = {Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.PINK, Color.MAGENTA, Color.DARK_GRAY};
private final int[] array = {1, 0, 0, 0, 0, 0, 0, 0};
public MyFrame () {
setTitle("Wheel Of Life");
MySlider[] sliders = new MySlider[NumberOfSpheres];
JButton saveButton = new JButton("Save");
MyActionListener listener1 = new MyActionListener();
saveButton.addActionListener(listener1);
file = new MyRandomAccessFile();
//String s3 = "0 0 0 0 0 0 0 0";
//array = stringToIntArray(s3);
array[1] = 4;
JLabel[] labels = new JLabel[NumberOfSpheres];
imagePanel = new ImagePanel(colors, array);
System.out.println(array[1]);
JPanel mainPanel = new JPanel();
JPanel[] sliderPanels = new JPanel[NumberOfSpheres];
JPanel mainSliderPanel = new JPanel(new GridLayout(4, 2, 20, 20));
MyChangeListener listener = new MyChangeListener();
for (int i = 0; i < NumberOfSpheres; i++) {
sliders[i] = new MySlider(s[i]);
sliders[i].addChangeListener(listener);
labels[i] = new JLabel(s[i]);
labels[i].setForeground(colors[i]);
labels[i].setFont(new Font("Droid Sans", Font.BOLD, 20));
sliderPanels[i] = new JPanel();
sliders[i].setMinimum(Minimum);
sliders[i].setMaximum(Maximum);
System.out.print(array[i]);
sliders[i].setValue(4);
sliders[i].setMajorTickSpacing(1);
sliders[i].setMinorTickSpacing((int) 0.1);
sliders[i].setPaintLabels(true);
sliders[i].setPaintTicks(true);
sliderPanels[i].setLayout(new GridLayout(2, 1, 5, 5));
sliderPanels[i].add(sliders[i]);
sliderPanels[i].add(labels[i]);
mainSliderPanel.add(sliderPanels[i]);
}
mainPanel.setLayout(new BorderLayout());
mainPanel.add(imagePanel, BorderLayout.CENTER);
mainPanel.add(mainSliderPanel, BorderLayout.EAST);
mainPanel.add(saveButton, BorderLayout.SOUTH);
add(mainPanel);
}
输出是这样的
4 99999999
final 变量如何在执行时改变它的值,到底是什么???变量的实际值取决于我在 sliders[i].setValue(4); 处写入的值;但我不知道具体怎么...
我试图为这个变量设置一个观察点......不起作用。一次为零,下一次程序在此 for 循环中停止,值为 9、4 或其他...