private Vensim vensim = new Vensim();
final static int APPWIDTH = 800;
final static int APPHEIGHT = 600;
private Label l1, l2, l3, l4, l5, l6, l7, l8, l9, l10;
private TextField tf4,cprecio1, cprecio2, cdistribucion, cpublicidad, ccompras1, ccompras2, ccontratacion, csalarioj, csalarios;
private TextArea ta1;
private Button b1, b2, b3, b5, b7;
private Panel p1, p2, p3, p4, p5;
private int tpoints, result;
float rval[], tval[], gval[], dval[];
float EBITDA[] = new float[36];
float precioinicial1[] = new float[36];
float precioinicial2[] = new float[36];
float distribucion[] = new float[36];
float publicidad[] = new float[36];
float comprasalmacen1[] = new float[36];
float comprasalmacen2[] = new float[36];
float contratacion[] = new float[36];
float salarioj[] = new float[36];
float salarios[] = new float[36];
double distri[] = new double[36];
private String PrecioInit1,PrecioInit2, PublicidadInit, DistribucionInit, ComprasInit1, ComprasInit2, ContratacionInit, SalarioJInit, SalarioSInit, vensimCommand;
/**
* Constructor creates the application interface
*/
public VensimApp()
{
//TAMAÑO DE LA VENTANA DE APLICACION Y TITULO
setSize( APPWIDTH, APPHEIGHT );
setLayout( new BorderLayout(20,20) );
setTitle( "Java to Vensim" );
//PANEL DONDE ESTA INCLUIDOS TODOS LOS DEMAS PANELES
p1 = new Panel();
p1.setLayout( new BorderLayout(20,20) );
add( p1, BorderLayout.WEST );
//PANEL DEL TEXTO GRIS
p2 = new Panel();
p2.setLayout( new BorderLayout(20,20) );
add( p2, BorderLayout.CENTER );
//PANEL DONDE ESTAN LOS CAMPOS PARA INTRODUCIR LOS DATOS
p3 = new Panel();
p3.setLayout( new GridLayout(9,10) );
p1.add( p3, BorderLayout.NORTH );
//PANEL DE LOS BOTONES
p4 = new Panel();
p4.setLayout( new GridLayout(5,2,10,10) );
p1.add( p4, BorderLayout.CENTER );
//PANEL INFERIOR, DONDE ESTA EL CAMPO DE SALIDA
p5 = new Panel();
p5.setLayout( new FlowLayout() );
p1.add( p5, BorderLayout.SOUTH );
//AÑADE ETIQUETA Y CAMPO DE TEXTO AL PANEL 3
l1 = new Label( "Precio Producto 1" );
p3.add( l1 );
cprecio1 = new TextField( 10 );
p3.add( cprecio1 );
//AÑADE ETIQUETA Y CAMPO DE TEXTO AL PANEL 3
l2 = new Label( "Precio Producto 2" );
p3.add( l2 );
cprecio2 = new TextField( 10 );
p3.add(cprecio2);
//AÑADE ETIQUETA Y CAMPO DE TEXTO AL PANEL 3
l3 = new Label( "Gastos distribución ");
p3.add( l3 );
cdistribucion = new TextField( 10 );
p3.add(cdistribucion);
l4 = new Label ("Gastos publicidad ");
p3.add(l4);
cpublicidad = new TextField(10);
p3.add(cpublicidad);
l5 = new Label (" Compras almacen Producto 1");
p3.add(l5);
ccompras1 = new TextField (10);
p3.add(ccompras1);
l6 = new Label (" Compras almacen Producto 2");
p3.add(l6);
ccompras2 = new TextField(10);
p3.add(ccompras2);
l7 = new Label (" Plantilla Junior");
p3.add(l7);
ccontratacion = new TextField(10);
p3.add(ccontratacion);
l8 = new Label (" Salario Personal Junior");
p3.add(l8);
csalarioj = new TextField(10);
p3.add(csalarioj);
l9 = new Label (" Salario Personal Senior");
p3.add(l9);
csalarios = new TextField(10);
p3.add(csalarios);
//AÑADE BOTONES AL PANEL 4
b1 = new Button( "CARGAR MODELO" );
p4.add( b1 );
b1.addActionListener( this );
b2 = new Button( "SIMULAR" );
p4.add( b2 );
b2.addActionListener( this );
b3 = new Button( "SETUP GAME" );
p4.add( b3 );
b3.addActionListener( this );
b5 = new Button( "CONTINUAR EL JUEGO" );
p4.add( b5 );
b5.addActionListener( this );
b7 = new Button( "EMPEZAR EL JUEGO" );
p4.add( b7 );
b7.addActionListener( this );
//AÑADE ETIQUETA Y CAMPO DE SALIDA AL PANEL 5 (el de abajo del todo)
l10 = new Label( "EBITDA = " );
p5.add( l10 );
tf4 = new TextField( 15 );
tf4.setEditable(false);
p5.add( tf4 );
//AÑADE AREA DE SALIDA DE DATOS AL PANEL 2 (el campo de la derecha grande)
ta1 = new TextArea("CUADRO DE TEXTO: A QUE VOY A SALIR BIEN?....", 10,50);
ta1.setEditable( false );
p2.add( ta1, BorderLayout.NORTH );
//HACE LA APLICACIÓN VISIBLE
setVisible( true );
// CREAMOS ARRAY DE TIEMO Y VALORES, hardwired array length
tval = new float[41];
rval = new float[41];
result = vensim.be_quiet(2);
if (result == 0)
System.out.println( "Vensim be quiet failed" );
}
public void actionPerformed ( ActionEvent e )
{
//CARGAR MODELO
if (e.getSource() == b1)
{
result = vensim.command( "SPECIAL>LOADMODEL|C:\\Documents and Settings\\miriiam\\Escritorio\\PROYECTO\\mariaje\\MODELO\\ACI118MO00\\CIMD9.vmf" );
ta1.setText("MODELO VENSIM......OK");
}
//get the value for precio inicial and put it in the text field
result=vensim.get_data("base.vdf","precio inicial[producto1,competidor1]","TIME",precioinicial1,tval,41);
cprecio1.setText(Float.toString(precioinicial1[0]));
//get the value for precio inicial and put it in the text field
result=vensim.get_data("base.vdf","precio inicial[producto2,competidor2]","TIME",precioinicial2,tval,41);
cprecio2.setText(Float.toString(precioinicial2[0]));
result=vensim.get_data("base.vdf","Gastos distribucion[competidor1]","TIME",distribucion,tval,41);
cdistribucion.setText(Float.toString(distribucion[0]));
result=vensim.get_data("base.vdf","Gastos publicidad[competidor1]","TIME",publicidad,tval,41);
cpublicidad.setText(Float.toString(publicidad[0]));
result=vensim.get_data("base.vdf","Compras almacen[producto1,competidor1]","TIME",comprasalmacen1,tval,41); ccompras1.setText(Float.toString(comprasalmacen1[0]));
result=vensim.get_data("base.vdf","Compras almacen[producto2,competidor1]","TIME",comprasalmacen2,tval,41); ccompras2.setText(Float.toString(comprasalmacen2[0]));
result=vensim.get_data("base.vdf","contratacion junior[competidor1]","TIME",contratacion,tval,41); ccontratacion.setText(Float.toString(contratacion[0]));
result=vensim.get_data("base.vdf","Salario medio[junior,competidor1]","TIME",salarioj,tval,41);
csalarioj.setText(Float.toString(salarioj[0]));
//SALARIO SENIOR
result=vensim.get_data("base.vdf","Salario medio[senior,competidor1]","TIME",salarios,tval,41);
csalarios.setText(Float.toString(salarios[0]));
}
//SIMULAR
else if (e.getSource() == b2)
{
//set run name
result = vensim.command( "SIMULATE>RUNNAME|base" );
//COGE EL VALOR DEL CAMPO cprecio1
PrecioInit1 = cprecio1.getText();
vensimCommand = "SIMULATE>DATA|precio inicial[producto1,competidor1] = " + PrecioInit1;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO cprecio2
PrecioInit2 = cprecio2.getText;
vensimCommand = "SIMULATE>DATA|precio inicial[producto2,competidor1] = " + PrecioInit2;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO cdistribucion
DistribucionInit=cdistribucion.getText();
vensimCommand = "SIMULATE>DATA|Gastos distribucion[competidor1] = " + DistribucionInit;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO cpublicidad
PublicidadInit = cpublicidad.getText();
vensimCommand = "SIMULATE>DATA|Gastos publicidad[competidor1] = " + PublicidadInit;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO ccompras1
ComprasInit1 = ccompras1.getText();
vensimCommand = "SIMULATE>DATA|Compras almacen[producto1,competidor1] = " + ComprasInit1;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO ccompras2
ComprasInit2 = ccompras2.getText();
vensimCommand = "SIMULATE>DATA|Compras almacen[producto2,competidor1] = " + ComprasInit2;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO csalarios
SalarioSInit = csalarios.getText(); vensimCommand = "SIMULATE>DATA|Salario medio[senior,competidor1] = " + SalarioSInit;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPO csalarioj (salario junior)
SalarioJInit = csalarioj.getText();
vensimCommand = "SIMULATE>DATA|Salario medio[junior,competidor1] = " + SalarioJInit;
result = vensim.command( vensimCommand );
//COGE EL VALOR DEL CAMPOS ccontratacion
ContratacionInit = ccontratacion.getText();
vensimCommand = "SIMULATE>DATA|Contratacion junior[competidor1] = " + ContratacionInit;
result = vensim.command( vensimCommand );
//SIMULAMOS.....
result = vensim.command( "MENU>RUN|0" );
MY PROBLEM STARTS FROM HERE!!!!!!!
//OUTPUT
tpoints = vensim.get_data( "base.vdf", "EBITDA", "TIME", EBITDA, tval, 41 );
StringBuffer buf = new StringBuffer("EBITDA \n");
//se van insertando los datos en el array tval
for (int i = 0; i < tpoints; i++)
{
buf.append(Float.toString(tval
));
buf.append("\t");
}
buf.append("\n");
for (int i = 0; i < tpoints; i++)
{
buf.append(Float.toString(EBITDA));
buf.append("\t");
}
//escribimos el stringbuffer en el campo grande de texto
ta1.setText(buf.toString());
//coge el valor de ebitda y lo pone en el campo de texto
result=vensim.get_data("base.vdf","EBITDA","TIME",EBITDA,tval,41);
//se añade el valor actual?? en el campo de salida de abajo
tf4.setText(Float.toString(EBITDA[0]));
}
//SET UP
else if (e.getSource() == b3)
{
result = vensim.command("GAME>GAMEINTERVAL|1");
result = vensim.command("MENU>GAME");
if (result == 0)
ta1.setText("Start game fails");
else
ta1.setText("Start game succeeds");
/**
* Check the status of vensim
**/
result = vensim.start_simulation(1,1,1);
if (result != 5)
System.out.println( "Start a gaming simulation -- failed" );
else
ta1.setText("Vensim started a game");
}
else if (e.getSource() == b5)
{
//CONTINUE A GAME
//set the capital investment rate to the input field value
EBITDA = tf3.getText();
//continue the simulation game
result = vensim.command("GAME>GAMEON") ;
if (result == 1)
{
System.out.println( "game in progress" );
ta1.setText("game in progress");
}
else
{
System.out.println( "Vensim failed to continue game" );
ta1.setText("Vensim failed to continue game");
}
//get the value for EBITDA and put it in the text field
result=vensim.get_data("base.vdf","EBITDA","TIME",EBITDA,tval,41);
if (result == 0)
{
System.out.println( "get_val -- failed" );
ta1.setText("Failed to get EBITDA Values");
}
tf4.setText(Float.toString(EBITDA[0]));
}
Thank you very muchTextMY PROBLEM STARTS FROM HERE
:(:(:(:(:(:(