DrawPolygon
来源:互联网 发布:数控车床编程90例图 编辑:程序博客网 时间:2024/06/07 00:39
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
public class DrawPolygon extends JFrame {
public DrawPolygon() {
add(new PolygonPanel());
}
/** Main method */
public static void main(String[] args) {
DrawPolygon frame = new DrawPolygon();
frame.setTitle("DrawPolygon");
frame.setSize(300, 200);
frame.setLocationRelativeTo(null); //Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
//Draw a polygon in the panel
class PolygonPanel extends JPanel {
protected void paintComponent(Graphics g) {
int xCenter = getWidth() / 2;
int yCenter = getHeight() / 2;
int radius = Math.min(getWidth(), getHeight()) / 2;
int[] xPoints = new int[6];
int[] yPoints = new int[6];
int nPoints = 6;
for(int i = 0; i < nPoints; i++) {
xPoints[i] = (int)(xCenter + radius * Math.cos(Math.PI / 3 * i));
yPoints[i] = (int)(yCenter + radius * Math.sin(Math.PI / 3 * i));
}
// Create a Polygon object
Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
super.paintComponent(g);
// Draw the polygon
g.setColor(Color.RED);
g.drawPolygon(polygon);
}
}
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
public class DrawPolygon extends JFrame {
public DrawPolygon() {
add(new PolygonPanel());
}
/** Main method */
public static void main(String[] args) {
DrawPolygon frame = new DrawPolygon();
frame.setTitle("DrawPolygon");
frame.setSize(300, 200);
frame.setLocationRelativeTo(null); //Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
//Draw a polygon in the panel
class PolygonPanel extends JPanel {
protected void paintComponent(Graphics g) {
int xCenter = getWidth() / 2;
int yCenter = getHeight() / 2;
int radius = Math.min(getWidth(), getHeight()) / 2;
int[] xPoints = new int[6];
int[] yPoints = new int[6];
int nPoints = 6;
for(int i = 0; i < nPoints; i++) {
xPoints[i] = (int)(xCenter + radius * Math.cos(Math.PI / 3 * i));
yPoints[i] = (int)(yCenter + radius * Math.sin(Math.PI / 3 * i));
}
// Create a Polygon object
Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
super.paintComponent(g);
// Draw the polygon
g.setColor(Color.RED);
g.drawPolygon(polygon);
}
}
0 0
- DrawPolygon
- SWT:GC.drawPolygon
- CCDrawNode(是一个节点有drawDot drawSegment drawPolygon方法 可以类绘制点 线段 多边形--与drawing primitives不同 采用批渲染)
- 一个锁屏应用
- 我的blog第一天,谈谈心中的自己。
- Linux ./configure --prefix 选项的意义
- SRM 620
- 让网站内链为网站流量贡献价值
- DrawPolygon
- JS面向对象编程之对象
- UVA 297 Quadtrees( 数据结构,树)
- LA2797 - Monster Trap PSLG 线段闭合圈
- android 项目中设置背景图片
- 计算KL距离的几个例子
- 谢谢鱼团长和众位的盛情款待
- 我的GV电话设置经验
- nodejs jsdom模块安装