zoukankan      html  css  js  c++  java
  • java2D

    计算机图形学来日再战:(先立一个flag)

    package com.java2d;
    
    /**
     * 实现进行几何变换的圆与字符
     * @author Administrator
     */
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    
    import javax.swing.JApplet;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Test1 extends JApplet {
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.setTitle("Hello 2D");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JApplet applet = new Test1();
            applet.init();
            frame.getContentPane().add(applet);
            frame.pack();
            frame.setVisible(true);
        }
    
        // 重写初始化函数
        public void init() {
            JPanel panel = new Hello();
            getContentPane().add(panel);
        }
    
        // 定义一个hello类
        class Hello extends JPanel {
            public Hello() {
                setPreferredSize(new Dimension(640, 480));
            }
    
            // 重写组件绘制函数
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g;
                g2.setColor(Color.blue);
                Ellipse2D e = new Ellipse2D.Double(-100, -50, 200, 100);
                AffineTransform tr = new AffineTransform();
                tr.rotate(Math.PI / 6.0);// 设置旋转变换
                Shape shape = tr.createTransformedShape(e);
                g2.translate(300, 300);
                g2.scale(2, 2);
                g2.draw(shape);
                g2.drawString("Hello 2D", 0, 0);
            }
        }
    }
    View Code

     修改后:

    package com.java2d;
    
    /**
     * 实现进行几何变换的圆与字符
     * @author Administrator
     */
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    
    import javax.swing.JApplet;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Test1 extends JApplet {
        public static void main(String[] args) {
            JApplet applet = new Test1();
        }
        public Test1(){
            JFrame frame = new JFrame();
            frame.setTitle("Hello 2D");
            this.init();
            frame.getContentPane().add(this);
            frame.pack();
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    
        // 重写初始化函数
        public void init() {
            JPanel panel = new Hello();
            getContentPane().add(panel);
        }
    
        // 定义一个hello类
        class Hello extends JPanel {
            public Hello() {
                setPreferredSize(new Dimension(640, 480));
            }
    
            // 重写组件绘制函数
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g;
                g2.setColor(Color.blue);
                Ellipse2D e = new Ellipse2D.Double(-100, -50, 200, 100);
                AffineTransform tr = new AffineTransform();
                tr.rotate(Math.PI / 6.0);// 设置旋转变换
                Shape shape = tr.createTransformedShape(e);
                g2.translate(300, 300);
                g2.scale(2, 2);
                g2.draw(shape);
                g2.drawString("Hello 2D", 0, 0);
            }
        }
    }
    View Code
  • 相关阅读:
    Regex一些基本的方法
    正则表达式中特殊字符的含义
    demo_36 收藏与点赞功能实现_02
    demo_36 收藏与点赞功能实现_01
    demo_35 关注作者_02 关注作者功能实现
    demo_35 关注作者_01 云函数实现
    demo_34 评论内容实现_6 实现对子回复的回复
    demo_34 评论内容实现_5 对回复的回复的逻辑实现并渲染到页面
    demo_34 评论内容实现_4 实现对评论的评论
    demo_34 评论内容实现_3 从数据库加载评论
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10839963.html
Copyright © 2011-2022 走看看