java swing滑块帮助!! [英] java swing slider help!!

查看:56
本文介绍了java swing滑块帮助!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我对java swing很新,需要一些帮助。我正在开发一个简单的颜色选择器程序。我有一个连接到三个滑块的颜色面板。红绿蓝。但由于某种原因,我无法让它工作..我会发布我的代码,如果有人有任何洞察力为什么我的changelistener不能正常工作,我会非常感激。谢谢。

Hey guys i am pretty new to java swing and need some help. I am developing a simple color chooser program in swing. I have a color panel that is connected to three sliders. red green and blue. but for some reason i cant get it to work..i will post my code and if anyone has any insight to why my changelistener wont work correctly I would really appreciate it. Thanks.

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案

创建滑块时,将它们分配给局部变量与您的成员变量同名;省略那些局部变量,因为它们隐藏了你的成员变量。


你不能创建rLabel,gLabel和bLabel,但你确实想在你的更改监听器中为它们分配一个文本。它们仍为null,因此抛出NullPointerException。


可能会有更多错误,但我建议你在这里和那里撒上一些System.out.println()语句,这样你就可以看到实际上正在发生。


亲切的问候,


Jos
When you create your sliders you assign them to local variables with the same name as your member variables; leave out those local variables because they hide your member variables.

You don''t create rLabel, gLabel and bLabel but you do want to assign a text to them in your change listener. They are still null so a NullPointerException is thrown.

There may be more errors but I suggest you sprinkle in some System.out.println() statements here and there so you can see what is actually happening.

kind regards,

Jos


谢谢你我修好了。但是我有另一个问题......当我从网格中选择一个随机颜色时,它会在面板中显示我想要的颜色..但我希望滑块自动设置为那种颜色..我不确定如何做到这一点。但如果有人可以提供帮助那就太棒了..

ya thank you i fixed it..but Ihave another question..when i select a random color from my grid it shows the color in the panel how i want..but I want the sliders to automatically get set to that color..Im not really sure how to do that. but if anyone could help that would be great..

展开 | 选择 | Wrap | 行号


@ yeshello54

您是否阅读过JSlider组件的API文档?您可以通过编程方式设置其位置。


亲切的问候,


Jos
@yeshello54
Have you read the API documentation for the JSlider component? You can programmatically set its position.

kind regards,

Jos


这篇关于java swing滑块帮助!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆