用java语言绘制三角函数图像
答案:1 悬赏:70 手机版
解决时间 2021-03-12 20:58
- 提问者网友:抽煙菂渘情少年
- 2021-03-12 13:01
用java语言绘制三角函数图像
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-03-12 13:26
package com.graphics;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test(){
getContentPane().add(new GJpanel());
setSize(400,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Test();
}
}
class GJpanel extends JPanel {
private int w;
private int h;
public GJpanel(){
}
public void paintComponent(final Graphics g){
w = getWidth();
h = getHeight();
g.setColor(Color.green);
g.drawLine(0, 0, 0,getHeight());
g.setColor(Color.red);
g.drawLine(0,h/2,w,h/2); //x
g.drawLine(w, h/2, w-10, h/2-10);
g.drawLine(w, h/2, w-10, h/2+10);
g.drawLine(w/2, 0,w/2, h); //y
g.drawLine(w/2, 0, w/2-10, 10);
g.drawLine(w/2, 0, w/2+10, 10);
g.drawString("Y", w/2-20, 20);
g.drawString("X", w-20, h/2+20);
for(int x =0;x int y =(int) (Math.cos (x*Math. PI/180)*h/3);
g.drawString("·", x, h/2-y);
}
}
}
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test(){
getContentPane().add(new GJpanel());
setSize(400,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Test();
}
}
class GJpanel extends JPanel {
private int w;
private int h;
public GJpanel(){
}
public void paintComponent(final Graphics g){
w = getWidth();
h = getHeight();
g.setColor(Color.green);
g.drawLine(0, 0, 0,getHeight());
g.setColor(Color.red);
g.drawLine(0,h/2,w,h/2); //x
g.drawLine(w, h/2, w-10, h/2-10);
g.drawLine(w, h/2, w-10, h/2+10);
g.drawLine(w/2, 0,w/2, h); //y
g.drawLine(w/2, 0, w/2-10, 10);
g.drawLine(w/2, 0, w/2+10, 10);
g.drawString("Y", w/2-20, 20);
g.drawString("X", w-20, h/2+20);
for(int x =0;x
g.drawString("·", x, h/2-y);
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯