Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:请问一个jFreeChart曲线图的问题???急!!! [Re:wh_44448]
jackchengen





发贴: 16
积分: 0
于 2006-09-16 14:30 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
package monitor;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.util.LinkedList;

import javax.swing.BorderFactory;

import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;
import javax.swing.JFrame;

/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class HistoryPanel extends javax.swing.JPanel {
  private double grid = 12;

  private double baseX = grid;

  private int speedFactor = 6;

  private LinkedList list;

  private int total = 255;
  private MainFrame mf;

  /**
   * @param mf
   */
  public HistoryPanel(MainFrame mf) {
    this();
    this.mf = mf;
  }

  /**
   * Auto-generated main method to display this JPanel inside a new JFrame.
   */
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new HistoryPanel());
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    for (int i = 0; i < 100; i++) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      frame.repaint();
    }
  }

  public HistoryPanel() {
    super();
    initGUI();
    list=new LinkedList();
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  protected void paintComponent(Graphics g) {
    // TODO Auto-generated method stub
    super.paintComponentPresent;
    Graphics2D g2 = (Graphics2D) g;
    double leftX = 0;
    double topY = 0;
    double width = this.getWidth();
    double height = this.getHeight();
    int x_num = (int) ((width - baseX) / (int) grid);
    int y_num = (int) (height / (int) grid);

    g2.setColor(new Color(0, 150, 0));
    // draw y lines
    for (int i = 0; i <= x_num; i++) {
      Line2D line = new Line2D.Double(baseX + i * (width / x_num), topY,
          baseX + i * (width / x_num), height);
      g2.draw(line);
    }

    // draw x lines
    for (int i = 0; i <= y_num; i++) {
      Line2D line = new Line2D.Double(leftX, topY + i * (height / y_num),
          width, topY + i * (height / y_num));
      g2.draw(line);
    }

    g2.setColor(new Color(100, 255, 0));
    // draw history curvs
    if (list.size()>= 2) {
      double historybaseX = width - (list.size() - 1) * this.speedFactor;
      Object[] array = list.toArray();
      for (int i = 0; i < array.length-1; i++) {
        int data = ((Integer) array[i]).intValue();
        int nextdata = ((Integer) array[i+1]).intValue();
        Line2D line = new Line2D.Double(historybaseX, (total - data)
            * height / total, historybaseX + this.speedFactor,
            (total - nextdata) * height / total);
        g2.draw(line);
        historybaseX += this.speedFactor;
      }
    }

    baseX = baseX - grid / speedFactor;
    if (baseX == 0)
      baseX = grid;
  }

  private void initGUI() {
    try {
      setPreferredSize(new Dimension(400, 300));
      this.setBackground(new java.awt.Color(0, 0, 0));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void addData(int data){
    int historyNum=(int)(this.getWidth()/this.speedFactor)+1;
    if(list.size()==historyNum)
      list.removeFirst();
    list.add(new Integer(data));
  }
  /**
   * @param baseX
   * the baseX to set
   */
  public void setBaseX(double baseX) {
    this.baseX = baseX;
  }

  /**
   * @param grid
   * the grid to set
   */
  public void setGrid(double grid) {
    this.grid = grid;
  }

  /**
   * @return the baseX
   */
  public double getBaseX() {
    return baseX;
  }

  /**
   * @return the grid
   */
  public double getGrid() {
    return grid;
  }

  /**
   * @return the list
   */
  public LinkedList getList() {
    return list;
  }

}




话题树型展开
人气 标题 作者 字数 发贴时间
3757 请问一个jFreeChart曲线图的问题???急!!! wh_44448 36 2006-09-12 15:44
3149 Re:请问一个jFreeChart曲线图的问题???急!!! jackchengen 159 2006-09-16 14:29
3678 Re:请问一个jFreeChart曲线图的问题???急!!! jackchengen 4389 2006-09-16 14:30

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923