トップ  >  リファレンス  >  サンプルソースコード  >  ストラテジーAPI  >  TickCountingTabSimple.java
TickCountingTabSimple.java

注意事項:
サンプルソースコードには実際にオーダーを発注するものがあります。
サンプルソースコードのストラテジーを起動する場合は、注意して下さい。



// Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved.
package jforex.guitests;

import javax.swing.*;
import com.dukascopy.api.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 JForexクライアントにtickカウンター(リセットボタン付き)の新しいタブを追加します。
 */
public class TickCountingTabSimple implements IStrategy {
    private IUserInterface userInterface;
    private JLabel labelTickCount;
    
    private int tickCount;
    private int resets;
    private final String tabName = "TickCounter";
    
    public void onStart(IContext context) throws JFException {
        this.userInterface = context.getUserInterface();
        
        // ボトムタブを追加し、ラベルとResetボタンを追加します。
        JPanel myTab       = userInterface.getBottomTab(tabName);
        labelTickCount     = new JLabel();
        final JButton btn = new JButton("Reset");

        myTab.add(labelTickCount);
        myTab.add(btn);
        
        // "Reset"ボタンをクリックするとtickカウンターをリセットし、ラベルの色を変更します。
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tickCount = 0;
                labelTickCount.setForeground((resets % 2 == 0 ? Color.RED : Color.BLUE));
                btn.setText("Reset (" + ++resets +")");
            }
        }); 
    }
    
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if(labelTickCount != null)
            labelTickCount.setText("リセットしてからのtickカウント数: " + tickCount++);     
    }

    public void onStop() throws JFException {
        userInterface.removeBottomTab(tabName);
    }
    
    public void onAccount(IAccount account) throws JFException {    }
    public void onMessage(IMessage message) throws JFException {    }    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {    }
}








スポンサーリンク

スポンサーリンク
検索
リファレンスツリー


Copyright ©2016 JForexAPIで自動売買させ隊! All Rights Reserved.


Top

inserted by FC2 system