滚动条事件处理,如何保持抓取的数字静态

发布于 2024-08-18 09:04:37 字数 868 浏览 5 评论 0原文

正如标题所示,我有一个带有滚动条界面的程序。问题是该程序对四组不同的数字使用相同的三个滚动条,一旦对另一组数字进行更改,滚动条将保持与前一组数字相同的值

        float RedAmount1 = lightDimmer1.getValue();
        float GreenAmount1 = lightDimmer2.getValue();
        float BlueAmount1 = lightDimmer3.getValue();

        diffuseSwitch[0] = RedAmount1;          
        diffuseSwitch[1] = GreenAmount1;
        diffuseSwitch[2] = BlueAmount1;

        float StoreColours1[] = {RedAmount1,GreenAmount1,BlueAmount1};

        int StoreColourRed = (int)StoreColours1[0];
        int StoreColourGreen = (int)StoreColours1[1];
        int StoreColourBlue = (int)StoreColours1[2];

        if(diffuseSwitch[0] != StoreColourRed)
        {
         lightDimmer1.setValue(StoreColourRed);
        }

这段代码被放置在滚动条事件处理部分,因此尝试比较 float StoreColourRed 和 diffuseSwitch[0] 的数字不断更改为最新一组数字的值,而不是保留之前的一组值。

任何帮助将不胜感激

As the title suggests I have a program with a scrollbar interface. The problem is that the program uses the same three scrollbars for four sets of different numbers, once the change has been made to another set of numbers the scrollbar remains on the same values from the previous set of numbers

        float RedAmount1 = lightDimmer1.getValue();
        float GreenAmount1 = lightDimmer2.getValue();
        float BlueAmount1 = lightDimmer3.getValue();

        diffuseSwitch[0] = RedAmount1;          
        diffuseSwitch[1] = GreenAmount1;
        diffuseSwitch[2] = BlueAmount1;

        float StoreColours1[] = {RedAmount1,GreenAmount1,BlueAmount1};

        int StoreColourRed = (int)StoreColours1[0];
        int StoreColourGreen = (int)StoreColours1[1];
        int StoreColourBlue = (int)StoreColours1[2];

        if(diffuseSwitch[0] != StoreColourRed)
        {
         lightDimmer1.setValue(StoreColourRed);
        }

This piece of code is placed within a scrollbars event handling section so the number am trying to compare float StoreColourRed and diffuseSwitch[0] keep being changed to the values of the latest set of numbers instead of keeping the previous set of values.

any help would be much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-08-25 09:04:37

使用一个非常简单的类来保存您的值,例如:

private static class MyColor {
    float red, green, blue;
}

您应该能够使用 getValueIsAdjusting()setValueIsAdjusting() 确定值何时稳定。您可能还需要我们 JRadioButtonJComboBox< /code>选择正在操作的值集。

附录:我粗心地假设 JSlider 阅读问题时。此外,调整可能无关紧要。 JTabbedPane是选择要操纵哪组值的另一种选择。

Use a very simple class to hold your values, for example:

private static class MyColor {
    float red, green, blue;
}

You should be able to use getValueIsAdjusting() and setValueIsAdjusting() to determine when the values are stable. You may also want to us JRadioButton or JComboBox to select which set of values is being manipulated.

Addendum: I carelessly assumed JSlider when reading the question. Also, adjusting is probably irrelevant. JTabbedPane is another choice for selecting which set of values is being manipulated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文