コード
package J3D;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.Line2D;
import java.awt.Color;
public class J3D2 extends JPanel{
public static void main(String[] args){
JFrame frame = new JFrame();
J3D2 app = new J3D2();
frame.getContentPane().add(app);
frame.setBackground(Color.BLACK);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 400, 400);
frame.setTitle("あいうえお");
frame.setVisible(true);
Insets insets = frame.getInsets();
frame.setSize(400 + insets.left + insets.right,
400 + insets.top + insets.bottom);
}
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D)g;
int x = 1,y = 1;
g2.setColor(Color.BLUE);
g2.draw(new Line2D.Double(200,0,200,400));
g2.draw(new Line2D.Double(0,200,400,200));
drawCircle(g2);
}
public void drawCircle(Graphics2D g2){
double x , y , cx = 200, cy = 200, r = 100;
for(int i = 0; i < 12; i++){
x = r * Math.sin(Math.toRadians(30*i)) + cx;
y = r * Math.cos(Math.toRadians(30*i)) + cy;
g2.setColor(Color.GREEN);
g2.draw(new Line2D.Double(x, y, x + 0.1, y + 0.1));
}
}
}
実行環境
・Mac versin 10.10.2
・eclipse