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());
}
}
java 三角插值 java三角函数运算代码
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【Canvas与艺术】绘制斜置黄色三角biohazard标志
使用Html5/Canvas绘制斜置黄色三角biohazard标志。
canvas biohazard -
三角函数
常用三角函数
三角函数 分享 -
java中三角函数运算代码 java编程三角形
用java来打印出一个5行的三角形
java中三角函数运算代码 for循环 System i++