ApplicationFrame详细简介

        import   org.jfree.ui.ApplicationFrame     是界面方面的类

       其实它就只是一个窗口类

      即public Frame(String title) throws HeadlessException

      下面贴出它的原代码

package org.jfree.ui;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

/**
 * A base class for creating the main frame for simple applications.  The frame listens for
 * window closing events, and responds by shutting down the JVM.  This is OK for small demo
 * applications...for more serious applications, you'll want to use something more robust.
 *
 * @author David Gilbert
 */
public class ApplicationFrame extends JFrame implements WindowListener {

    /**
     * Constructs a new application frame.
     *
     * @param title  the frame title.
     */
    public ApplicationFrame(final String title) {
        super(title);
        addWindowListener(this);
    }

    /**
     * Listens for the main window closing, and shuts down the application.
     *
     * @param event  information about the window event.
     */
    public void windowClosing(final WindowEvent event) {
        if (event.getWindow() == this) {
            dispose();
            System.exit(0);
        }
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowClosed(final WindowEvent event) {
        // ignore
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowActivated(final WindowEvent event) {
        // ignore
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowDeactivated(final WindowEvent event) {
        // ignore
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowDeiconified(final WindowEvent event) {
        // ignore
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowIconified(final WindowEvent event) {
        // ignore
    }

    /**
     * Required for WindowListener interface, but not used by this class.
     *
     * @param event  information about the window event.
     */
    public void windowOpened(final WindowEvent event) {
        // ignore
    }

}

     

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用ApplicationFrame实现jfreechart动态折线图,需要遵循以下步骤: 1. 导入jfreechart库。 2. 创建一个ApplicationFrame实例,它将包含动态折线图。 3. 创建一个TimeSeries对象,它将存储图表中的数据。 4. 创建一个TimeSeriesCollection对象,它将包含所有TimeSeries对象。 5. 创建一个ChartPanel对象,它将显示动态折线图。 6. 创建一个JFreeChart对象,它将与ChartPanel关联。 7. 设置折线图的样式和属性。 8. 创建一个Timer对象,它将定期更新折线图。 9. 在Timer对象的ActionListener方法中,添加新数据到TimeSeries对象中,并刷新折线图。 下面是一个简单的示例代码,演示如何使用ApplicationFrame实现jfreechart动态折线图: ```java import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.Timer; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.xy.XYDataset; public class DynamicLineChart extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private TimeSeries series; private Timer timer; public DynamicLineChart(final String title) { super(title); this.series = new TimeSeries("Random Data"); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(500, 270)); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); setContentPane(content); this.timer = new Timer(1000, this); this.timer.start(); } private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart( "Dynamic Line Chart", "Time", "Value", dataset, true, true, false ); return result; } public void actionPerformed(final ActionEvent e) { final double factor = Math.random() * 0.1 + 0.95; final Millisecond now = new Millisecond(); this.series.add(new Millisecond(), Math.random() * factor); } public static void main(final String[] args) { final DynamicLineChart demo = new DynamicLineChart("Dynamic Line Chart"); demo.pack(); demo.setVisible(true); } } ``` 在这个示例中,我们创建了一个名为DynamicLineChart的类,它继承自JFrame,并实现了ActionListener接口,用于更新折线图。在构造函数中,我们创建了一个TimeSeries对象,将其添加到TimeSeriesCollection中,并将其与ChartPanel关联。我们还创建了一个定时器,每秒钟更新一次折线图。在ActionListener方法中,我们向TimeSeries对象中添加新数据,并使用ChartPanel对象的repaint()方法刷新折线图。最后,我们创建了一个DynamicLineChart对象,并调用它的pack()和setVisible()方法显示动态折线图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值