Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 479|回复: 0

[Swing学习]蒙娜丽莎的微笑(JAVA代码绘制)

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-11-13 23:59:42 | 显示全部楼层 |阅读模式
    使用java画出蒙娜丽莎的微笑!ml.rar文件:需要读取的颜色值文件,可用写字板程序打开。
    1. /*
    2. * To change this template, choose Tools | Templates
    3. * and open the template in the editor.
    4. */
    5. import java.awt.Color;
    6. import java.awt.Frame;
    7. import java.awt.Graphics;
    8. import java.awt.event.WindowAdapter;
    9. import java.awt.event.WindowEvent;
    10. import java.awt.event.WindowListener;
    11. import java.io.BufferedReader;
    12. import java.io.File;
    13. import java.io.FileReader;
    14. import java.io.IOException;
    15. import java.util.ArrayList;
    16. import java.util.List;
    17. import java.util.logging.Level;
    18. import java.util.logging.Logger;
    19. import javax.swing.JFrame;
    20. /**
    21. *
    22. * @author Administrator
    23. */
    24. public class PaintMonaLisa extends JFrame {
    25.    private int x, y, R, G, B, w, h;
    26.    private Color color;
    27.    private int count;
    28.    private int i;
    29.    private List< String> list = new ArrayList< String>();
    30.    public PaintMonaLisa() {
    31.      this.setSize(600, 550);
    32.      this.setBackground(Color.BLACK);
    33.      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    34.      this.setTitle("Java画蒙娜丽莎的微笑  QQ:909854136  开源中国: @hoodoo");
    35.      this.setResizable(false);
    36.      this.setLocationRelativeTo(null);
    37.    }
    38.    @Override
    39.    public void paint(Graphics g) {
    40.         color = new Color(R, G, B);
    41.         g.setColor(color);
    42.         g.fillRect(x+50, y+50, w, h);
    43.         if (i < count){
    44.            changeNextPoint(list.get(i));
    45.         }
    46.    }
    47.    public void readFileInfo(String path) {
    48.         File file = new File(path);
    49.         try {
    50.            BufferedReader bw = new BufferedReader(new FileReader(file));
    51.            String line = null;
    52.            while ((line = bw.readLine()) != null) {
    53.              list.add(line);
    54.            }
    55.           bw.close();
    56.         } catch (IOException e) {
    57.            e.printStackTrace();
    58.         }
    59.         count=list.size();
    60.         System.out.println(count);
    61.     }
    62.    private void changeNextPoint(String temp) {
    63.        String[] s = temp.split("x");
    64.        x = Integer.parseInt(s[0]);
    65.        y = Integer.parseInt(s[1]);
    66.        w = Integer.parseInt(s[2]);
    67.        h = Integer.parseInt(s[3]);
    68.        R = Integer.parseInt(s[4].substring(0, 2), 16);
    69.        G = Integer.parseInt(s[4].substring(2, 4), 16);
    70.        B = Integer.parseInt(s[4].substring(4, 6), 16);
    71.       try {
    72.         Thread.sleep(1);
    73.       } catch (InterruptedException ex) {
    74.       }
    75.         i++;
    76.         repaint();
    77.     }
    78.     public static void main(String[] args) {
    79.       final PaintMonaLisa s = new PaintMonaLisa();
    80.       s.readFileInfo("ml");
    81.       s.open();
    82.      }
    83.      private void open() {
    84.         this.setVisible(true);
    85.      }
    86. }
    87. 直接运行:如下图。
    复制代码


       
         
         
          
          

            
          

            
          
         
       

      


    源码下载:http://file.javaxxz.com/2014/11/13/235911843.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-2-25 07:46 , Processed in 0.475924 second(s), 46 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表