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入门到精通教程
查看: 482|回复: 0

[Swing学习]Java Applet Web图表实例:带徽标的垂直柱状图

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

    [LV.1]初来乍到

    发表于 2014-10-29 23:55:45 | 显示全部楼层 |阅读模式
    这是这个Applet的HTML文件:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <BODY>
    <APPLET CODE = "LogoVBar.class" WIDTH = "600" HEIGHT = "500">
    </APPLET>
    </BODY>
    </HTML>

    下面的画垂直柱状图的源码:
       
    1. // Fig. 3.02_01: LogoVBar.java
    2. // Java Applet Web图表实例3:带Java徽标的Web图表

    3. import java.awt.*; // 引入 java.awt包中所有的类
    4. import javax.swing.*; // 引入 javax.swing包中所有的类
    5. public class LogoVBar extends JApplet
    6. {
    7.   Image logoJPG;
    8.   Image offImage;
    9.   Graphics offGraphics;
    10.   int appletWidth = 600, appletHeight = 500;
    11.   int bookSales[] = new int[5];
    12.   String bookTitle[] =
    13.   {
    14.     "Python", "JAVA", "C#", "Perl", "PHP"
    15.   };
    16.   // 初始化颜色数组
    17.   Color color[] =
    18.   {
    19.     new Color(99, 99, 0), Color.GREEN, Color.YELLOW, Color.RED, Color.BLUE
    20.   };
    21.   // 初始化绘图缓冲区
    22.   public void init()
    23.   {
    24.     offImage = createImage(appletWidth, appletHeight);
    25.     offGraphics = offImage.getGraphics();
    26.     for (int i = 0; i < bookSales.length; i++)
    27.     {
    28.       bookSales[i] = 1+(int)(Math.random() * 100);
    29.     }
    30.     logoJPG = getImage(getDocumentBase(), "javaLogo.jpg");
    31.   }
    32.   public void paint(Graphics g)
    33.   {
    34.     // 调用父类的 paint 方法
    35.     super.paint(g);
    36.     update(g);
    37.   } // paint 方法结束
    38.   public void update(Graphics g)
    39.   {
    40.     // 绘制标题区域
    41.     offGraphics.drawImage(logoJPG, 100, 0, this);
    42.     offGraphics.setColor(Color.BLACK);
    43.     offGraphics.setFont(new Font("方正粗宋简体", Font.BOLD, 30));
    44.     offGraphics.drawString("带Java徽标的Web图表", 135, 40);
    45.     // 绘制代表销售量的10条直线
    46.     offGraphics.setFont(new Font("SansSerif", Font.PLAIN, 12));
    47.     int salesValue = 0;
    48.     for (int i = 418; i > 0; i -= 38)
    49.     {
    50.       offGraphics.setColor(Color.BLACK);
    51.       offGraphics.drawString("" + salesValue, 40, (i + 27));
    52.       offGraphics.setColor(Color.LIGHT_GRAY);
    53.       offGraphics.drawLine(80, (i + 27), 520, (i + 27));
    54.       salesValue += 10;
    55.     }
    56.     // 绘制实心矩形       
    57.     int drawHigh = 0;
    58.     for (int i = 0; i < bookTitle.length; i++)
    59.     {
    60.       offGraphics.setColor(color[i]);
    61.       drawHigh = (int)(Math.ceil(bookSales[i] * 3.8));
    62.       offGraphics.fill3DRect(110+i * 80, 445-drawHigh, 50, drawHigh, true);
    63.       offGraphics.setColor(Color.BLACK);
    64.       offGraphics.drawString(bookTitle[i], 110+i * 80, 465);
    65.     }
    66.     // 绘制坐标系
    67.     offGraphics.setColor(Color.BLACK);
    68.     offGraphics.drawLine(80, 40, 80, 445);
    69.     offGraphics.drawLine(80, 445, 550, 445);
    70.     // 绘制坐标系说明
    71.     offGraphics.setFont(new Font("黑体", Font.BOLD, 16));
    72.     offGraphics.drawString("销售量", 20, 50);
    73.     offGraphics.drawString("编程书籍", 500, 465);
    74.     // 输出缓冲区图像
    75.     g.drawImage(offImage, 0, 0, null);
    76.   }
    77. } //  LogoVBar 类结束
    复制代码
    /*************************************************************
       
    (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓). *
       
    * All Rights Reserved. *
       
    * *
       
    * DISCLAIMER: The authors of this code have used their *
       
    * best efforts in preparing the code. These efforts include the *
       
    * development, research, and testing of the theories and programs *
       
    * to determine their effectiveness. The authors and publisher make *
       
    * no warranty of any kind, expressed or implied, with regard to these *
       
    * programs or to the documentation contained in these codes. The authors *
       
    * shall not be liable in any event for incidental or consequential *
       
    * damages in connection with, or arising out of, the furnishing, *
       
    * performance, or use of these programs. *
       
    ****************************************************************/
       
      
       
       

         
       

         
       
      
      
      
       
      
      

      
      
       
       

         
       

         
       
      



    源码下载:http://file.javaxxz.com/2014/10/29/235545328.zip
    回复

    使用道具 举报

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

    本版积分规则

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

    GMT+8, 2025-2-26 01:12 , Processed in 0.346509 second(s), 46 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

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