📄 sliderpanel.java
字号:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.ArrayList;
public class sliderPanel extends JPanel
{
private JSlider sa0,sa1,sa2,sa3,sa4,sa5,sa6;
public ArrayList<Integer> L;
private Container cc1,cc2;
private final int max=20,min=-20,Major=10,Minor=1;
private JLabel la0,la1,la2,la3,la4,la5,la6;
private sixxPanel six;
public sliderPanel(sixxPanel sixx)
{
L=new ArrayList<Integer>();
six=sixx;
SliderListener listener=new SliderListener();
cc1=new Container();
cc2=new Container();
cc1.setLayout(new GridLayout(7,1));
cc2.setLayout(new GridLayout(7,1));
sa0=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa0.setMajorTickSpacing(Major);
sa0.setMinorTickSpacing(Minor);
sa0.setPaintTicks(true);
sa0.setPaintLabels(true);
sa0.setAlignmentX(Component.LEFT_ALIGNMENT);
sa0.addChangeListener(listener);
la0=new JLabel("0*x^6");
la0.setAlignmentX(Component.LEFT_ALIGNMENT);
sa1=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa1.setMajorTickSpacing(Major);
sa1.setMinorTickSpacing(Minor);
sa1.setPaintTicks(true);
sa1.setPaintLabels(true);
sa1.setAlignmentX(Component.LEFT_ALIGNMENT);
sa1.addChangeListener(listener);
la1=new JLabel("0*x^5");
la1.setAlignmentX(Component.LEFT_ALIGNMENT);
sa2=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa2.setMajorTickSpacing(Major);
sa2.setMinorTickSpacing(Minor);
sa2.setPaintTicks(true);
sa2.setPaintLabels(true);
sa2.setAlignmentX(Component.LEFT_ALIGNMENT);
sa2.addChangeListener(listener);
la2=new JLabel("0*x^4");
la2.setAlignmentX(Component.LEFT_ALIGNMENT);
sa3=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa3.setMajorTickSpacing(Major);
sa3.setMinorTickSpacing(Minor);
sa3.setPaintTicks(true);
sa3.setPaintLabels(true);
sa3.setAlignmentX(Component.LEFT_ALIGNMENT);
sa3.addChangeListener(listener);
la3=new JLabel("0*x^3");
la3.setAlignmentX(Component.LEFT_ALIGNMENT);
sa4=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa4.setMajorTickSpacing(Major);
sa4.setMinorTickSpacing(Minor);
sa4.setPaintTicks(true);
sa4.setPaintLabels(true);
sa4.setAlignmentX(Component.LEFT_ALIGNMENT);
sa4.addChangeListener(listener);
la4=new JLabel("0*x^2");
la4.setAlignmentX(Component.LEFT_ALIGNMENT);
sa5=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa5.setMajorTickSpacing(Major);
sa5.setMinorTickSpacing(Minor);
sa5.setPaintTicks(true);
sa5.setPaintLabels(true);
sa5.setAlignmentX(Component.LEFT_ALIGNMENT);
sa5.addChangeListener(listener);
la5=new JLabel("0*x");
la5.setAlignmentX(Component.LEFT_ALIGNMENT);
sa6=new JSlider (JSlider.HORIZONTAL,min,max,0);
sa6.setMajorTickSpacing(Major);
sa6.setMinorTickSpacing(Minor);
sa6.setPaintTicks(true);
sa6.setPaintLabels(true);
sa6.setAlignmentX(Component.LEFT_ALIGNMENT);
sa6.addChangeListener(listener);
la6=new JLabel("0");
la6.setAlignmentX(Component.LEFT_ALIGNMENT);
cc1.add(la0);
cc1.add(la1);
cc1.add(la2);
cc1.add(la3);
cc1.add(la4);
cc1.add(la5);
cc1.add(la6);
cc2.add(sa0);
cc2.add(sa1);
cc2.add(sa2);
cc2.add(sa3);
cc2.add(sa4);
cc2.add(sa5);
cc2.add(sa6);
setLayout(new BorderLayout());
add(cc1,BorderLayout.WEST);
add(cc2,BorderLayout.CENTER);
}
public class SliderListener implements ChangeListener
{
public void stateChanged(ChangeEvent e)
{
L.clear();
L.add(sa0.getValue());
L.add(sa1.getValue());
L.add(sa2.getValue());
L.add(sa3.getValue());
L.add(sa4.getValue());
L.add(sa5.getValue());
L.add(sa6.getValue());
la0.setText(L.get(0)+"*x^6");
la1.setText(L.get(1)+"*x^5");
la2.setText(L.get(2)+"*x^4");
la3.setText(L.get(3)+"*x^3");
la4.setText(L.get(4)+"*x^2");
la5.setText(L.get(5)+"*x");
la6.setText(L.get(6)+" ");
six.repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -