每次我移动我的 JSlider 时,我的 JDialog 框都会出现在它移动的每个位置上,我只希望它在用户尝试移动 JSlider 而不他们从我的菜单中进行选择时显示一次。我该怎么做?
public void stateChanged(ChangeEvent e)
{
if(myFrame.shape == null)
{
JOptionPane.showMessageDialog(popUp, "You should select an item first.", "Information", JOptionPane.WARNING_MESSAGE);
}
else if(myFrame.shape != null)
{
DecimalFormat df = new DecimalFormat("0.0");
float value = diameterJSlider.getValue();
String strValue = Float.toString(value);
sliderLabel.setText(strValue);
boundaryTextField.setText("" + df.format(myFrame.shape.getBoundary(value)));
areaTextField.setText("" + df.format(myFrame.shape.getArea(value)));
myTopPanel.reDraw(diameterJSlider.getValue());
}