Java 2D 화면 처리

1964 단어 2DJava
Java 2D 화면 처리가 수행되었습니다.
처리 내용
수직·가로·사선
둥글다
타원

코드
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 J3D extends JPanel{

    public static void main(String[] args){
    JFrame frame = new JFrame();

    J3D app = new J3D();
    frame.getContentPane().add(app);

    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.draw(new Line2D.Double(200,0,200,400));
    g2.draw(new Line2D.Double(0,200,400,200));

    drawCircle(g2);
    drawEllipse(g2);
    for(int i = 0;i < 400; i++){
        g2.draw(new Line2D.Double(0 - (x * -i) ,400 - (y * i),200 - (x * -i),200 - (y * i)));
    }

    g.setColor(Color.blue);
   // g.drawString("Hello Java2D", 10, 50);
  }
  public void drawCircle(Graphics2D g2){
      double x , y , cx = 200, cy = 200, r = 100;
      for(int i = 0; i < 820; i++){
          x = r * Math.sin(i) + cx;
          y = r * Math.cos(i) + cy;
          g2.draw(new Line2D.Double(x, y, x + 0.1, y + 0.1));
      }
  }
  public void drawEllipse(Graphics2D g2){
      double x , y , cx = 200, cy = 200, r = 100;
      for(int i = 0; i < 820; i++){
          x = r * Math.sin(i) + cx;
          y = r * Math.cos(i) / 2 + cy;
          g2.draw(new Line2D.Double(x, y, x + 0.1, y + 0.1));
      }
  }
}
운영 환경
・Mac version 10.2
・eclipse

좋은 웹페이지 즐겨찾기