0

Jgrapht を使用して、有向加重グラフに基づくシミュレーション環境を構築しています。Jgraphを使用してシミュレーションを表示したいと思います。

グラフを表示し、シミュレーションの実行時にグラフを更新する方法を理解していましたが、エッジの重みが更新されると、ウィンドウ全体がちらつくことに気付きました。frame.paintComponents()現在、私はウィンドウを更新するよう呼びかけています。

変化している個々のエッジのみを更新することができると思いますが、java.awt.

public static void main(String [] args) throws InterruptedException
{

    Simulation newSim = new Simulation(31, .01);//extends ListenableDirectedWeightedGraph

    SimulationViewer applet = new SimulationViewer(newSim);//extends JApplet
    applet.init();

    JFrame frame = new JFrame();
    frame.getContentPane().add(applet);
    frame.setTitle("Simulation Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);


    //run simulation
    for (;newSim.getStep() < newSim.getMAX_STEP(); newSim.incrementStep()) {
        BreadthFirstIterator<SimulationBlock, Signal> iter = 
                         new BreadthFirstIterator<SimulationBlock, Signal>(newSim, newSim.head);

        while (iter.hasNext()) {
            iter.next().execute(newSim);
            //update graphics
            frame.paintComponents(applet.getGraphics());//looks clunky
            Thread.sleep(500);
        }

    }

}
4

1 に答える 1

0

updateアプレットのメソッドを呼び出す必要があったようです。置換:

frame.paintComponents(applet.getGraphics());//looks clunky

と:

applet.update(applet.getGraphics());

これは少しファンキーに見えますSimulationViewer。クラス内に収まるように、このコードをリファクタリングする必要があるかもしれません。

于 2013-12-19T15:24:26.117 に答える