使用Objects生成新值时遇到问题

时间:2016-05-04 21:20:44

标签: java user-interface

在问题3的 GraphicalInterface.java 上,由于使用相同的对象,我在生成新的数字列表时遇到了麻烦。如何在生成新数字时实现目标?

private void optionMethod() {
    button = new JButton("Generate Frequency!");
    button.addActionListener(
        new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                //Issue #2: What if exceeds the range from 10?                  
                int minRangeValue = Integer.parseInt(minRange.getText());
                int maxRangeValue = Integer.parseInt(maxRange.getText());
                int lengthValue = Integer.parseInt(value.getText());

                //Issue #3: Numbers are being generated only one time.
                gen.generateNumber(lengthValue, minRangeValue, maxRangeValue);
                for (int i=0; i < 10; i++) {
                    frequencyStatsLabel[i].setText(gen.frequencyNumber(i+1) + "%"); 
                }       
                System.out.println("[Console]: Min Range: " + minRange.getText());
                System.out.println("[Console]: Max Range: " + maxRange.getText());
                System.out.println("[Console]: Length: " + value.getText());
                System.out.println("[Console]: All numbers have been generated.");
            }
        }
    );
}

Click here查看源代码。

1 个答案:

答案 0 :(得分:0)

谢谢@Minh Kieu,我能够在我的程序中找到问题。显然我有一个static ArrayList,这就是实例不会改变的原因。我已从ArrayList中删除静态,现在我的ActionList将生成新的数字列表,以更新数据。