swing 绘制图表

由于JFreeChart在swing中不能动态刷新, 所以采用手工的方式来做


[img]http://dl.iteye.com/upload/attachment/521476/3dd50f95-3ef8-3d2a-b6ee-e1669c3ba5d3.jpg[/img]


package fiveGame;

import java.awt.BorderLayout;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Panel5 extends JPanel{
public static void main(String[] args) {
JFrame frame = new JFrame();
Panel5 p = new Panel5();
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
frame.setContentPane(p);
frame.setSize(443,552);
frame.setLayout(new BorderLayout());

frame.setVisible(true);
}

@Override
synchronized protected void paintComponent(Graphics g) {

int x = 20;
int y = 450;
int xDistance = 360;
int yDistance = 380;
int letterDistance = 12;

g.drawLine(x, y, x+xDistance, y);
g.drawLine(x, y, x, y-yDistance);

g.drawString(String.valueOf(yDistance), x, y-yDistance);
g.drawString(String.valueOf(0), x, y + letterDistance);

int j = yDistance;
for(int i=33, k=1; i<xDistance; i=i+xDistance/10, k++){

j=j - yDistance/10;

g.drawLine(x+i, y, x+i, y-j);
g.drawString(String.valueOf(j), x+i,y-j);
g.drawString(String.valueOf(k), x+i,y+letterDistance);
}

}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值