Display error message for JSlider
Hi, I have create a Java app using BlueJ, in which you can change the size of a selected shape using a JSlider. One of the shapes to choose from is just a 'point', the size of a pixel, whose size i do not want to be changed.
I am trying to get an error message to display when the 'point' shape is selected and the user tries to change the size using the JSlider. The code I have got is shown below. The problem I have is that the error message is displayed loads of times in the terminal window if you drag the slider a large amount, it is displayed for each time the slider changes by 1, if that makes sense. Is there any way I can get the error message to display just once no matter how far the slider has moved?
"
//When the slider is moved the following method will be called
public void stateChanged(ChangeEvent e) {
//Rewrite the label reflecting the new value of the slider
label.setText("Size: " + adjustsize.getValue() + " pixels");
//Change size of shape when slider is moved
adjustsize = (JSlider)e.getSource();
newSize = adjustsize.getValue();
aShape.reSize(newSize);
//If Point shape is selected display error message
if (aShape == firstPoint) {
System.out.println("You can't resize a point");
//Repaint the window to reflect the updates made
repaint();
}
"
Thanks!
Re: Display error message for JSlider
Thread moved from New to Java. Also, please go through http://www.java-forums.org/forum-gui...w-members.html and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.
Quote:
Originally Posted by
daft_punk01
I am trying to get an error message to display when the 'point' shape is selected and the user tries to change the size using the JSlider.
I would hate to be a user of such an application. The common programming idiom is to disable a GUI control that it isn't right to use.
db