各位高手,请问怎么把下面这个程序改成applet

ljx243644128 2011-05-25 04:41:55
以便能在web上显示,万分感谢!

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class RealTimeChart extends ChartPanel implements Runnable
{
private static TimeSeries timeSeries;
private long value=0;

public RealTimeChart(String chartContent,String title,String yaxisName)
{
super(createChart(chartContent,title,yaxisName));
}

private static JFreeChart createChart(String chartContent,String title,String yaxisName){
//创建时序图对象
timeSeries = new TimeSeries(chartContent,Millisecond.class);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeSeries);
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title,"time(minutes)",yaxisName,timeseriescollection,true,true,false);
XYPlot xyplot = jfreechart.getXYPlot();
//纵坐标设定
ValueAxis valueaxis = xyplot.getDomainAxis();
//自动设置数据轴数据范围
valueaxis.setAutoRange(true);
//数据轴固定数据范围 30s
valueaxis.setFixedAutoRange(30000D);

valueaxis = xyplot.getRangeAxis();
//valueaxis.setRange(0.0D,200D);

return jfreechart;
}

public void run()
{
while(true)
{
try
{
timeSeries.add(new Millisecond(), randomNum());
Thread.sleep(300);
}
catch (InterruptedException e) { }
}
}

private long randomNum()
{
// System.out.println((Math.random()*20+80));
return (long)(Math.random()*20+80);
}

public static void main(String[] args) {

JFrame frame=new JFrame("Test Chart");
RealTimeChart rtcp=new RealTimeChart("Random Data","Random","value");
frame.getContentPane().add(rtcp,new BorderLayout().CENTER);
frame.pack();
frame.setVisible(true);
(new Thread(rtcp)).start();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent windowevent)
{
System.exit(0);
}

});
}
}
...全文
72 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljx243644128 2011-05-25
  • 打赏
  • 举报
回复
静待各位高手指点
ljx243644128 2011-05-25
  • 打赏
  • 举报
回复
求助高手
ljx243644128 2011-05-25
  • 打赏
  • 举报
回复
jfreechart

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧