www.pudn.com > asm_java.zip > PolarShow.java
package asm;
import java.awt.event.*;
import java.util.Vector;
import java.awt.*;
/**
* Title: Artificial Stock Market
* Description: 人工模拟股市(来源:SFI的Swarm版本)的Java版本
* Copyright: Copyright (c) 2003
* Company: http://agents.yeah.net
* @author jake
* @version 1.0
*/
public class PolarShow extends Frame implements Runnable{
Panel view = new Panel();
Thread runner1;//定义独立线程
Graphics gra;//在一个面板view上画图
int cycles=100;//图中显示的横坐标数目
int cyclemax;//主程序中定义的历史数据最大长度
int originx=40;//画图区域原点的坐标
int originy=20;
int type;
int itemCount=9;
double maxvalue[];
public int nAgentIndex=0;
AsmModel local;//主程序的本地拷贝
Label label2 = new Label();
Choice choiceItem = new Choice();
public PolarShow(AsmModel pd,int type1) {
super("数据柱状图");
local=pd;
type=type1;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
view.setBackground(Color.white);
view.setBounds(new Rectangle(7, 25, 537, 316));
this.setBackground(Color.gray);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(WindowEvent e) {
this_windowOpened(e);
}
public void windowClosing(WindowEvent e) {
this_windowClosing(e);
}
});
choiceItem.addItem("股票需求量");
choiceItem.addItem("总财富");
choiceItem.addItem("股票份额");
choiceItem.addItem("现金量");
choiceItem.addItem("规则平均特定度");
choiceItem.addItem("预测量");
choiceItem.addItem("预测偏差");
choiceItem.addItem("预测系数a");
choiceItem.addItem("预测系数b");
label2.setText("查看项目:");
label2.setBounds(new Rectangle(11, 358, 66, 17));
choiceItem.setBounds(new Rectangle(73, 355, 99, 18));
maxvalue=new double[itemCount];
for(int i=0;imaxval){
maxval=values[i];
}
}
if(maxval>maxvalue[choiceItem.getSelectedIndex()]||maxval/maxvalue[choiceItem.getSelectedIndex()]<0.01){
maxvalue[choiceItem.getSelectedIndex()]=maxval;
}
int width=517-originx-25;
int height=316-originy;
//清空画图区域
gra.clearRect(0,0,517,316);
//设定原点坐标
int x=0,y=0,y0=height-originy;
//对设定的要画的横坐标点数循环
for(int i=0;i=5)txt=txt.substring(0,5);
gra.drawString(txt,x3-40,y3+10);
}
super.paint(g);
}
void btnRefresh_actionPerformed(ActionEvent e) {
repaint();
}
public void stop() {
if (runner1!=null)
{
// running = false;
runner1.stop();
runner1=null;
}
}
public void run() {
while(true){
repaint();
try{Thread.sleep(1000);}catch(InterruptedException e){};
}
}
}