本文整理匯總了Java中javax.swing.JSlider.setLabelTable方法的典型用法代碼示例。如果您正苦於以下問題:Java JSlider.setLabelTable方法的具體用法?Java JSlider.setLabelTable怎麽用?Java JSlider.setLabelTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JSlider
的用法示例。
在下文中一共展示了JSlider.setLabelTable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RangeOptionUI
import javax.swing.JSlider; //導入方法依賴的package包/類
/**
* Creates a new {@code RangeOptionUI} for the given
* {@code RangeOption}.
*
* @param option The {@code RangeOption} to make a user interface for
* @param editable boolean whether user can modify the setting
*/
public RangeOptionUI(final RangeOption option, boolean editable) {
super(option, editable);
JSlider slider = getComponent();
slider.setModel(new DefaultBoundedRangeModel(option.getValueRank(), 0,
0, option.getItemValues().size()-1));
Hashtable<Integer, JComponent> labels
= new Hashtable<>();
int index = 0;
for (String string : option.getItemValues().values()) {
if (option.localizeLabels()) {
labels.put(index, Utility.localizedLabel(string));
} else {
labels.put(index, new JLabel(string));
}
index++;
}
slider.setLabelTable(labels);
slider.setValue(option.getValueRank());
slider.setMajorTickSpacing(1);
slider.setSnapToTicks(true);
}
示例2: PercentageOptionUI
import javax.swing.JSlider; //導入方法依賴的package包/類
/**
* Creates a new {@code PercentageOptionUI} for the given
* {@code PercentageOption}.
*
* @param option The {@code PercentageOption} to make a user
* interface for.
* @param editable boolean whether user can modify the setting
*/
public PercentageOptionUI(final PercentageOption option, boolean editable) {
super(option, editable);
JSlider slider = getComponent();
slider.setModel(new DefaultBoundedRangeModel(option.getValue(), 0, 0, 100));
Hashtable<Integer, JComponent> labels
= new Hashtable<>();
labels.put(0, new JLabel("0 %"));
labels.put(25, new JLabel("25 %"));
labels.put(50, new JLabel("50 %"));
labels.put(75, new JLabel("75 %"));
labels.put(100, new JLabel("100 %"));
slider.setLabelTable(labels);
slider.setValue(option.getValue());
slider.setMajorTickSpacing(5);
slider.setSnapToTicks(false);
}
示例3: getControls
import javax.swing.JSlider; //導入方法依賴的package包/類
public Component getControls() {
final JSlider slider = new JSlider(JSlider.HORIZONTAL,0,100,opacity);
final HashMap<Integer,JLabel> labelTable = new HashMap<Integer,JLabel>();
labelTable.put(0, new JLabel("Transparent"));
labelTable.put(100, new JLabel("Opaque"));
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
// Note: JSlider uses the outdated Hashtable. Eventually Hashtable
// will be deprecated and we'll be able to use the HashMap directly.
slider.setLabelTable(new Hashtable<Integer,JLabel>(labelTable));
slider.setPaintLabels(true);
slider.setBorder(javax.swing.BorderFactory.createTitledBorder(name));
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
final JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
opacity = source.getValue();
}
}});
return slider;
}
示例4: addSuffixToSliderLabels
import javax.swing.JSlider; //導入方法依賴的package包/類
public static void addSuffixToSliderLabels(JSlider slider, String suffix) {
assert (slider != null && suffix != null);
Dictionary oldLabels = slider.getLabelTable();
Enumeration oldKeys = oldLabels.keys();
Hashtable newLabelTable = new Hashtable();
while (oldKeys.hasMoreElements()) {
Object key = oldKeys.nextElement();
Object value = oldLabels.get(key);
assert (value instanceof String);
String str = ((String)value).concat(suffix);
JLabel label = new JLabel(str);
newLabelTable.put(key, label);
}
slider.setLabelTable(newLabelTable);
}
示例5: RNNSearchDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public RNNSearchDemo() {
super(new BorderLayout());
startButton = new JButton("Start");
startButton.setActionCommand("startButton");
startButton.addActionListener(this);
Hashtable<Integer, JLabel> logNLabelTable = new Hashtable<>();
for (int i = 3; i <= 7; i++) {
logNLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
logNSlider = new JSlider(3, 7, logN);
logNSlider.setLabelTable(logNLabelTable);
logNSlider.setMajorTickSpacing(1);
logNSlider.setPaintTicks(true);
logNSlider.setPaintLabels(true);
Hashtable<Integer, JLabel> dimensionLabelTable = new Hashtable<>();
dimensionLabelTable.put(new Integer(2), new JLabel(String.valueOf(2)));
for (int i = 20; i <= 120; i += 20) {
dimensionLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
dimensionSlider = new JSlider(2, 128, dimension);
dimensionSlider.setLabelTable(dimensionLabelTable);
dimensionSlider.setMajorTickSpacing(20);
dimensionSlider.setMinorTickSpacing(5);
dimensionSlider.setPaintTicks(true);
dimensionSlider.setPaintLabels(true);
radiusField = new JTextField(Double.toString(radius), 5);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(startButton);
optionPane.add(new JLabel("log N:"));
optionPane.add(logNSlider);
optionPane.add(new JLabel("Dimension:"));
optionPane.add(dimensionSlider);
optionPane.add(new JLabel("Radius:"));
optionPane.add(radiusField);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(1, 2));
canvas.setBackground(Color.WHITE);
add(canvas, BorderLayout.CENTER);
}
示例6: KNNDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public KNNDemo() {
super(new BorderLayout());
startButton = new JButton("Start");
startButton.setActionCommand("startButton");
startButton.addActionListener(this);
Hashtable<Integer, JLabel> logNLabelTable = new Hashtable<>();
for (int i = 3; i <= 7; i++) {
logNLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
logNSlider = new JSlider(3, 7, logN);
logNSlider.setLabelTable(logNLabelTable);
logNSlider.setMajorTickSpacing(1);
logNSlider.setPaintTicks(true);
logNSlider.setPaintLabels(true);
Hashtable<Integer, JLabel> dimensionLabelTable = new Hashtable<>();
dimensionLabelTable.put(new Integer(2), new JLabel(String.valueOf(2)));
for (int i = 20; i <= 120; i += 20) {
dimensionLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
dimensionSlider = new JSlider(2, 128, dimension);
dimensionSlider.setLabelTable(dimensionLabelTable);
dimensionSlider.setMajorTickSpacing(20);
dimensionSlider.setMinorTickSpacing(5);
dimensionSlider.setPaintTicks(true);
dimensionSlider.setPaintLabels(true);
knnField = new JTextField(Integer.toString(knn), 5);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(startButton);
optionPane.add(new JLabel("log N:"));
optionPane.add(logNSlider);
optionPane.add(new JLabel("Dimension:"));
optionPane.add(dimensionSlider);
optionPane.add(new JLabel("K:"));
optionPane.add(knnField);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(1, 2));
canvas.setBackground(Color.WHITE);
add(canvas, BorderLayout.CENTER);
}
示例7: GaussianDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public GaussianDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 50; i+=10) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
sigmaSlider = new JSlider(0, 50, (int) Math.round(sigma * 10));
sigmaSlider.addChangeListener(this);
sigmaSlider.setLabelTable(labelTable);
sigmaSlider.setMajorTickSpacing(10);
sigmaSlider.setMinorTickSpacing(2);
sigmaSlider.setPaintTicks(true);
sigmaSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("\u03C3:"));
optionPane.add(sigmaSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
GaussianDistribution dist = new GaussianDistribution(0, sigma);
double[][] p = new double[200][2];
double[][] q = new double[200][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i - 100) / 10.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i - 100) / 10.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例8: WeibullDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public WeibullDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> shapeLabelTable = new Hashtable<>();
for (int i = 0; i <= 10; i+=2) {
shapeLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
shapeSlider = new JSlider(0, 10, (int) Math.round(shape));
shapeSlider.addChangeListener(this);
shapeSlider.setLabelTable(shapeLabelTable);
shapeSlider.setMajorTickSpacing(2);
shapeSlider.setMinorTickSpacing(1);
shapeSlider.setPaintTicks(true);
shapeSlider.setPaintLabels(true);
Hashtable<Integer, JLabel> scaleLabelTable = new Hashtable<>();
for (int i = 0; i <= 50; i+=10) {
scaleLabelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
scaleSlider = new JSlider(0, 50, (int) Math.round(scale*10));
scaleSlider.addChangeListener(this);
scaleSlider.setLabelTable(scaleLabelTable);
scaleSlider.setMajorTickSpacing(10);
scaleSlider.setMinorTickSpacing(2);
scaleSlider.setPaintTicks(true);
scaleSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("Shape:"));
optionPane.add(shapeSlider);
optionPane.add(new JLabel("Scale:"));
optionPane.add(scaleSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
WeibullDistribution dist = new WeibullDistribution(shape, scale);
double[][] p = new double[100][2];
double[][] q = new double[100][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = i / 20.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = i / 20.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例9: ExponentialDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public ExponentialDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 50; i+=10) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
lambdaSlider = new JSlider(0, 50, (int) Math.round(lambda * 10));
lambdaSlider.addChangeListener(this);
lambdaSlider.setLabelTable(labelTable);
lambdaSlider.setMajorTickSpacing(10);
lambdaSlider.setMinorTickSpacing(2);
lambdaSlider.setPaintTicks(true);
lambdaSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("\u03BB:"));
optionPane.add(lambdaSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
ExponentialDistribution dist = new ExponentialDistribution(lambda);
double[][] p = new double[100][2];
double[][] q = new double[100][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = i / 20.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = i / 20.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例10: BetaDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public BetaDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 100; i+=20) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i / 10)));
}
alphaSlider = new JSlider(0, 100, (int) Math.round(alpha * 10));
alphaSlider.addChangeListener(this);
alphaSlider.setLabelTable(labelTable);
alphaSlider.setMajorTickSpacing(10);
alphaSlider.setMinorTickSpacing(2);
alphaSlider.setPaintTicks(true);
alphaSlider.setPaintLabels(true);
betaSlider = new JSlider(0, 100, (int) Math.round(beta * 10));
betaSlider.addChangeListener(this);
betaSlider.setLabelTable(labelTable);
betaSlider.setMajorTickSpacing(10);
betaSlider.setMinorTickSpacing(2);
betaSlider.setPaintTicks(true);
betaSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("\u03B1:"));
optionPane.add(alphaSlider);
optionPane.add(new JLabel("\u03B2:"));
optionPane.add(betaSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
BetaDistribution dist = new BetaDistribution(alpha, beta);
double[][] p = new double[99][2];
double[][] q = new double[99][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i+1) / 100.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i+1) / 100.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例11: FDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public FDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
labelTable.put(1, new JLabel(String.valueOf(1)));
for (int i = 20; i <= 100; i += 20) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
d1Slider = new JSlider(1, 100, d1);
d1Slider.addChangeListener(this);
d1Slider.setLabelTable(labelTable);
d1Slider.setMajorTickSpacing(10);
d1Slider.setMinorTickSpacing(2);
d1Slider.setPaintTicks(true);
d1Slider.setPaintLabels(true);
d2Slider = new JSlider(1, 100, d2);
d2Slider.addChangeListener(this);
d2Slider.setLabelTable(labelTable);
d2Slider.setMajorTickSpacing(10);
d2Slider.setMinorTickSpacing(2);
d2Slider.setPaintTicks(true);
d2Slider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("Degree of Freedom 1:"));
optionPane.add(d1Slider);
optionPane.add(new JLabel("Degree of Freedom 2:"));
optionPane.add(d2Slider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
FDistribution dist = new FDistribution(d1, d2);
double[][] p = new double[100][2];
double[][] q = new double[100][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i+1) / 20.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i+1) / 20.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例12: MultivariateGaussianDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public MultivariateGaussianDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 30; i+=10) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i/10.0)));
}
sigma1Slider = new JSlider(0, 30, (int) (sigma[0]*10));
sigma1Slider.addChangeListener(this);
sigma1Slider.setLabelTable(labelTable);
sigma1Slider.setMajorTickSpacing(10);
sigma1Slider.setMinorTickSpacing(2);
sigma1Slider.setPaintTicks(true);
sigma1Slider.setPaintLabels(true);
sigma2Slider = new JSlider(0, 30, (int) (sigma[1]*10));
sigma2Slider.addChangeListener(this);
sigma2Slider.setLabelTable(labelTable);
sigma2Slider.setMajorTickSpacing(10);
sigma2Slider.setMinorTickSpacing(2);
sigma2Slider.setPaintTicks(true);
sigma2Slider.setPaintLabels(true);
optionPane = new JPanel();
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("<html>\u03C3<sub>1</sub>:</html>"));
optionPane.add(sigma1Slider);
optionPane.add(new JLabel("<html>\u03C3<sub>2</sub>:</html>"));
optionPane.add(sigma2Slider);
add(optionPane, BorderLayout.NORTH);
MultivariateGaussianDistribution g = new MultivariateGaussianDistribution(mu, sigma);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
z[i][j][0] = 6.0 * (i - m/2) / m;
z[i][j][1] = 6.0 * (j - n/2) / n;
double[] point = {z[i][j][0], z[i][j][1]};
z[i][j][2] = g.p(point);
}
}
pdf = Surface.plot(z);
pdf.setTitle("Multivariate Gaussian");
add(pdf, BorderLayout.CENTER);
}
示例13: GammaDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public GammaDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> shapeLabelTable = new Hashtable<>();
for (int i = 0; i <= 10; i+=2) {
shapeLabelTable.put(new Integer(i), new JLabel(String.valueOf(i)));
}
shapeSlider = new JSlider(0, 10, (int) Math.round(shape));
shapeSlider.addChangeListener(this);
shapeSlider.setLabelTable(shapeLabelTable);
shapeSlider.setMajorTickSpacing(2);
shapeSlider.setMinorTickSpacing(1);
shapeSlider.setPaintTicks(true);
shapeSlider.setPaintLabels(true);
Hashtable<Integer, JLabel> scaleLabelTable = new Hashtable<>();
for (int i = 0; i <= 50; i+=10) {
scaleLabelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
scaleSlider = new JSlider(0, 50, (int) Math.round(scale*10));
scaleSlider.addChangeListener(this);
scaleSlider.setLabelTable(scaleLabelTable);
scaleSlider.setMajorTickSpacing(10);
scaleSlider.setMinorTickSpacing(2);
scaleSlider.setPaintTicks(true);
scaleSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("Shape:"));
optionPane.add(shapeSlider);
optionPane.add(new JLabel("Scale:"));
optionPane.add(scaleSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
GammaDistribution dist = new GammaDistribution(shape, scale);
double[][] p = new double[100][2];
double[][] q = new double[100][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = i / 5.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = i / 5.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例14: LogNormalDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public LogNormalDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 20; i+=10) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
sigmaSlider = new JSlider(0, 20, (int) Math.round(sigma * 10));
sigmaSlider.addChangeListener(this);
sigmaSlider.setLabelTable(labelTable);
sigmaSlider.setMajorTickSpacing(10);
sigmaSlider.setMinorTickSpacing(1);
sigmaSlider.setPaintTicks(true);
sigmaSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("\u03C3:"));
optionPane.add(sigmaSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
LogNormalDistribution dist = new LogNormalDistribution(0, sigma);
double[][] p = new double[100][2];
double[][] q = new double[100][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i+1) / 20.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i+1) / 20.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}
示例15: LogisticDistributionDemo
import javax.swing.JSlider; //導入方法依賴的package包/類
public LogisticDistributionDemo() {
super(new BorderLayout());
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
for (int i = 0; i <= 50; i+=10) {
labelTable.put(new Integer(i), new JLabel(String.valueOf(i/10)));
}
sigmaSlider = new JSlider(0, 50, (int) Math.round(sigma * 10));
sigmaSlider.addChangeListener(this);
sigmaSlider.setLabelTable(labelTable);
sigmaSlider.setMajorTickSpacing(10);
sigmaSlider.setMinorTickSpacing(2);
sigmaSlider.setPaintTicks(true);
sigmaSlider.setPaintLabels(true);
optionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
optionPane.setBorder(BorderFactory.createRaisedBevelBorder());
optionPane.add(new JLabel("Scale:"));
optionPane.add(sigmaSlider);
add(optionPane, BorderLayout.NORTH);
canvas = new JPanel(new GridLayout(2, 2));
add(canvas, BorderLayout.CENTER);
LogisticDistribution dist = new LogisticDistribution(0, sigma);
double[][] p = new double[200][2];
double[][] q = new double[200][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i - 100) / 10.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i - 100) / 10.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf = LinePlot.plot(p, Line.Style.SOLID, Color.BLUE);
pdf.setTitle("PDF");
canvas.add(pdf);
cdf = LinePlot.plot(q, Line.Style.SOLID, Color.BLUE);
cdf.setTitle("CDF");
canvas.add(cdf);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram = Histogram.plot(data, 20);
histogram.setTitle("Histogram");
canvas.add(histogram);
qqplot = QQPlot.plot(data, dist);
qqplot.setTitle("Q-Q Plot");
canvas.add(qqplot);
}