我用Java创建了一个JSlider,它改变了线需要倾斜的角度。
angle = new JSlider(SwingConstants.HORIZONTAL, 0, 180, 90);
angle.setSize(300, 50);
angle.setLocation(650, 60);
angle.setPaintTicks(true);
angle.setPaintTrack(true);
angle.setMinorTickSpacing(10);
angle.setMajorTickSpacing(30);
angle.setPaintLabels(true);
angle.addChangeListener(this);
thepanel.add(angle);
我希望代码绘制实现JSlider角度的那条线。
这是我的代码:
public void paintComponent(Graphics g){
super.paintComponent(g);
int angle = intAngle;
Graphics2D graphics = (Graphics2D)g;
int startX = getWidth()/2;
int startY = getHeight()/2;
int length = 200;
int endX = startX + length * (int)Math.cos(Math.toRadians(angle));
int endY = startY + length * (int)Math.sin(Math.toRadians(angle));
graphics.drawLine(startX, startY, endX, endY);
}
给定值旋转一条线后的数学是什么?