※ 引述《dichotomyptt ((  ̄ c ̄)y▂ξ)》之铭言:
: 如题
: 我想要请问一下 有没有K棒制作程式
: 可以 自由填入X轴 Y轴
: 跟下面的成交量 有均线更佳
: 谢谢^^
很久以前找到的程式码,原作好像不是java,我改成写成java,并加上注解
import java.awt.*;
import java.awt.event.*;
public class stock extends Frame
{
char [] dashline=new char [200];
int span=6; //宽的间距
int height=500; //图高
int start=120; //X座标起点
int width=8; //长方形宽
int end=750; //X座标终点
int height_span=50; //高的间距
int max; //最大值
int min; //最小值
int scale=0;
int ss;
int es;
int hs;
int ls;
int xL;
int totspan;
int stock_data[][]=
{
//开盘, 收盘, 当天最高, 当天最低
{313 ,331 ,333 ,311 },
{324 ,330 ,335 ,323 },
{335 ,329 ,337 ,328 },
{329 ,341 ,342 ,327 },
{341 ,328 ,343 ,328 },
{328 ,318 ,330 ,315 },
{320 ,321 ,326 ,320 },
{319 ,321 ,327 ,315 },
{325 ,335 ,335 ,323 },
{344 ,335 ,348 ,335 },
{338 ,358 ,358 ,333 },
{360 ,351 ,365 ,350 },
{355 ,346 ,356 ,345 },
{347 ,356 ,360 ,346 },
{356 ,353 ,362 ,352 },
{357 ,345 ,360 ,342 },
{344 ,338 ,348 ,338 },
{333 ,324 ,336 ,318 },
{332 ,321 ,334 ,321 },
{316 ,326 ,328 ,315 },
{328 ,318 ,332 ,318 },
{324 ,330 ,330 ,318 },
{332 ,329 ,333 ,327 },
{334 ,326 ,336 ,326 },
{324 ,318 ,324 ,318 },
{317 ,321 ,323 ,316 },
{326 ,326 ,329 ,324 },
{338 ,328 ,340 ,328 },
{333 ,333 ,337 ,330 },
{335 ,334 ,335 ,330 },
{334 ,331 ,338 ,330 },
{331 ,322 ,332 ,321 },
{323 ,325 ,327 ,316 },
{324 ,318 ,324 ,317 },
{318 ,310 ,322 ,310 },
{313 ,296 ,317 ,293 },
{295 ,302 ,302 ,291 },
{288 ,286 ,290 ,283 }
};
public stock()
{
super("股票行情");
setSize(800,600);
setResizable(false); //不可改变大小
addWindowListener(new WindowAdapter() //匿名的视窗事件调适器
{
public void windowClosing(WindowEvent e) //视窗关闭事件
{
dispose(); // 释放视窗所占用的资源, 并关闭视窗
}
});
for(int i=0;i<200;i++)
dashline[i]='-';
}
public void paint (Graphics g)
{
int i,j,k;
max = 0;
for(j=0;j<stock_data.length;j++)
{
if (stock_data[j][2]>max) //求最大值
max = stock_data[j][2];
}
min = max;
for(j=0;j<stock_data.length;j++)
{
if (stock_data[j][3]<min) //求最小值
min = stock_data[j][3];
}
scale=height/(max-min);
g.drawString("max=" + max,110,60); // 写出最大值
g.drawString("min=" + min,110,80); // 写出最小值
g.drawString("height/max-min=" + scale,110,120); //写出刻度
for( k=0;k<10;k++) // 分10个横线
{
int number=min+(scale*k);
g.drawChars(dashline,0,200,
0,height-(k*height_span)); // 画出横的虚线
g.drawString(k + "->" + number ,
start - 70,
height-((height_span*k)+5)); //横线代表的数值
}
for(i=0;i<stock_data.length;i++)
{
ss = stock_data[i][0]; // 开盘
es = stock_data[i][1]; // 收盘
hs = stock_data[i][2]; // 当天最高
ls = stock_data[i][3]; // 当天最低
xL= start+(width*i);
totspan = span*(i-1);
if(es>ss) //收盘大于开盘
{
g.setColor(Color.red);
g.fillRect(xL+totspan,
height-((es-min)*scale),
width,
(es-ss)*scale);
g.setColor(Color.black);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
}
else if(ss>es) //开盘大于收盘
{
g.setColor(Color.green);
g.fillRect(xL+totspan,
height-((ss-min)*scale),
width,
(ss-es)*scale);
g.setColor(Color.black);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
}
else //开盘等于收盘
{
g.setColor(Color.black);
g.fillRect(xL+totspan,
height-((ss-min)*scale),
width,
1);
g.drawLine((xL*2+totspan+(span*i))/2,
height-((hs-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((ss-min)*scale));
g.drawLine((xL*2+totspan+(span*i))/2,
height-((ls-min)*scale),
(xL*2+totspan+(span*i))/2,
height-((es-min)*scale));
}
}
}
}