0
JSlider
のノンリニアスケールを作成しようとしていますが、現在使用しているスケールではそれほど大きくないために大きなギャップがあります。JSliderのノンリニアスケールを作成する
これは私が部門を設定したためです。たとえば、スライダが300
の場合、精度は1661
ですが、スライダが301
の場合、精度は9192
です。
多くの余分な範囲を追加することなくギャップを小さくする方法はありますか?例えば
else if(temp > 150 && temp <= 250)
accuracy = (int) Math.pow((double) accSlide.getValue(), 1.2);
編集
の多くを行うことなく、このJSlider
の目的は、数字の間の加速度の3~4の異なるセクションを有することです。例えば
Section 1 (First quarter of JSlider) : 0-150
Section 2 (Second quarter of JSlider): 150-10000
Section 3 (Third quarter of JSlider) : 10000-100000
Section 4 (Final quarter of JSlider) : 100000-1000000
ためのこのaccuracy
変数は、プログラム内の異なる機能に後で使用されます。次の短いコード例では、更新JLabel
として示されています。 JSlider
を使用してこれを達成する最良の方法は何ですか?
SSCCE/MCVE
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@SuppressWarnings("serial")
public class Slider extends JFrame {
private int accuracy = 150;
private Slider() {
super("Slider");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createLayout();
setSize(400, 100);
setLocationRelativeTo(null);
setVisible(true);
}
private void createLayout() {
JPanel rootPanel = new JPanel();
JLabel acc = new JLabel("Accuracy: " + accuracy);
JSlider accSlide = new JSlider(1, 1000, accuracy);
accSlide.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
int temp = accSlide.getValue();
if(temp <= 150)
accuracy = accSlide.getValue();
else if(temp > 150 && temp <= 300)
accuracy = (int) Math.pow((double) accSlide.getValue(), 1.3);
else if(temp > 300 && temp <= 600)
accuracy = (int) Math.pow((double) accSlide.getValue(), 1.6);
else if(temp > 600 && temp <= 1000)
accuracy = (int) Math.pow((double) accSlide.getValue(), 2);
acc.setText("Accuracy: " + accuracy);
}
});
rootPanel.add(acc);
rootPanel.add(accSlide, "grow");
add(rootPanel);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> new Slider());
}
}
は、それはあなたが、スライダーの値から(ひどくという名前の非Java標準)変数SQRT_DIGを計算するために使用し、あなたの方程式上のすべてのヒンジないのですか?あなたの現在の方程式は、あなたが見ているひどい不連続をもたらします。代わりに、より滑らかになるように方程式を微調整する必要があります。私たちはあなたの方程式の必要性を知らないので、これはあなたが解決できる唯一の問題であるようです。 –
あなたの関数には巨大なジャンプがあります。 https://www.mathsisfun.com/calculus/continuity.html –
300と301の等しい値を生成するように、適切なオフセットを方程式のケースに追加することをお勧めします。 –