62,614
社区成员
发帖
与我相关
我的任务
分享
/*
* MainFrame.java
*
* Created on 2007年10月24日, 下午5:04
*/
package pentacle2;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.math.*;
/**
*
* @author qhj
*/
public class MainFrame extends javax.swing.JFrame {
/** Creates new form MainFrame */
public MainFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// 变量声明 - 不进行修改
// 变量声明结束
public void paint(Graphics g) {
super.paint(g);
int rectHeight,y ;
int rectWidth, x ;
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(Color.black);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle rectWindow = getContentPane().getBounds(); //窗口的大小
Point2D.Double origin = new Point2D.Double(rectWindow.x+rectWindow.width / 2f,
rectWindow.y+rectWindow.height / 2f);//五角星的原点
PolarCoordinate plc = new PolarCoordinate(origin);//新建个极座标系
double rad = (rectWindow.x < rectWindow.y)?(rectWindow.width * 0.6)/2.0:(rectWindow.height * 0.6)/2.0; //五角星的外接圆半径
Point2D.Double points[] = new Point2D.Double[5];
double angle = 0;
for(int i = 1 ; i <=5; i++ )
{
points[i-1] = (Point2D.Double) plc.toCartesianWithAngle(rad, angle);
angle += 360.0/5;
}
GeneralPath pentacle = new GeneralPath(GeneralPath.WIND_NON_ZERO,5);
pentacle.moveTo(points[0].getX(), points[0].getY());
pentacle.lineTo(points[3].getX(), points[3].getY());
pentacle.lineTo(points[1].getX(), points[1].getY());
pentacle.lineTo(points[4].getX(), points[4].getY());
pentacle.lineTo(points[2].getX(), points[2].getY());
pentacle.closePath();
g2.setStroke(new BasicStroke(2.0f));
x = (int)pentacle.getBounds().getX();
y = (int)pentacle.getBounds().getX();
rectWidth = (int)pentacle.getBounds().getWidth();
GradientPaint redtowhite = new GradientPaint(x,y,Color.RED,x+rectWidth-5, y,Color.white);
g2.setPaint(redtowhite);
g2.fill(pentacle);
}
}
class PolarCoordinate
{
private Point2D.Double origin = new Point2D.Double();
public PolarCoordinate(Point2D.Double origin)
{
this.origin.setLocation(origin);
}
public PolarCoordinate(double x, double y)
{
origin.setLocation(x, y);
}
public Point2D toCartesianWithAngle(double radius, double angleInAngle)
{
Point2D.Double result = new Point2D.Double();
return toCartesianWithRadians(radius, angleInAngle*Math.PI/180);
}
public Point2D toCartesianWithRadians(double radius, double angleInRadians)
{
Point2D.Double result = new Point2D.Double();
result.setLocation(origin.getX()+Math.cos(angleInRadians)*radius, origin.getY()+Math.sin(angleInRadians)*radius);
return result;
}
}
import java.util.*;
public class Scan {
public static void main(String[] args) {
Scanner scann = new Scanner(System.in);
int i = scann.nextInt();
System.out.print(i);
}
}