java画三角函数

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Paint {

public static void main(String[] args) {

JFrame f = new PaintFrame();
f.setVisible(true);
}
}

class PaintovalPane extends JPanel {

/**
*
*/
private static final long serialVersionUID = 9125164341994818026L;

public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.green);
g.fillOval(150, 150, 200, 200);

}
}

class GJpanel extends JPanel {

/**
*
*/
private static final long serialVersionUID = 1L;

private int w;
private int h;

public GJpanel() {
}

public void paintComponent(final Graphics g) {

w = getWidth();
h = getHeight();

g.drawLine(0, 0, 0, getHeight());
g.setColor(Color.black);
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);

g.setColor(Color.black);
for (int x = 0; x < w; x++) {
int y = (int) (Math.cos(x * Math.PI / 180) * h / 3);
g.drawString("·", x, h / 2 - y);
}
}
}

class PaintFrame extends JFrame {

/**
*
*/
private static final long serialVersionUID = 6729853332061293627L;

Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int screen_width = (int) screensize.getWidth();
int screen_height = (int) screensize.getHeight();
int width = 800;
int height = 600;

public PaintFrame() {
setTitle("Java画板");
setSize(width, height);
setLocation((screen_width - width) / 2, (screen_height - height) / 2);
addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = getContentPane();
// contentPane.add(new PaintovalPane());
contentPane.add(new GJpanel());
}
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值