home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / S5JAVA.ZIP / s52.java < prev    next >
Encoding:
Java Source  |  1999-02-25  |  35.0 KB  |  1,168 lines

  1. /* S5 simulator based on DOS/TP, WIN/Delphi and LINUX/FreePascal versions
  2.    (C) 1999 Peter Sieg
  3. */
  4.  
  5. import java.applet.*;
  6. import java.awt.*;
  7. import java.io.*;
  8. import java.util.*;
  9. import java.net.*;
  10.  
  11. public class s52 extends Applet implements Runnable
  12. {
  13.   Thread timer = null;
  14.   Image bg_img;
  15.   int i_red, i_green, i_blue;
  16.   String s_backimg;
  17.   long cnt;
  18.   String s_mesg = new String("Test...");
  19.   protected static final int i_MAX_AW = 101; // 0-100 1-100 Used
  20.   protected static final int i_MAX_EAM_BAUSTEIN = 0; // EAM 0.0-7
  21.  
  22.   String sa_operation[] = new String[i_MAX_AW];
  23.   String s_operation    = new String();
  24.   String sa_operand[]   = new String[i_MAX_AW];
  25.   String s_operand      = new String();
  26.   String s_line      = new String();
  27.   int  ia_baustein[] = new int[i_MAX_AW];
  28.   int  ia_bitnr[]    = new int[i_MAX_AW];
  29.   int  ia_t_wert[]   = new int[i_MAX_AW];
  30.   int  ia_c_wert[]   = new int[i_MAX_AW];
  31.   int  i_baustein, i_bitnr, i_t_wert, i_c_wert;
  32.   int  i_act_aw, i_anz_aw;
  33.   int  i_hw_simcode; // which hardware to simulate; load with L K N 7!
  34.   int  i_yy,i_yn,i_yw,i_yd,i_yo,i_yh,i_ym,i_ys;
  35.   boolean b_awl_ok, b_running, b_vkl, b_vka, b_vkb, b_vku, b_error;
  36.  
  37.   Checkbox cb_e_00 = new Checkbox("E 0.0");
  38.   Checkbox cb_e_01 = new Checkbox("E 0.1");
  39.   Checkbox cb_e_02 = new Checkbox("E 0.2");
  40.   Checkbox cb_e_03 = new Checkbox("E 0.3");
  41.   Checkbox cb_e_04 = new Checkbox("E 0.4");
  42.   Checkbox cb_e_05 = new Checkbox("E 0.5");
  43.   Checkbox cb_e_06 = new Checkbox("E 0.6");
  44.   Checkbox cb_e_07 = new Checkbox("E 0.7");
  45.  
  46.   Checkbox cb_a_00 = new Checkbox("A 0.0");
  47.   Checkbox cb_a_01 = new Checkbox("A 0.1");
  48.   Checkbox cb_a_02 = new Checkbox("A 0.2");
  49.   Checkbox cb_a_03 = new Checkbox("A 0.3");
  50.   Checkbox cb_a_04 = new Checkbox("A 0.4");
  51.   Checkbox cb_a_05 = new Checkbox("A 0.5");
  52.   Checkbox cb_a_06 = new Checkbox("A 0.6");
  53.   Checkbox cb_a_07 = new Checkbox("A 0.7");
  54.  
  55.   Checkbox cb_m_00 = new Checkbox("M 0.0");
  56.   Checkbox cb_m_01 = new Checkbox("M 0.1");
  57.   Checkbox cb_m_02 = new Checkbox("M 0.2");
  58.   Checkbox cb_m_03 = new Checkbox("M 0.3");
  59.   Checkbox cb_m_04 = new Checkbox("M 0.4");
  60.   Checkbox cb_m_05 = new Checkbox("M 0.5");
  61.   Checkbox cb_m_06 = new Checkbox("M 0.6");
  62.   Checkbox cb_m_07 = new Checkbox("M 0.7");
  63.  
  64.   Label l_counter  = new Label("Counter");
  65.   Label l_timer    = new Label("Timer");
  66.   TextField t_c_00 = new TextField("0",8);
  67.   TextField t_c_01 = new TextField("0",8);
  68.   TextField t_c_02 = new TextField("0",8);
  69.   TextField t_t_00 = new TextField("0",8);
  70.   TextField t_t_01 = new TextField("0",8);
  71.   TextField t_t_02 = new TextField("0",8);
  72.  
  73.   Label l_date_time= new Label("<empty>");
  74.   Label l_accu     = new Label("Accu:");
  75.   TextField t_accu = new TextField("0",8);
  76.   Label l_act_aw   = new Label("Actual AW:");
  77.   Label l_actual_aw= new Label("<empty>");
  78.   Checkbox cb_vka  = new Checkbox("VKA");
  79.   Checkbox cb_vkb  = new Checkbox("VKB");
  80.  
  81.   Button b_load_awl  = new Button("Load AWL");
  82.   Button b_start_stop= new Button("Start/Stop");
  83.   Button b_single_step=new Button("Single Step");
  84.   TextField t_awl_name=new TextField("my.awl",24);
  85.  
  86.   public void start()
  87.   {
  88.     if (timer == null)
  89.     {
  90.       timer = new Thread(this);
  91.       timer.start();
  92.     }
  93.   }
  94.  
  95.   public void stop()
  96.   {
  97.     timer = null;
  98.   }
  99.  
  100.   public void run()
  101.   {
  102.     while (timer != null)
  103.     {
  104.       try
  105.       {
  106.         Thread.sleep(100);
  107.       }
  108.       catch (InterruptedException e){}
  109.       if (b_running == true) single_step();
  110.     }
  111.     timer = null;
  112.   }
  113.  
  114.   // override imageUpdate method for loading control of background image and stopping of progress thread
  115.   public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
  116.   {
  117.     boolean done = ((flags & (ERROR | FRAMEBITS | ALLBITS)) != 0);
  118.     repaint (done ? 0 : 100);
  119.     return !done;
  120.   }
  121.  
  122. // overide some methods to display author and parameter infos
  123.   public String getAppletInfo()
  124.   {
  125.     return "S5 like plc simulation  (c) 1999 Peter Sieg. For Robin and Heike";
  126.   }
  127.  
  128.   public String[][] getParameterInfo()
  129.   {
  130.     String[][] info = 
  131.     {
  132.       {"backimg","Name of image (GIF or JPG) file for background", "Will be loaded as background image"},
  133.       {"red","A color value for the red part. Range 0 to 255", "Used to create background color"},
  134.       {"green","A color value for the green part. Range 0 to 255", "Used to create background color"},
  135.       {"blue","A color value for the blue part. Range 0 to 255", "Used to create background color"}
  136.     };
  137.     return info;
  138.   }
  139.  
  140.   public void init()
  141.   {
  142.     resize(500,400); // Set window size (width,height)
  143.     setLayout(null); // use free layout with x,y,width and height.
  144.  
  145. //    tracker = new MediaTracker(this);
  146. // get background image parameter or use default
  147.     s_line = getParameter("backimg");
  148.     if (s_line == null) s_backimg = "backgr.jpg";
  149.     else s_backimg = s_line;
  150.     bg_img = getImage(getCodeBase(),s_backimg);
  151. //    tracker.addImage(bg_img,0);
  152.  
  153. // get RGB parameter or use defaults
  154.     s_line = getParameter("red");
  155.     if (s_line == null) i_red = 200;
  156.     else i_red = Integer.parseInt(s_line);
  157.     if ((i_red < 0) || (i_red > 255)) i_red = 200;
  158.  
  159.     s_line = getParameter("green");
  160.     if (s_line == null) i_green = 225;
  161.     else i_green = Integer.parseInt(s_line);
  162.     if ((i_green < 0) || (i_green > 255)) i_green = 200;
  163.  
  164.     s_line = getParameter("blue");
  165.     if (s_line == null) i_blue = 200;
  166.     else i_blue = Integer.parseInt(s_line);
  167.     if ((i_blue < 0) || (i_blue > 255)) i_blue = 200;
  168.  
  169.     
  170.     Color backcolor = new Color(i_red, i_green, i_blue); // r,g,b
  171.     setBackground(backcolor);
  172.     setForeground(Color.black);
  173.  
  174.     add(cb_e_00);
  175.     cb_e_00.reshape(   1,   1,  46, 28);
  176.     cb_e_00.setForeground(Color.green);
  177.     add(cb_e_01);
  178.     cb_e_01.reshape(   1,  31,  46, 28);
  179.     cb_e_01.setForeground(Color.green);
  180.     add(cb_e_02);
  181.     cb_e_02.reshape(   1,  61,  46, 28);
  182.     cb_e_02.setForeground(Color.green);
  183.     add(cb_e_03);
  184.     cb_e_03.reshape(   1,  91,  46, 28);
  185.     cb_e_03.setForeground(Color.green);
  186.     add(cb_e_04);
  187.     cb_e_04.reshape(   1,  121,  46, 28);
  188.     cb_e_04.setForeground(Color.green);
  189.     add(cb_e_05);
  190.     cb_e_05.reshape(   1, 151,  46, 28);
  191.     cb_e_05.setForeground(Color.green);
  192.     add(cb_e_06);
  193.     cb_e_06.reshape(   1, 181,  46, 28);
  194.     cb_e_06.setForeground(Color.green);
  195.     add(cb_e_07);
  196.     cb_e_07.reshape(   1, 211,  46, 28);
  197.     cb_e_07.setForeground(Color.green);
  198.  
  199.     add(cb_a_00);
  200.     cb_a_00.reshape(  51,   1,  46, 28);
  201.     cb_a_00.setForeground(Color.red);
  202.     add(cb_a_01);
  203.     cb_a_01.reshape(  51,  31,  46, 28);
  204.     cb_a_01.setForeground(Color.red);
  205.     add(cb_a_02);
  206.     cb_a_02.reshape(  51,  61,  46, 28);
  207.     cb_a_02.setForeground(Color.red);
  208.     add(cb_a_03);
  209.     cb_a_03.reshape(  51,  91,  46, 28);
  210.     cb_a_03.setForeground(Color.red);
  211.     add(cb_a_04);
  212.     cb_a_04.reshape(  51,  121,  46, 28);
  213.     cb_a_04.setForeground(Color.red);
  214.     add(cb_a_05);
  215.     cb_a_05.reshape(  51, 151,  46, 28);
  216.     cb_a_05.setForeground(Color.red);
  217.     add(cb_a_06);
  218.     cb_a_06.reshape(  51, 181,  46, 28);
  219.     cb_a_06.setForeground(Color.red);
  220.     add(cb_a_07);
  221.     cb_a_07.reshape(  51, 211,  46, 28);
  222.     cb_a_07.setForeground(Color.red);
  223.  
  224.     add(cb_m_00);
  225.     cb_m_00.reshape( 101,   1,  46, 28);
  226.     cb_m_00.setForeground(Color.blue);
  227.     add(cb_m_01);
  228.     cb_m_01.reshape( 101,  31,  46, 28);
  229.     cb_m_01.setForeground(Color.blue);
  230.     add(cb_m_02);
  231.     cb_m_02.reshape( 101,  61,  46, 28);
  232.     cb_m_02.setForeground(Color.blue);
  233.     add(cb_m_03);
  234.     cb_m_03.reshape( 101,  91,  46, 28);
  235.     cb_m_03.setForeground(Color.blue);
  236.     add(cb_m_04);
  237.     cb_m_04.reshape( 101,  121,  46, 28);
  238.     cb_m_04.setForeground(Color.blue);
  239.     add(cb_m_05);
  240.     cb_m_05.reshape( 101, 151,  46, 28);
  241.     cb_m_05.setForeground(Color.blue);
  242.     add(cb_m_06);
  243.     cb_m_06.reshape( 101, 181,  46, 28);
  244.     cb_m_06.setForeground(Color.blue);
  245.     add(cb_m_07);
  246.     cb_m_07.reshape( 101, 211,  46, 28);
  247.     cb_m_07.setForeground(Color.blue);
  248.  
  249.     add(l_counter);
  250.     l_counter.reshape( 201,   1,  80, 28);
  251.     l_counter.setBackground(Color.magenta);
  252.     add(t_c_00);
  253.     t_c_00.reshape(    201,  31,  80, 28);
  254.     add(t_c_01);
  255.     t_c_01.reshape(    201,  61,  80, 28);
  256.     add(t_c_02);
  257.     t_c_02.reshape(    201,  91,  80, 28);
  258.     add(l_timer);
  259.     l_timer.reshape(   201,  121,  80, 28);
  260.     l_timer.setBackground(Color.cyan);
  261.     add(t_t_00);
  262.     t_t_00.reshape(    201, 151,  80, 28);
  263.     add(t_t_01);
  264.     t_t_01.reshape(    201, 181,  80, 28);
  265.     add(t_t_02);
  266.     t_t_02.reshape(    201, 211,  80, 28);
  267.  
  268.     add(l_date_time);
  269.     l_date_time.reshape( 1, 241, 96, 28);
  270.     add(l_accu);
  271.     l_accu.reshape(      1, 271,  80, 28);
  272.     add(t_accu);
  273.     t_accu.reshape(    101, 271,  80, 28);
  274.  
  275.     add(l_act_aw);
  276.     l_act_aw.reshape(    1, 301,  80, 28);
  277.     add(l_actual_aw);
  278.     l_actual_aw.reshape(101,301,  80, 28);
  279.     l_actual_aw.setForeground(Color.yellow);
  280.     add(cb_vka);
  281.     cb_vka.reshape(    201, 301,  40, 28);
  282.     cb_vka.setForeground(Color.yellow);
  283.     add(cb_vkb);
  284.     cb_vkb.reshape(    251, 301,  40, 28);
  285.     cb_vkb.setForeground(Color.red);
  286.  
  287.     add(b_load_awl);
  288.     b_load_awl.reshape(     1, 341, 80, 20);
  289.     b_load_awl.setForeground(Color.red);
  290.     add(b_start_stop);
  291.     b_start_stop.reshape( 101, 341, 80, 20);
  292.     b_start_stop.setForeground(Color.red);
  293.     add(b_single_step);
  294.     b_single_step.reshape(201, 341, 80, 20);
  295.     b_single_step.setForeground(Color.red);
  296.  
  297.     add(t_awl_name);
  298.     t_awl_name.reshape  (   1, 370,280, 28);
  299.  
  300.     cnt = 0;
  301.     i_hw_simcode = 0;
  302.   }
  303.  
  304.   public void debug(String s, long i)
  305.   {
  306.     s_mesg = s;
  307.     cnt = i;
  308.     repaint();
  309.   }
  310.  
  311.   public void load_awl()
  312.   {
  313.     // this will load a awl file from file system line=aw by line,
  314.     // checks the syntax of each line and stores the awl in the
  315.     // appropiate variables. If an error occurs, the function will
  316.     // abort and initialize the variables to zero (i_anz_aw=0)
  317.  
  318.     debug("Load...",0-cnt);
  319.  
  320. /*  DUMMY LOAD IS HERE
  321.     // UNA0.0
  322.     sa_operation[1] = "UN";
  323.     sa_operand[1]   = "A";
  324.     ia_baustein[1]  = 0;
  325.     ia_bitnr[1]     = 0;
  326.  
  327.     // =A0.0
  328.     sa_operation[2] = "=";
  329.     sa_operand[2]   = "A";
  330.     ia_baustein[2]  = 0;
  331.     ia_bitnr[2]     = 0;
  332.  
  333.     // BE
  334.     sa_operation[3] = "BE";
  335.     sa_operand[3]   = " ";
  336.     ia_baustein[3]  = 0;
  337.     ia_bitnr[3]     = 0;
  338.  
  339.     i_act_aw = 1;    // start with first aw
  340.     i_anz_aw = 3;    // total aw, should point to "BE"*
  341.     b_awl_ok = true; // overall everything ok to process awl
  342.     b_vkl    = true; // up to last aw state init with true
  343.     b_vku    = true; // allow for single and (U) to be true
  344. */
  345.     // real loading, parsing and checking of a awl file starts here
  346.     b_error  = true; // assume error in file
  347.  
  348.     debug("Before try...",0);
  349.     try
  350.     {
  351.       debug("Inside try...",0);
  352.       String s_line;  // line from file
  353.       String s_token; // token from line
  354.       int i_line_nr;
  355.  
  356.       debug("Before f_is...",0);
  357.       URL f_is = null;
  358.       DataInputStream d_is = null;
  359. //    f_is = new URL(getCodeBase(), "my.awl");
  360.       f_is = new URL(getCodeBase(), t_awl_name.getText());
  361.       debug("Before d_is...",0);
  362.       d_is = new DataInputStream(f_is.openStream());
  363.  
  364.       i_line_nr= 0;
  365.       i_anz_aw = 0;
  366.       debug("Before while...",0);
  367.       while ((s_line = d_is.readLine()) != null)
  368.       {
  369.         i_line_nr++;
  370.         debug(s_line,1000+i_line_nr);
  371.         // now we have a line from the file. first parse it
  372.         // into operation, operand, baustein and bitnr
  373.  
  374.         // make uppercase anyway
  375.         s_line = s_line.toUpperCase();
  376.         // remove leading and trailing white space chars
  377.         s_line = s_line.trim();
  378.  
  379.         StringTokenizer st = new StringTokenizer(s_line," ");
  380.         if (st.countTokens() == 4)
  381.         {
  382.           // if all ok store inside awl arrays. increase i_anz_awl
  383.           i_anz_aw++;
  384.           s_token = st.nextToken(); // operation
  385.           sa_operation[i_anz_aw] = s_token;
  386.           s_token = st.nextToken(); // operand
  387.           sa_operand[i_anz_aw]   = s_token;
  388.           s_token = st.nextToken(); // baustein
  389.           ia_baustein[i_anz_aw]  = Integer.valueOf(s_token).intValue();
  390.           s_token = st.nextToken(); // bitnr
  391.           ia_bitnr[i_anz_aw]     = Integer.valueOf(s_token).intValue();
  392.         }
  393.         else
  394.         {
  395.           if (s_line.equals("BE"))
  396.           {
  397.             i_anz_aw++;
  398.             sa_operation[i_anz_aw] = "BE";
  399.             sa_operand[i_anz_aw]   = "";
  400.             ia_baustein[i_anz_aw]  = 0;
  401.             ia_bitnr[i_anz_aw]     = 0;
  402.             b_error = false;
  403.           }
  404.           else b_error = true;
  405.         }
  406.       }
  407.       debug("EOF...",0);
  408.       d_is.close();
  409.     }
  410.     catch (IOException e)
  411.     {
  412.         b_error= true;
  413.         debug("IOError...",-1l);
  414.     }
  415.     i_act_aw = 1; // start with 1 anyway
  416.     if (b_error)
  417.     {
  418.       b_awl_ok = false; // overall everthing *not* ok to process awl
  419.       b_vkl    = false; // up to last aw state init with false
  420. //    debug("b_error is true",0);
  421.     }
  422.     else
  423.     {
  424.       b_awl_ok = true; // overall everthing ok to process awl
  425.       b_vkl    = true; // up to last aw state init with true
  426. //    debug("b_error is false",0);
  427.  
  428. //  init e,a,m to false
  429.       cb_e_00.setState(false);
  430.       cb_e_01.setState(false);
  431.       cb_e_02.setState(false);
  432.       cb_e_03.setState(false);
  433.       cb_e_04.setState(false);
  434.       cb_e_05.setState(false);
  435.       cb_e_06.setState(false);
  436.       cb_e_07.setState(false);
  437.  
  438.       cb_a_00.setState(false);
  439.       cb_a_01.setState(false);
  440.       cb_a_02.setState(false);
  441.       cb_a_03.setState(false);
  442.       cb_a_04.setState(false);
  443.       cb_a_05.setState(false);
  444.       cb_a_06.setState(false);
  445.       cb_a_07.setState(false);
  446.  
  447.       cb_m_00.setState(false);
  448.       cb_m_01.setState(false);
  449.       cb_m_02.setState(false);
  450.       cb_m_03.setState(false);
  451.       cb_m_04.setState(false);
  452.       cb_m_05.setState(false);
  453.       cb_m_06.setState(false);
  454.       cb_m_07.setState(false);
  455.  
  456. //   init timer and counter to 0
  457.        t_t_00.setText("0");
  458.        t_t_01.setText("0");
  459.        t_t_02.setText("0");
  460.  
  461.        t_c_00.setText("0");
  462.        t_c_01.setText("0");
  463.        t_c_02.setText("0");
  464.     }
  465.   }
  466.  
  467.   public void start_stop()
  468.   {
  469.     cnt--;
  470.     if (b_running)
  471.     {
  472.        b_running = false;
  473.        debug("Stop...",cnt);
  474.     }
  475.     else
  476.     {
  477.        b_running = true;
  478.        debug("Start...",cnt);
  479.     }
  480.   }
  481.  
  482.   public void update_date_time()
  483.   {
  484.     Date now = new Date(); // get actual date and time; put in now 
  485.     i_yy = now.getYear() + 1900; // number starting with 1900
  486.     i_yn = now.getMonth() + 1; // zero based +1 to result in 1-12
  487.     i_yd = now.getDate(); // day of month
  488.     i_yo = now.getDay(); // Sun=0,Sat=6
  489.     i_yh = now.getHours();
  490.     i_ym = now.getMinutes();
  491.     i_ys = now.getSeconds();
  492.     i_yw = (((i_yn-1)*30+i_yd)/7)+1; // simple substitution
  493.     // show date and time in label l_date_time
  494.     l_date_time.setText(now.toLocaleString());
  495.   }
  496.  
  497.   public void do_one_aw(int i)
  498.   {
  499.     String s_xoperation = new String();
  500.     String s_xoperand   = new String();
  501.     int i_xbaustein, i_xbitnr, i_n;
  502.  
  503.     s_xoperation = sa_operation[i];
  504.     s_xoperand   = sa_operand[i];
  505.     i_xbaustein  = ia_baustein[i];
  506.     i_xbitnr     = ia_bitnr[i];
  507.  
  508.     // b_vka holts the individual state of the operand of the actual aw
  509.     // if b_vkl (last b_vkb) and b_vka are true then the total score b_vkb is true
  510.  
  511.     if (s_xoperand.equals("E"))
  512.     {
  513.       switch (i_xbitnr)
  514.       {
  515.         case 0: b_vka = cb_e_00.getState(); break;
  516.         case 1: b_vka = cb_e_01.getState(); break;
  517.         case 2: b_vka = cb_e_02.getState(); break;
  518.         case 3: b_vka = cb_e_03.getState(); break;
  519.         case 4: b_vka = cb_e_04.getState(); break;
  520.         case 5: b_vka = cb_e_05.getState(); break;
  521.         case 6: b_vka = cb_e_06.getState(); break;
  522.         case 7: b_vka = cb_e_07.getState(); break;
  523.       }
  524.     }
  525.  
  526.     if (s_xoperand.equals("A"))
  527.     {
  528.       switch (i_xbitnr)
  529.       {
  530.         case 0: b_vka = cb_a_00.getState(); break;
  531.         case 1: b_vka = cb_a_01.getState(); break;
  532.         case 2: b_vka = cb_a_02.getState(); break;
  533.         case 3: b_vka = cb_a_03.getState(); break;
  534.         case 4: b_vka = cb_a_04.getState(); break;
  535.         case 5: b_vka = cb_a_05.getState(); break;
  536.         case 6: b_vka = cb_a_06.getState(); break;
  537.         case 7: b_vka = cb_a_07.getState(); break;
  538.       }
  539.     }
  540.  
  541.     if (s_xoperand.equals("M"))
  542.     {
  543.       switch (i_xbitnr)
  544.       {
  545.         case 0: b_vka = cb_m_00.getState(); break;
  546.         case 1: b_vka = cb_m_01.getState(); break;
  547.         case 2: b_vka = cb_m_02.getState(); break;
  548.         case 3: b_vka = cb_m_03.getState(); break;
  549.         case 4: b_vka = cb_m_04.getState(); break;
  550.         case 5: b_vka = cb_m_05.getState(); break;
  551.         case 6: b_vka = cb_m_06.getState(); break;
  552.         case 7: b_vka = cb_m_07.getState(); break;
  553.       }
  554.     }
  555.     // now the Y? operands are handled to update b_vka
  556.     if (s_xoperand.equals("YY")) if (i_yy > i_xbaustein) b_vka = true;
  557.     else b_vka = false;
  558.     if (s_xoperand.equals("YN")) if (i_yn > i_xbaustein) b_vka = true;
  559.     else b_vka = false;
  560.     if (s_xoperand.equals("YW")) if (i_yw > i_xbaustein) b_vka = true;
  561.     else b_vka = false;
  562.     if (s_xoperand.equals("YD")) if (i_yd > i_xbaustein) b_vka = true;
  563.     else b_vka = false;
  564.     if (s_xoperand.equals("YO")) if (i_yo > i_xbaustein) b_vka = true;
  565.     else b_vka = false;
  566.     if (s_xoperand.equals("YH")) if (i_yh > i_xbaustein) b_vka = true;
  567.     else b_vka = false;
  568.     if (s_xoperand.equals("YM")) if (i_ym > i_xbaustein) b_vka = true;
  569.     else b_vka = false;
  570.     if (s_xoperand.equals("YS")) if (i_ys > i_xbaustein) b_vka = true;
  571.     else b_vka = false;
  572.  
  573.     if (s_xoperand.equals("T")) // b_vka = (t_t_nn == 0)
  574.     {
  575.       if (i_xbitnr == 0)
  576.       {
  577.         if (0 == Integer.valueOf(t_t_00.getText()).intValue()) b_vka = true;
  578.         else b_vka = false;
  579.       }
  580.       if (i_xbitnr == 1)
  581.       {
  582.         if (0 == Integer.valueOf(t_t_01.getText()).intValue()) b_vka = true;
  583.         else b_vka = false;
  584.       }
  585.       if (i_xbitnr == 2)
  586.       {
  587.         if (0 == Integer.valueOf(t_t_02.getText()).intValue()) b_vka = true;
  588.         else b_vka = false;
  589.       }
  590.     }
  591.     if (s_xoperand.equals("Z")) // b_vka = (t_c_nn == 0)
  592.     {
  593.       if (i_xbitnr == 0)
  594.       {
  595.         if (0 == Integer.valueOf(t_c_00.getText()).intValue()) b_vka = true;
  596.         else b_vka = false;
  597.       }
  598.       if (i_xbitnr == 1)
  599.       {
  600.         if (0 == Integer.valueOf(t_c_01.getText()).intValue()) b_vka = true;
  601.         else b_vka = false;
  602.       }
  603.       if (i_xbitnr == 2)
  604.       {
  605.         if (0 == Integer.valueOf(t_c_02.getText()).intValue()) b_vka = true;
  606.         else b_vka = false;
  607.       }
  608.     }
  609.  
  610.  
  611.     // b_vka holts the individual state of the operand of the actual aw
  612.     // if b_vkl (last b_vkb) and b_vka are true then the total score b_vkb is true
  613.  
  614.     if (s_xoperation.equals("U"))
  615.     {
  616.       cnt += 10;
  617.       if (!b_vku) b_vkl = true;
  618.       if ((b_vka == true) && (b_vkl == true)) b_vkb = true;
  619.       else b_vkb = false;
  620.     }
  621.     if (s_xoperation.equals("UN"))
  622.     {
  623.       cnt += 10;
  624.       if (!b_vku) b_vkl = true;
  625.       if ((b_vka == false) && (b_vkl == true)) b_vkb = true;
  626.       else b_vkb = false;
  627.     }
  628.     if (s_xoperation.equals("O"))
  629.     {
  630.       cnt += 10;
  631.       if ((b_vka == true) || (b_vkl == true)) b_vkb = true;
  632.       else b_vkb = false;
  633.     }
  634.     if (s_xoperation.equals("ON"))
  635.     {
  636.       cnt += 10;
  637.       if ((b_vka == false) || (b_vkl == true)) b_vkb = true;
  638.       else b_vkb = false;
  639.     }
  640.  
  641.     if ((s_xoperation.equals("L")) && (b_vkl))
  642.     {
  643.       if (s_xoperand.equals("K")) // load value (baustein) into accu
  644.       {
  645.         if (i_xbitnr < 7) t_accu.setText(String.valueOf(i_xbaustein));
  646.         else 
  647.         {
  648.           i_hw_simcode = i_xbaustein; // which hardware to simulate
  649.         }
  650.       }
  651.     }
  652.  
  653.     if ((s_xoperation.equals("S")) && (b_vkl)) // set t_t/c_nn to accu; if b_vkl == true set EAM to true
  654.     {
  655.       if (s_xoperand.equals("T")) // timer
  656.       {
  657.         if (i_xbitnr == 0)
  658.         {
  659.           t_t_00.setText(t_accu.getText());
  660.         }
  661.         if (i_xbitnr == 1)
  662.         {
  663.           t_t_01.setText(t_accu.getText());
  664.         }
  665.         if (i_xbitnr == 2)
  666.         {
  667.           t_t_02.setText(t_accu.getText());
  668.         }
  669.       }
  670.       if (s_xoperand.equals("Z")) // counter
  671.       {
  672.         if (i_xbitnr == 0)
  673.         {
  674.           t_c_00.setText(t_accu.getText());
  675.         }
  676.         if (i_xbitnr == 1)
  677.         {
  678.           t_c_01.setText(t_accu.getText());
  679.         }
  680.         if (i_xbitnr == 2)
  681.         {
  682.           t_c_02.setText(t_accu.getText());
  683.         }
  684.       }
  685.       if (s_xoperand.equals("E"))
  686.       {
  687.         switch (i_xbitnr)
  688.         {
  689.           case 0: cb_e_00.setState(true); break;
  690.           case 1: cb_e_01.setState(true); break;
  691.           case 2: cb_e_02.setState(true); break;
  692.           case 3: cb_e_03.setState(true); break;
  693.           case 4: cb_e_04.setState(true); break;
  694.           case 5: cb_e_05.setState(true); break;
  695.           case 6: cb_e_06.setState(true); break;
  696.           case 7: cb_e_07.setState(true); break;
  697.         }
  698.       }
  699.       if (s_xoperand.equals("A"))
  700.       {
  701.         switch (i_xbitnr)
  702.         {
  703.           case 0: cb_a_00.setState(true); break;
  704.           case 1: cb_a_01.setState(true); break;
  705.           case 2: cb_a_02.setState(true); break;
  706.           case 3: cb_a_03.setState(true); break;
  707.           case 4: cb_a_04.setState(true); break;
  708.           case 5: cb_a_05.setState(true); break;
  709.           case 6: cb_a_06.setState(true); break;
  710.           case 7: cb_a_07.setState(true); break;
  711.         }
  712.       }
  713.       if (s_xoperand.equals("M"))
  714.       {
  715.         switch (i_xbitnr)
  716.         {
  717.           case 0: cb_m_00.setState(true); break;
  718.           case 1: cb_m_01.setState(true); break;
  719.           case 2: cb_m_02.setState(true); break;
  720.           case 3: cb_m_03.setState(true); break;
  721.           case 4: cb_m_04.setState(true); break;
  722.           case 5: cb_m_05.setState(true); break;
  723.           case 6: cb_m_06.setState(true); break;
  724.           case 7: cb_m_07.setState(true); break;
  725.         }
  726.       }
  727.     }
  728.  
  729.     if ((s_xoperation.equals("R")) && (b_vkl)) // set t_t/c_nn to 0; if b_vkl == true set EAM to false
  730.     {
  731.       if (s_xoperand.equals("T")) // timer
  732.       {
  733.         if (i_xbitnr == 0)
  734.         {
  735.           t_t_00.setText("0");
  736.         }
  737.         if (i_xbitnr == 1)
  738.         {
  739.           t_t_01.setText("0");
  740.         }
  741.         if (i_xbitnr == 2)
  742.         {
  743.           t_t_02.setText("0");
  744.         }
  745.       }
  746.       if (s_xoperand.equals("Z")) // counter
  747.       {
  748.         if (i_xbitnr == 0)
  749.         {
  750.           t_c_00.setText("0");
  751.         }
  752.         if (i_xbitnr == 1)
  753.         {
  754.           t_c_01.setText("0");
  755.         }
  756.         if (i_xbitnr == 2)
  757.         {
  758.           t_c_02.setText("0");
  759.         }
  760.       }
  761.       if (s_xoperand.equals("E"))
  762.       {
  763.         switch (i_xbitnr)
  764.         {
  765.           case 0: cb_e_00.setState(false); break;
  766.           case 1: cb_e_01.setState(false); break;
  767.           case 2: cb_e_02.setState(false); break;
  768.           case 3: cb_e_03.setState(false); break;
  769.           case 4: cb_e_04.setState(false); break;
  770.           case 5: cb_e_05.setState(false); break;
  771.           case 6: cb_e_06.setState(false); break;
  772.           case 7: cb_e_07.setState(false); break;
  773.         }
  774.       }
  775.       if (s_xoperand.equals("A"))
  776.       {
  777.         switch (i_xbitnr)
  778.         {
  779.           case 0: cb_a_00.setState(false); break;
  780.           case 1: cb_a_01.setState(false); break;
  781.           case 2: cb_a_02.setState(false); break;
  782.           case 3: cb_a_03.setState(false); break;
  783.           case 4: cb_a_04.setState(false); break;
  784.           case 5: cb_a_05.setState(false); break;
  785.           case 6: cb_a_06.setState(false); break;
  786.           case 7: cb_a_07.setState(false); break;
  787.         }
  788.       }
  789.       if (s_xoperand.equals("M"))
  790.       {
  791.         switch (i_xbitnr)
  792.         {
  793.           case 0: cb_m_00.setState(false); break;
  794.           case 1: cb_m_01.setState(false); break;
  795.           case 2: cb_m_02.setState(false); break;
  796.           case 3: cb_m_03.setState(false); break;
  797.           case 4: cb_m_04.setState(false); break;
  798.           case 5: cb_m_05.setState(false); break;
  799.           case 6: cb_m_06.setState(false); break;
  800.           case 7: cb_m_07.setState(false); break;
  801.         }
  802.       }
  803.     }
  804.  
  805.     if ((s_xoperation.equals("Z")) && (b_vkl)) // inc/dec t_c_nn R=-1/V=+1
  806.     {
  807.       if (s_xoperand.equals("V")) // increment t_c_nn +1
  808.       {
  809.         if (i_xbitnr == 0)
  810.         {
  811.           i_n = Integer.valueOf(t_c_00.getText()).intValue();
  812.           i_n++;
  813.           t_c_00.setText(String.valueOf(i_n));
  814.         }
  815.         if (i_xbitnr == 1)
  816.         {
  817.           i_n = Integer.valueOf(t_c_01.getText()).intValue();
  818.           i_n++;
  819.           t_c_01.setText(String.valueOf(i_n));
  820.         }
  821.         if (i_xbitnr == 2)
  822.         {
  823.           i_n = Integer.valueOf(t_c_02.getText()).intValue();
  824.           i_n++;
  825.           t_c_02.setText(String.valueOf(i_n));
  826.         }
  827.       }
  828.       if (s_xoperand.equals("R")) // decrement t_c_nn -1
  829.       {
  830.         if (i_xbitnr == 0)
  831.         {
  832.           i_n = Integer.valueOf(t_c_00.getText()).intValue();
  833.           if (i_n > 0) i_n--;
  834.           t_c_00.setText(String.valueOf(i_n));
  835.         }
  836.         if (i_xbitnr == 1)
  837.         {
  838.           i_n = Integer.valueOf(t_c_01.getText()).intValue();
  839.           if (i_n > 0) i_n--;
  840.           t_c_01.setText(String.valueOf(i_n));
  841.         }
  842.         if (i_xbitnr == 2)
  843.         {
  844.           i_n = Integer.valueOf(t_c_02.getText()).intValue();
  845.           if (i_n > 0) i_n--;
  846.           t_c_02.setText(String.valueOf(i_n));
  847.         }
  848.       }
  849.     }
  850.  
  851.     if (s_xoperation.equals("="))
  852.     {
  853.       cnt += 10;
  854.       if (s_xoperand.equals("E"))
  855.       {
  856.         switch (i_xbitnr)
  857.         {
  858.           case 0: cb_e_00.setState(b_vkl); break;
  859.           case 1: cb_e_01.setState(b_vkl); break;
  860.           case 2: cb_e_02.setState(b_vkl); break;
  861.           case 3: cb_e_03.setState(b_vkl); break;
  862.           case 4: cb_e_04.setState(b_vkl); break;
  863.           case 5: cb_e_05.setState(b_vkl); break;
  864.           case 6: cb_e_06.setState(b_vkl); break;
  865.           case 7: cb_e_07.setState(b_vkl); break;
  866.         }
  867.       }
  868.  
  869.       if (s_xoperand.equals("A"))
  870.       {
  871.         switch (i_xbitnr)
  872.         {
  873.           case 0: cb_a_00.setState(b_vkl); break;
  874.           case 1: cb_a_01.setState(b_vkl); break;
  875.           case 2: cb_a_02.setState(b_vkl); break;
  876.           case 3: cb_a_03.setState(b_vkl); break;
  877.           case 4: cb_a_04.setState(b_vkl); break;
  878.           case 5: cb_a_05.setState(b_vkl); break;
  879.           case 6: cb_a_06.setState(b_vkl); break;
  880.           case 7: cb_a_07.setState(b_vkl); break;
  881.         }
  882.       }
  883.  
  884.       if (s_xoperand.equals("M"))
  885.       {
  886.         switch (i_xbitnr)
  887.         {
  888.           case 0: cb_m_00.setState(b_vkl); break;
  889.           case 1: cb_m_01.setState(b_vkl); break;
  890.           case 2: cb_m_02.setState(b_vkl); break;
  891.           case 3: cb_m_03.setState(b_vkl); break;
  892.           case 4: cb_m_04.setState(b_vkl); break;
  893.           case 5: cb_m_05.setState(b_vkl); break;
  894.           case 6: cb_m_06.setState(b_vkl); break;
  895.           case 7: cb_m_07.setState(b_vkl); break;
  896.         }
  897.       }
  898.     }
  899.  
  900.     if (s_xoperation.equals("BE"))
  901.     {
  902.       cnt += 10;
  903.       b_vkl = true;
  904.     }
  905.  
  906.     b_vkl = b_vkb; // save last vkb
  907.     b_vku = false;
  908.     if (s_xoperation.equals("U")) b_vku = true;
  909.     if (s_xoperation.equals("UN")) b_vku= true;
  910.   }
  911.  
  912.   public void single_step()
  913.   {
  914.     int i_n;
  915.     cnt++;
  916.     debug("Step...",cnt);
  917.  
  918.     if (b_awl_ok == true)
  919.     {
  920.       // show aw in applet
  921.  
  922.       l_actual_aw.setText(sa_operation[i_act_aw]+sa_operand[i_act_aw]
  923.       +String.valueOf(ia_baustein[i_act_aw])+"."+String.valueOf(ia_bitnr[i_act_aw]));
  924.  
  925.       do_one_aw(i_act_aw);
  926.  
  927.       // show b_vka and b_vkb state
  928.       cb_vka.setState(b_vka);
  929.       cb_vkb.setState(b_vkb);
  930.  
  931.       if (i_act_aw < i_anz_aw)
  932.       {
  933.         i_act_aw++;
  934.       }
  935.       else
  936.       {
  937.         i_act_aw = 1;
  938.         // update date and time values
  939.         update_date_time();
  940.         // update t_t_00-02 as pseudo timer
  941.         i_n = Integer.valueOf(t_t_00.getText()).intValue();
  942.         if (i_n > 0) i_n--;
  943.         t_t_00.setText(String.valueOf(i_n));
  944.         i_n = Integer.valueOf(t_t_01.getText()).intValue();
  945.         if (i_n > 0) i_n--;
  946.         t_t_01.setText(String.valueOf(i_n));
  947.         i_n = Integer.valueOf(t_t_02.getText()).intValue();
  948.         if (i_n > 0) i_n--;
  949.         t_t_02.setText(String.valueOf(i_n));
  950.       }
  951.  
  952.     }
  953.   }
  954.  
  955.   public boolean action(Event evt, Object arg)
  956.   {
  957.     if (evt.target == b_start_stop)
  958.     {
  959.       start_stop();
  960.       return true; // yes, this event was handled.
  961.     }
  962.     if (evt.target == b_single_step)
  963.     {
  964.       single_step();
  965.       return true; // yes, this event was handled.
  966.     }
  967.     if (evt.target == b_load_awl)
  968.     {
  969.       load_awl();
  970.       return true; // yes, this event was handled.
  971.     }
  972.     return false;  // other events should be handled elsewhere.
  973.   }
  974.  
  975.  
  976.   public void pre_paint()
  977.   {
  978.     Graphics g = getGraphics();
  979.  
  980.     // paint hardware simulation area 
  981.     // width=196 starting at 302; height=296 starting at 2
  982.     g.drawRect(301,  1,197,298);
  983.     switch (i_hw_simcode)
  984.     {
  985.     case 0:
  986.     // *************************************************
  987.     // start individual hardware simulation routine here
  988.     // 1.) first show a_00-a_02 with traffic light
  989.     //  Color brown = new Color(150, 75,  0); // r,g,b = pcb board brown
  990.     //  g.setColor(brown);
  991.     //  g.setColor(Color.gray);
  992.     //  g.fillRect(310, 10,180,280);
  993.       g.setColor(Color.black);
  994.       g.fillRect(311, 11, 20, 58);
  995.       g.setColor(Color.black);
  996.       g.fillRect(311, 70, 40, 40);
  997.       // clear round area
  998.       g.setColor(Color.white);
  999.       g.fillOval(313, 73, 34, 34);    
  1000.       g.setColor(Color.black);
  1001.       g.fillRect(311,115, 50, 20);
  1002.       g.fillRect(311,140, 50, 20);
  1003.       g.setColor(Color.white);
  1004.       g.fillRect(313,118, 44, 14);
  1005.       g.fillRect(313,143, 44, 14);
  1006.       g.setColor(Color.black);
  1007.       // con lines first relais
  1008.       g.drawLine(311,128,325,128);
  1009.       g.drawLine(345,128,360,128);
  1010.       // con lines second relais
  1011.       g.drawLine(311,153,325,153);
  1012.       g.drawLine(345,153,360,153);
  1013.     break;
  1014.     // *************************************************
  1015.     case 1:
  1016.       // g.setColor(Color.yellow);
  1017.       // g.setColor(Color.gray);
  1018.       // g.fillRect(310, 10,180,280);
  1019.       // paint a 'transport' belt 
  1020.       g.setColor(Color.black);
  1021.       g.fillRect(320,200,160, 10);
  1022.       g.fillOval(322,210,  8,  8);
  1023.       g.fillOval(396,210,  8,  8);
  1024.       g.fillOval(470,210,  8,  8);
  1025.       // draw filling nozzle above middle beaker position
  1026.       g.fillRect(394,110, 10, 30);
  1027.       g.fillRect(390,125, 18, 10);
  1028.       // e_03 to show beaker is full
  1029.       g.fillOval(380,160,  8,  8);
  1030.     break;
  1031.     default:
  1032.     break;    
  1033.     }
  1034.     // restore color
  1035.     g.setColor(Color.black);
  1036.   }
  1037.  
  1038.   public void upd_paint()
  1039.   {
  1040.     Graphics g = getGraphics();
  1041.     // paint hardware simulation area 
  1042.     // width=196 starting at 302; height=296 starting at 2
  1043.     switch (i_hw_simcode)
  1044.     {
  1045.     case 0:
  1046.     // *************************************************
  1047.     // start individual hardware simulation routine here
  1048.     // 1.) first show a_00-a_02 with traffic light
  1049.     // a_00 = green
  1050.     if (cb_a_00.getState()) g.setColor(Color.green);
  1051.     else g.setColor(Color.black);
  1052.     g.fillOval(313, 13, 14, 14);
  1053.     // a_01 = yellow
  1054.     if (cb_a_01.getState()) g.setColor(Color.yellow);
  1055.     else g.setColor(Color.black);
  1056.     g.fillOval(313, 33, 14, 14);
  1057.     // a_02 = red
  1058.     if (cb_a_02.getState()) g.setColor(Color.red);
  1059.     else g.setColor(Color.black);
  1060.     g.fillOval(313, 53, 14, 14);
  1061.     // restore color
  1062.     g.setColor(Color.black);
  1063.     // 2.) show a_03 with spinning ventilator
  1064.     if (cb_a_03.getState()) g.setColor(Color.blue);
  1065.     else g.setColor(Color.white);
  1066.     // draw + middle x=330;y=90
  1067.     g.fillRect(325, 75, 10, 30);
  1068.     g.fillRect(315, 85, 30, 10); 
  1069.     // restore color
  1070.     g.setColor(Color.black);
  1071.     // 3.) show a_04+a_05 with relais
  1072.     if (cb_a_04.getState()) g.setColor(Color.orange);
  1073.     else g.setColor(Color.white);
  1074.     g.fillRect(325,120, 20,  8);
  1075.     if (cb_a_05.getState()) g.setColor(Color.magenta);
  1076.     else g.setColor(Color.white);
  1077.     g.fillRect(325,145, 20,  8);
  1078.     break;
  1079.     // *************************************************
  1080.     case 1:
  1081.     // now show status of e_00-e_03 with red light if true, black if false
  1082.     if (cb_e_00.getState()) g.setColor(Color.red);
  1083.     else g.setColor(Color.black);
  1084.     g.fillOval(322,210,  8,  8);
  1085.     if (cb_e_01.getState()) g.setColor(Color.red);
  1086.     else g.setColor(Color.black);
  1087.     g.fillOval(396,210,  8,  8);
  1088.     if (cb_e_02.getState()) g.setColor(Color.red);
  1089.     else g.setColor(Color.black);
  1090.     g.fillOval(470,210,  8,  8);
  1091.     if (cb_e_03.getState()) g.setColor(Color.red);
  1092.     else g.setColor(Color.black);
  1093.     g.fillOval(380,160,  8,  8);
  1094.     // show beaker at pos e_00-e_02 if true
  1095.     if (cb_e_00.getState())
  1096.     {
  1097.       g.setColor(Color.yellow);
  1098.       g.fillRect(320,160, 19, 39);
  1099.     }
  1100.     else // clear beaker position
  1101.     {
  1102.       g.setColor(Color.black);
  1103.       g.drawRect(320,160, 18, 38); 
  1104.     }
  1105.     if (cb_e_01.getState())
  1106.     {
  1107.       g.setColor(Color.yellow);
  1108.       g.fillRect(390,160, 19, 39);
  1109.     }
  1110.     else // clear beaker position
  1111.     {
  1112.       g.setColor(Color.black);
  1113.       g.drawRect(390,160, 18, 38); 
  1114.     }
  1115.     if (cb_e_02.getState())
  1116.     {
  1117.       g.setColor(Color.yellow);
  1118.       g.fillRect(460,160, 19, 39);
  1119.     }
  1120.     else // clear beaker position
  1121.     {
  1122.       g.setColor(Color.black);
  1123.       g.drawRect(460,160, 18, 38); 
  1124.     }
  1125.     // show transport if a_00 = true with an arrow line
  1126.     if (cb_a_00.getState()) g.setColor(Color.red);
  1127.     else g.setColor(Color.black);
  1128.     g.drawLine(330,230,460,230);
  1129.     g.drawLine(440,220,460,230);
  1130.     g.drawLine(440,240,460,230);
  1131.     // show filling into beaker if a_03 is true with an arrow line
  1132.     if (cb_a_03.getState()) g.setColor(Color.red);
  1133.     else g.setColor(Color.black);
  1134.     g.drawLine(399,142,399,158);
  1135.     g.drawLine(393,150,399,158);
  1136.     g.drawLine(405,150,399,158);
  1137.  
  1138.     break;
  1139.     default:
  1140.     break;    
  1141.     }
  1142.     // restore color
  1143.     g.setColor(Color.black);
  1144.   }
  1145.  
  1146.   public void update( Graphics g)
  1147.   {
  1148.     paint(g);
  1149.   }
  1150.   
  1151.   public void paint( Graphics g)
  1152.   {
  1153.     // print out the values etc.
  1154.     // if (tracker.checkAll()) g.drawImage(bg_img,0,0,500,400,this);
  1155.     g.drawImage(bg_img,0,0,500,400,this);
  1156.  
  1157.     g.setColor(Color.white);
  1158.     g.fillRoundRect(302,341, 100, 20,4,2);
  1159.     g.setColor(Color.black);
  1160.     g.drawString(s_mesg + cnt, 305, 356);
  1161.     // paint one time elements of hardware simulation
  1162.     pre_paint();
  1163.     // paint updates of hardware simulation area
  1164.     upd_paint();
  1165.   }
  1166. }
  1167.  
  1168.