Hi,
I'm trying to get the equity in order to update a textField.
My first thought was to call a function that updates my textfield from
public void onAccount(IAccount acount) like this :
public void onAccount(IAccount account) throws JFException {
equityUpdate = account.getEquity();
myPanel.updateLabel(Double.toString(equityUpdate));
}
But I get a nullPointerException on running the strategy :
java.lang.NullPointerException @ jforex.SwingTest.onAccount(SwingTest.java:45)
Then I tried to update a variable from onAccount(IAccount account) and
then update the value of my textField from onTick(Instrument instrument, ITick tick)
and it works !
public void onAccount(IAccount account) throws JFException {
equityUpdate = account.getEquity();
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
myPanel.updateLabel(Double.toString(equityUpdate));
}
My question is why ??? I don't need to refresh the equity on each tick...
Thanks
Here is the whole code inspired from de swing test exemple.
package jforex;
import java.util.*;
import javax.swing.*;
import com.dukascopy.api.*;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.concurrent.Callable;
import javax.swing.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;
public class SwingTest implements IStrategy {
private IUserInterface userInterface;
private JPanel myTab;
private IConsole console;
private MySpecialPanel myPanel;
private double equityUpdate;
private int counter = 0;
public void onStart(IContext context) throws JFException {
this.console = context.getConsole();
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 {
//
// I want to do this here but I have a null pointer exception
//
equityUpdate = account.getEquity();
myPanel.updateLabel(Double.toString(equityUpdate));
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
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;
JTextField equityField;
MySpecialPanel(){
/* this.label = new JLabel();
this.add(label);*/
this.equityField = new JTextField();
equityField.setColumns(10);
this.add(equityField);
}
public void updateLabel(final String value){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
if (equityField!=null)
//console.getOut().println("updateLabel() : "+MySpecialPanel.this.label);
MySpecialPanel.this.equityField.setText(value);
}
});
}
}
}