0

JFreeCharts を使用して xy 折れ線グラフのプロット プロセスをアニメーション化する方法はありますか? プログラムが各線分を描画して接続するのを見ることができるようにしたいです。

たとえば、これを TextArea に貼り付けると、「gtgtaaacaatatattggcg」と表示され、各線分が 1 つずつグラフ化されます。

前もって感謝します!:)

私のコードは以下の通りです:

import java.util.Scanner;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;

public class RandomWalkComplete extends Applet implements ActionListener
{
    Panel panel;
    TextArea textarea, outputArea;
    Button move,exit;
    String thetext;
    Scanner reader = new Scanner(System.in);
    String thetext2;
    Label instructions;

     int x,y;

    public void init() 
    {
        setSize(500,250); //set size of applet

         instructions=new Label("Paste the gene sequences in the " +
                "text field and press the graph button.");
        add(instructions);

        panel = new Panel();
        add(panel);
        setVisible(true);
        textarea= new TextArea(10,20);
        add(textarea);

        move=new Button("Graph");
        move.addActionListener(this);
        add(move);

        exit=new Button("Exit");
        exit.addActionListener(this);
        add(exit);
    }

    public void actionPerformed(ActionEvent e)
    {
        XYSeries series = new XYSeries("DNA Walk",false,true);

        x= 0; y = 0;
        series.add(x,y);

        if(e.getSource() == move)
        {
            thetext=textarea.getText(); //the text is the DNA bases pasted
            thetext=thetext.replaceAll(" ",""); //removes spaces
            thetext2 = "";

            for(int i=0; i<thetext.length(); i++)
           {
            char a = thetext.charAt(i);

            switch (a)
            {
                case 'A': case 'a'://moves right
                   x+=1; y+=0;
                   series.add(x,y);
                    break;

                case 'C': case 'c': //moves up
                  x+=0; y+=1;
                  series.add(x,y);
                    break;

                case 'G': case 'g': //move left
                  x-=1; y+=0;
                  series.add(x,y);
                    break;

                case 'T': case 't'://move down
                  x+=0; y-=1;
                  series.add(x,y);
                    break;

                default: // series.add(0,0);
                    break;
            }
            }                       
        XYDataset xyDataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart("DNA Random Walk",
            "", "", xyDataset, PlotOrientation.VERTICAL, true, true, false);
        ChartFrame frame1=new ChartFrame("DNA Random Walk",chart);
        frame1.setVisible(true);
        frame1.setSize(300,300);   
        }       
        if(e.getSource()==exit)
        {System.exit(0);}     
    }
    public void stop(){}
}
4

1 に答える 1

1

How to Use Swing Timersjavax.swing.Timerで説明されているように、のインスタンスはこれに適しています。

補遺:@David Sauterが観察しているように、のscheduleAtFixedRate()方法がjava.util.Timer適切な代替手段になります。Using Timers in Swing Applicationsの記事では、2 つのアプローチを比較しています。

于 2010-05-27T21:27:19.527 に答える