Java实现动态sin和cos函数图像

JaJava实现动态sin和cos函数图像_第1张图片实现动态sin和cos函数图像的部分代码

public class DrawCoord extends JPanel {
@Override
public void setBackground(Color bg) {
super.setBackground(Color.BLACK);
}


public void paint(Graphics g) {
super.paint(g);
// 设置画笔的颜色
g.setColor(Color.WHITE);
// 画x轴
g.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2);
// 画y轴
g.drawLine(getWidth() / 4, 0, getWidth() / 4, getHeight());
// 画箭头
g.drawLine(getWidth(), getHeight() / 2, getWidth() - 10,
getHeight() / 2 - 10);
g.drawLine(getWidth(), getHeight() / 2, getWidth() - 10,
getHeight() / 2 + 10);
g.drawLine(getWidth() / 4, 0, getWidth() / 4 - 10, 10);
g.drawLine(getWidth() / 4, 0, getWidth() / 4 + 10, 10);
// 画X轴上的点
for (int i = 0; i < 16; i++) {
g.fillOval(i * getWidth() / 16 - 3, getHeight() / 2 - 3, 6, 6);
}
for (int i = 3; i < 8; i += 2) {
g.drawString(String.valueOf(i - 2) + "∏/2", i * getWidth() / 8 - 6,
getHeight() / 2 + 16);
}
g.drawString("-∏/2", getWidth() / 8 - 6, getHeight() / 2 + 16);
g.drawString("-∏", 0 * getWidth() / 4, getHeight() / 2 - 6);
g.drawString("∏", 2 * getWidth() / 4, getHeight() / 2 - 6);
g.drawString("2∏", 3 * getWidth() / 4, getHeight() / 2 - 6);
// 画y轴上的点
for (int i = 1, j = 2; i < 6; i++, j--) {
g.fillOval(getWidth() / 4 - 3, i * getHeight() / 6 - 3, 6, 6);
g.drawString(String.valueOf(j), getWidth() / 4 + 6, i * getHeight()
/ 6 + 3);
}
}
}

下载地址http://download.csdn.net/download/llei_6062/10103248

你可能感兴趣的:(Java)