SWING example
package jforex;
import java.util.*;
import javax.swing.*;
import com.dukascopy.api.*;
import java.awt.BorderLayout;
public class SwingTest implements IStrategy {
private IUserInterface userInterface;
private JPanel myTab;
private MySpecialPanel myPanel;
private int counter = 0;
public void onStart(IContext context) throws JFException {
this.userInterface = context.getUserInterface();
myTab = userInterface.getBottomTab("Test");
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
myPanel = new MySpecialPanel();
myTab.add(myPanel);
}
});
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
myPanel.updateLabel(getLabel(counter++));
if (counter > 6) counter = 0;
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
private String getLabel(int counter){
StringBuffer newLabel = new StringBuffer();
for (int i=1; i<=13; i++){
if (counter != i)
newLabel.append("1");
else
newLabel.append(i);
}
return newLabel.toString();
}
class MySpecialPanel extends JPanel{
JLabel label;
MySpecialPanel(){
this.label = new JLabel();
this.add(label);
}
public void updateLabel(final String value){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
if (label!=null)
MySpecialPanel.this.label.setText(value);
}
});
}
}
}