资源简介
用java画出任意八边形,次代码可以修改画出任意多边形,希望对java初学者有帮助!
代码片段和文件信息
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Polygon;
public class P138 extends Jframe{
public P138(){
add(new q());
}
public static void main(String []args){
P138 frame=new P138();
frame.settitle(“RRRRRR“);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
frame.setSize(400400);
frame.setVisible(true);
}
}
class q extends JPanel{
public q(){
super();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
int width=getWidth()/2;
int height=getHeight()/2;
int radius=(int)(Math.min(getWidth()getHeight())*0.4);
Polygon polygon=new Polygon();
polygon.addPoint(width+radiusheight);
polygon.addPoint((int)(width+radius*Math.cos(2*Math.PI/8))(int)(height-radius*Math.sin(2*Math.PI/8)));
polygon.addPoint((int)(width+radius*Math.cos(
- 上一篇:JAVA在服务器端和客户端传输图片和文件
- 下一篇:会议室预定系统java
评论
共有 条评论