日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當前位置:雨林木風下載站 > 技術(shù)開發(fā)教程 > 詳細頁面

java繪制一個成交量的統(tǒng)計圖

java繪制一個成交量的統(tǒng)計圖

更新時間:2022-05-14 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

在前面,我用多線程寫了一個繪制了股票K線圖的程序.這里我再通過繪制一個成交量的統(tǒng)計圖說明對鼠票事件的應(yīng)用.這里我們要傳入幾個參數(shù):
<applet code="sellhis.class" Archive="sellhis.jar" width="640" height="400">
<Param name="itemmonth" value="200201">
<Param name="itemcode" value="00002,00014,00019,00023,00041,00102,00113,00114,
00129,00132,00142,00146,00179,00203,00213,00223,00341">
<Param name="itemval" value="272950,193950,1015600,142700,1618500,671650,
2453300,630150,28375,1827660,7700,75700,27375,3375600,47500,17500,17500">
<Param name="itempce" value="219,156,817,114,2302,540,1974,507,22,
1471,6,60,22,4717,38,114,14">
</applet>
查看演示
sellhis.java源程序如下:
import java.awt.*;
import java.applet.*;
import java.awt.font.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.util.*;



public class sellhis extends Applet{
  static int Len;
  int leftMargine=50;
  int rightMargine=20;
  int topMargine=80;
  int buttomMargine=20;
  int width,height,w,h;
  int minStickLength=3;  //坐標的短刻度
  int majStickLength=8;   //坐標的長刻度
  int minStick=10;
  int majStick;
  String title;
  String xTitle="股票代碼";
  String xCode[];
  float yData[],xPce[];
  String MaxPce;
  boolean Mouse_Move;
  int x0,y0,X,Y,hx,hy;
  Label label[]=new Label[3];
  boolean mouse_move=false;
  public void init() {
    width=this.getBounds().width;
    height=this.getBounds().height;
    w=width-leftMargine-rightMargine;
    h=height-topMargine-buttomMargine;
    setSize(width,height);
    Color bc=new Color(229,229,229);
    setBackground(bc);
    setLayout(null);
    for(int I=0;I<3;I++){
      label[I]=new Label();
      label[I].setForeground(Color.blue);
      this.add(label[I]);
      if(I==0)
        label[I].reshape(75,topMargine-25,60,15);
      if(I==1)
        label[I].reshape(230,topMargine-25,80,15);
      if(I==2)
        label[I].reshape(505,topMargine-25,60,15);
    }
    try{
      title=getTitle(getParameter("itemmonth"));
    }
    catch(Exception e){
      System.out.println("Param itemmonth error!");
   System.out.println(e);
}
    try{
      xCode=Subicode(getParameter("itemcode"));
      Len=xCode.length;
      hx=w/Len;
    }
    catch(Exception e){
      System.out.println("Param itemcode error!");
   System.out.println(e);
}
    try{
      yData=Substr(getParameter("itemval"));
    }
    catch(Exception e){
      System.out.println("Param itemval error!");
   System.out.println(e);
}
    try{
      xPce=Substr(getParameter("itempce"));
      MaxPce=getMaxVal(xPce);
      majStick=Integer.parseInt(MaxPce.substring(0,1))+2; //取最大pce的最大整數(shù)
    }
    catch(Exception e){
      System.out.println("Param itempce error!");
   System.out.println(e);
}
    try{
      addMouseListener(new MouseAdapter(){
        public void mouseReleased(MouseEvent evt){//檢測釋放鼠標按鍵事件
          setCursor(Cursor.getDefaultCursor());
          Point ioc=evt.getPoint();
          X=ioc.x;         //把當前座標傳遞給另一線程
          Y=ioc.y;
          //repaint();
        }
      });
   addMouseMotionListener(new MouseMotionAdapter(){
        public void mouseDragged(MouseEvent evt){
          Point ioc=evt.getPoint();
          if((ioc.x>leftMargine & ioc.x< w+leftMargine) & (ioc.y >topMargine & ioc.y< h+topMargine))
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          else
            setCursor(Cursor.getDefaultCursor());
        }
        public void mouseMoved(MouseEvent evt){   //檢測鼠標移動事件
          Point ioc=evt.getPoint();
          X=ioc.x;
          Y=ioc.y;
          Graphics gten;
          gten=getGraphics();
          gten.setXORMode(Color.white);
          gten.setColor(Color.blue);
          int Axsis;


          if(ioc.x >leftMargine & ioc.x< w+leftMargine & ioc.y>topMargine & ioc.y<h+topMargine){
            try{
               Axsis=(X-leftMargine)/hx;        //設(shè)定橫座標范圍
                //在以下區(qū)域內(nèi),把鼠標當前橫座標處的各種股票參數(shù)顯示在相應(yīng)的標簽上
                 label[0].setText(xCode[Axsis]);
                 label[1].setText(Float.toString(yData[Axsis]));
                 float pcent=(xPce[Axsis]/100);
                 label[2].setText(Float.toString(pcent));
            }
            catch(Exception err){
            }
            try{
              if(y0 >topMargine & y0< h+topMargine)
                gten.drawLine(leftMargine,y0,w+leftMargine,y0);
              if(Y >topMargine & Y< h+topMargine)
                gten.drawLine(leftMargine,Y,w+leftMargine,Y);
              if(x0 >leftMargine & x0< w+leftMargine)
                gten.drawLine(x0,topMargine,x0,h+topMargine);
              if(X >leftMargine & X< w+leftMargine)
                gten.drawLine(X,topMargine,X,h+topMargine);
              x0=X;
              y0=Y;
            }
            finally{
              gten.dispose();
            }
          }
        }
      });
}
catch(Exception e)
{
  System.out.println("sellhis construct add mouse listener error!");
  System.out.println(e);
}
  }
  public void paint(Graphics g){
    try{
      g.drawString("股票代碼:",20,topMargine-15);
      g.drawString("賣空成交金額:",150,topMargine-15);
      g.drawString("賣空成交金額占總賣空成交金額%:",320,topMargine-15);



      g.drawRect(leftMargine,topMargine,w,h); //矩形方框



      int x0,y0,x1,y1,dy;
      int totalStick=(majStick-1)*minStick;
      x0=leftMargine;
      dy=h/((majStick-1)*minStick);
      for(int I=1;I<=totalStick;I++){
        y0=height-buttomMargine-I*dy;
        y1=y0;
        x1=x0-minStickLength;
        if(I%minStick==0){
          x1=x0-majStickLength;
          g.drawString(""+((I)/minStick)+"0%",x1-25,y0+5);    //y軸刻度數(shù)字
        }
        g.drawLine(x0,y0,x1,y1);  //y軸刻度標
      }
      for(int I=0;I<Len;I++){
        x0=leftMargine+I*hx;
        hy=(int)((xPce[I]/100)*(h/((majStick-1)*10)));
        y0=height-buttomMargine-hy;
        float pcent=(xPce[I]/100);
        Color pceCololr=new Color(153,0,153);
        g.setColor(pceCololr);
        g.setFont(new Font("Times New Roman",Font.PLAIN,11));
        g.drawString(Float.toString(pcent),x0,y0-5);//在柱狀圖上繪制%
        if(I%2==0)
          g.setColor(Color.orange);
        else
          g.setColor(Color.red);
        g.fillRect(x0,y0,hx,hy);  //繪制柱狀圖
        //g.setColor(Color.red);  //繪制股票代碼
        //g.setFont(new Font("Times New Roman",Font.PLAIN,10));
        //g.drawString(""+xCode[I],x0,height-topMargine+40);
      }
      Color titleColor=new Color(0,64,128);
      g.setColor(titleColor);
      g.setFont(new Font("monospaced",Font.BOLD,20));
      g.drawString(title,190,40);
    }
    catch(Exception e){
      System.out.println("sellhis paint error.");
      System.out.println(e);
    }
  }
  public static float[] Substr(String str){
    int I=0;
    StringTokenizer st = new StringTokenizer(str,",");
    int len=st.countTokens();
    float[] val=new float[len];
    while(st.hasMoreTokens()) {
      val[I]=Integer.parseInt(st.nextToken());
      I++;
    }
    return val;
  }
  public static String[] Subicode(String str){
    int I=0;
    StringTokenizer st = new StringTokenizer(str,",");
    int len=st.countTokens();
    String[] val=new String[len];
    while(st.hasMoreTokens()) {
      val[I]=st.nextToken();
      I++;
    }
    return val;
  }
  public static String getMaxVal(float[] Maxval){
    int I;
    float result;
    result=Maxval[0];
    for(I=0;I<Maxval.length;I++){
      if(result<Maxval[I])
        result=Maxval[I];
    }
    return Float.toString(result);
  }
  public String getTitle(String str){
    String title;
    title=str.substring(0,4)+"年"+str.substring(4,6)+"月賣空股票統(tǒng)計";
    return title;
  }
  public int getLeftMargine(){
    return leftMargine;
  }
  public int getButtomMargine(){
    return buttomMargine;
  }
  public void setLeftMargine(int leftMargine){
    this.leftMargine=leftMargine;
  }
  public void setButtomMargine(int buttomMargine){
    this.buttomMargine=buttomMargine;
  }
}

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統(tǒng)下載排行

主站蜘蛛池模板: 尤物国产在线精品福利一区 | 国产或人精品日本亚洲77美色 | 夜夜骑天天操 | av线上观看 | 在线不卡视频 | xxxx国产 | 色琪琪原网站亚洲香蕉 | 国产成人毛片亚洲精品不卡 | 亚洲狠狠婷婷综合久久久久网站 | 日本成人资源 | 亚洲精品亚洲人成毛片不卡 | 日本乱理伦中文三区 | 综合久| 最新国产大片高清视频 | 精品国产96亚洲一区二区三区 | 91视频在| 成人观看视频又黄又免费 | 欧美极品xxx| 久久日本精品久久久久久 | 亚欧成人毛片一区二区三区四区 | 天天舔天天色 | 久久伊人中文字幕有码 | 国产成人短视频在线观看免费 | 日韩 欧美 国产 亚洲 制服 | 亚洲国产精品成人午夜在线观看 | 成年人在线观看视频网站 | 日黄网站 | 国产人免费人成免费视频 | 国产成人久久蜜一区二区 | 国产精品久久亚洲一区二区 | 久久精品免费全国观看国产 | 欧美激情一区二区亚洲专区 | www亚洲成人 | 日本四虎影视 | 99久热国产精品视频尤物不卡 | 福利片成人午夜在线 | 欧美日韩国产最新一区二区 | 国产精品高清一区二区三区不卡 | 久久久久国产一级毛片高清版 | 日韩精品一区二区三区在线观看l | 91综合久久婷婷久久 |