Advertisement
Chemist-i

canvasP.java

Aug 18th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 74.22 KB | None | 0 0
  1. /*
  2.  * canvasP.java
  3.  *
  4.  * Created on 20 Август 2007 г., 9:33
  5.  *
  6.  * version 0.31 (040909 2359)
  7.  */
  8.  
  9.  
  10.  
  11. //import com.sun.midp.dev.GraphicalInstaller;
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. //import java.io.InputStreamReader;
  15.  
  16. import java.io.UnsupportedEncodingException;
  17. import javax.microedition.lcdui.*;
  18. //import javax.microedition.lcdui.game.*;
  19. //import javax.microedition.midlet.MIDlet;
  20. //import P.Students_Converter_by_Chemist;
  21. import javax.microedition.rms.*;
  22.  
  23. import java.io.DataOutputStream;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.ByteArrayInputStream;
  26. import java.io.DataInputStream;
  27. import java.io.EOFException;
  28. import java.io.OutputStream;
  29. import java.lang.Math.*;
  30.  
  31. /**Работа с файловой системой, используется только для процедуры kToBinOne, в билд не входит */
  32. import javax.microedition.io.Connector;
  33. import javax.microedition.io.file.*;//*/
  34. /**------------------------------------------------------------------------------------------*/
  35. //import sun.misc.FloatingDecimal;
  36.  
  37. /**
  38.  * @author  Chemist
  39.  * @version 0.30 (TEST 12)
  40.  */
  41. public abstract class canvasP extends Canvas { //Canvas => GameCamvas
  42. // отладка в методе паинт
  43. //    g.setColor(0);
  44. //    g.fillRect(0, 0, 100, HeightLine*2);
  45. //    g.setColor(255, 255, 255);
  46. //    g.drawString(String.valueOf(uroven), 0, 0, 0);
  47. //    g.drawString(String.valueOf(MAIN.length), 0, HeightLine, 0);
  48.  
  49.  
  50.     //Константы: клавиатуры
  51.     //СЕ_НОКИА_САМСУНГ
  52.     static final byte UP_KEY = -1;
  53.     static final byte DOWN_KEY = -2;
  54.     static final byte LEFT_LEY = -3;
  55.     static final byte RIGHT_KEY = -4;
  56.     static final byte FIRE_KEY = -5;
  57.     static final byte LEFT_SOFTKEY = -6;
  58.     static final byte RIGHT_SOFTKEY = -7;
  59.     static final byte GREEN_KEY = -10;
  60.     //static final byte RED_KEY = -11;
  61.     static final byte BACK_KEY = -11;
  62.     static final byte C_KEY = -8;
  63.  
  64.     //МОТОРОЛЛА_СИМЕНС_и_др_говно
  65. //    static final byte UP_KEY = -59;
  66. //    static final byte DOWN_KEY = -60;
  67. //    static final byte LEFT_LEY = -61;
  68. //    static final byte RIGHT_KEY = -62;
  69. //    static final byte FIRE_KEY = -26;
  70. //    static final byte LEFT_SOFTKEY = -1;
  71. //    static final byte RIGHT_SOFTKEY = -4;
  72. //    static final byte GREEN_KEY = -11;
  73. //    static final byte RED_KEY = -12;
  74. //    static final byte BACK_KEY = -11;
  75.     //static final byte C_KEY = -0;
  76.    
  77.    
  78.     static final byte PrecCount=17; //количество возможных точностей
  79.  
  80.     static final byte ThemeItemCount=14; //Количество пунктов в массиве "Темы" (теперь он одномерный)
  81.    
  82.     // if uroven = MAIN.Lenght        - options
  83.     // if uroven = MAIN.Lenght + 1 или 0    - about
  84.     // if uroven = MAIN.Lenght + 1 +1 - Выбор темы
  85.    
  86.  
  87.     /**Число с клавиатуры ввиде строки*/
  88.     private String Gen; //
  89.     /**Номер "линии рамки выбора"*/
  90.     private int NLine;//
  91.     /**Если модиф=фалсе то НЛинеПост = НЛине*/
  92.     private int NLinePos; //
  93.     /**относительный коэф*/
  94.     private int eN; //
  95.     /**Через какое кол-во нажетий "с" можно "*" отменять*/
  96.     private int Star; //
  97.     /**Отрицательно ли вводимое число*/
  98.     private boolean otr; //
  99.     /**Сам не помню для чего я его ввел*/
  100.     private boolean RPos; //
  101.     /**Ширина левого отступа*/
  102.     private int wid; //
  103.     /**Показывать ли пояснение*/
  104.     private boolean show; //
  105.     /**выполняется один раз при запуске*/
  106.     private boolean once; //
  107.     /**Коэфициент обозначающий длинну максимального отрезка строки + 3*/
  108.     private int o[]; //
  109.     /**Правий край рамки это число зависить от скролла*/
  110.     private byte PraviyKrayRamki; //
  111.     /**Если труе, то при репаинте сразу запустить "опции"*/
  112.     private boolean OnceInProject = false; //
  113.     /**Номер выбраной темы*/
  114.     private int NTheme = 0; //
  115.     /**Высота линии (default = 20)(Зависит от шрифта телефона)*/
  116.     private int HeightLine; //
  117.     /**Точность. т.е. Количиство знаков после запятой*/
  118.     private byte Precision;
  119.     /**Смещение для абоута*/
  120.     private byte ddY=0; //
  121.     /**Первое, второе число при быстром выборе*/
  122.     private byte oneS=0; //
  123.     /***/
  124.     private boolean oneSymb=true;
  125.  
  126.  
  127. //private boolean bolee; //Если true то список больше чем экран
  128. //private String test2;
  129. //private int test; //Так, тест
  130. //private int iii;
  131. //private double FL;
  132.  
  133.  
  134. /**Текст главного меню и заголовки уровней*/
  135. static String MAIN[];
  136.  
  137. /**Текст подуровней*/
  138. static String text[][];
  139.  
  140. /**Текст подуровня температура*/
  141. static String temperat_text[];
  142.  
  143. /**Пояснение к величинам*/
  144. //static String Details[][];
  145.  
  146. /**Название темы (оформления)*/
  147. static String ThemeTitle[];
  148.  
  149.  
  150.  
  151. /**Набор цветов для каждой темы
  152.  Вложеный массив означает следующее:
  153.  *Цвет:
  154.  *
  155.  *1. текста (Любого);
  156.  *2. заголовка
  157.  *3. текста заголовка
  158.  *4. рамки
  159.  *5. разделяющей слои линии
  160.  *6. 1,3,5, ... ,n прямоугольника слева
  161.  *7. 1,3,5, ... ,n прямоугольника справа
  162.  *8. 1,3,5, ... ,n прямоугольника справа ---------------
  163.  *9. 2,4,6, ... ,n+1 прямоугольника справа --------------
  164.  *10. фона скролла
  165.  *11. скролла
  166.  *12. границы (при расширеном показе)
  167.  *13. фона (при расширеном показе)
  168.  *14. текста (при расширеном показе)
  169.  */
  170. static int Theme[];
  171.  
  172. /**Колво тем в бинарнике (нужно для корректного отображения в меню темы)*/
  173. static byte ThemeCount=0;
  174.  
  175.  
  176. /**Коэфициенты подуровней (То на что умножается вводимое число чтоб получить результат)*/
  177. static double k[][];
  178.  
  179. /**Меню опций*/
  180. static String options[];
  181.  
  182. /**Указатель на экран устройства*/
  183. //Display myDisplay;
  184.  
  185.  
  186. /** Конструктор просто устанавливает экран.*/
  187. public canvasP(Display myDisp) {
  188.     /*
  189.     kToBin();
  190.     textArrayToBin();
  191.     themeToBin();
  192.     //*/
  193.  
  194.     ReadRS();
  195.    
  196.     read_k();//Загрузка из бин файла коэфициентов
  197.     read_text(); //Загрузка из бин файла с языком
  198.     read_theme(); //Загрузка из бин файла с цветовым оформлением    
  199.  
  200.     testForMassive();
  201.  
  202.     Gen = "0";
  203.     otr = false;
  204.     Star = 0;
  205.     NLine = 1;
  206.     uroven = 1;
  207.     eN = 0;
  208.     once = true;
  209.     o = new int[MAIN.length-2];
  210.  
  211.  
  212.     //DecimalFormat df = new DecimalFormat("###.########"); //(http://www.velocityreviews.com/forums/t139008-java-double-precision.html)
  213.     //super(false);
  214.    
  215.     myDisp.setCurrent(this);
  216.     repaint();
  217.    
  218.     //test();
  219.   }
  220.        
  221.  
  222. /**Процедура закидывающая коефициенты в бинарник и сохраняющая в файловой системе (Используется только на стадии разработки, в билд не входит)
  223. //specification:
  224. //    0 byte = k.length; //первый байт - сохраняет количество вложеных массивов в "к"
  225. //    1 - k.length byte = k[x].length;
  226. //    k.length+1 byte = k[0][0];
  227.  
  228.  
  229.     public void kToBin(){
  230.  
  231.  
  232.         double k_old[][] = {
  233.             {1000000000000000000.0, 1000000000000000.0, 1000000000000.0, 1000000000.0, 1000000.0, 1000.0, 100.0, 10.0, 1.0, 0.1, 0.01, 0.001, 0.000001, 0.000000001, 0.000000000001, 0.000000000000001, 0.000000000000000001}, //Приставки
  234.             {96.7841105354059, 9806650.0, 1.0, 100.0, 1000000.0, 1000000.0, 73556.127270818019531660191116245, 73556.127270818019531660191116245, 98.06650}, //Давление
  235.             {1.0e6, 1.0e3, 100.0, 1.0, 0.001, 39.3700787401575, 3.28083989501312, 1.09361329833771, 5.3995680345572354211663066954644e-4, 6.21371192237e-4},//длина
  236.             {10000.0, 1.0, 0.000001, 0.0001, 0.00024710538, 1550.0031, 10.763910416,  1.19599004630108, 0.000003861},//площадь
  237.             {1000.0, 1.0, 264.172052358148, 219.969248299088, 1000000.0, 61023.7440947323, 35.3146667214886, 1.30795061931439, 33814.022701843},//Обьем
  238.             {1.0, 3.6, 1.9438444924, 2.2374145431},//Скорость
  239.             {1.0, 12960.0, 0.01, 0.00001},//ускорение
  240.             {1.0, 1000, 2.2046226218, 0.15747304442, 35.273961949},//Вес
  241.             {31536000000.0 ,31536000.0, 525600.0, 8760.0, 365.0, 52.142857142857142857142857142857, 13.035714285714285714285714285714, 12.166666666666666666666666666667, 11.774193548387096774193548387097, 1.0}, //Время
  242.             {8796093022208.0, 8589934592.0, 8388608.0, 8192.0, 8.0, 1099511627776.0, 1073741824.0, 1048576.0, 1024, 1.0},//Информация
  243.             {9809.5, 9809.5, 9.8095, 13.1547561878824, 1.0, 13.1494638069705, 13.3372082549427, 13.1547539224889, 13.1487059056918}, //Мощность
  244.             {1.0, 1.00041802233042, 1.00052712434329, 0.999228932179151, 1.00066946708399, 252.055963643748, 252.291028628136, 0.252074030013141, 251.995761111111, 10550558526.2, 1055.05585262, 0.251995761111111}, //Энергия
  245.         };
  246.  
  247.  
  248.         //--------Более оптимальная но, более задрочная процедура (если полномочий нет - бесконца клацать подтверждать чтение запись)-------
  249.         try {
  250.             FileConnection fc = (FileConnection) Connector.open("file:///e:/k");
  251.  
  252.             if (fc.exists())
  253.                 fc.delete();
  254.             fc.create();
  255.             DataOutputStream dos =  fc.openDataOutputStream();
  256.  
  257.             dos.writeByte(k_old.length); //сохраняем количество векторов
  258.  
  259.             for (int i=0;i<k_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
  260.                 dos.writeByte(k_old[i].length);
  261.            
  262.             for (int i=0;i<k_old.length;i++) //сохраняем елементы вектора
  263.                 for (int j=0; j<k_old[i].length;j++)
  264.                 {
  265.                     dos.writeDouble(k_old[i][j]); // Push the score into a byte array.
  266.                 }
  267.  
  268.             //тут начинается проверка себя на вшивость
  269.             DataInputStream dis =  fc.openDataInputStream();
  270.             double[][] k_test=null;
  271.            
  272.             byte k_test_lenght = dis.readByte();
  273.             k_test = new double[ k_test_lenght ][];
  274.  
  275.             for (int i=0; i<k_test_lenght; i++)
  276.                 k_test[i] = new double[dis.readByte()];
  277.  
  278.             for (int i=0;i<k_test.length;i++)
  279.                 for (int j=0;j<k_test[i].length;j++)
  280.                     k_test[i][j]=dis.readDouble();
  281.  
  282.             if (k_old.length==k_test.length) System.out.println("k.length pass"); //сообственно проверка
  283.             else System.out.println("k.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  284.            
  285.             for (int i=0; i<k_old.length; i++)
  286.             {
  287.                 if (k_old[i].length==k_test[i].length) System.out.println("k["+i+"].length pass"); //сообственно проверка
  288.                 else System.out.println("k["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  289.                 for (int j=0; j<k_old[i].length;j++)
  290.                     if (k_old[i][j]==k_test[i][j]) System.out.println("k_old["+i+"]["+j+"]==k_test["+i+"]["+j+"] pass");
  291.                     else System.out.println("k["+i+"]["+j+"]!=k_test["+i+"]["+j+"] fail; k_old["+i+"]["+j+"]="+k_old[i][j]+", k_test["+i+"]["+j+"]="+k_test[i][j]+"!!!!!!!!!!!!!!!!!!!!");
  292.             }
  293.             dis.close();
  294.             //----------------------------------------
  295.             dos.close();
  296.             fc.close();
  297.  
  298.         } catch (IOException ex) {
  299.             ex.printStackTrace();
  300.         }
  301.         //--------------------------------------------------------------------------------------------------------------------------------
  302.  
  303.         //Чтоб я видел что выполнилась процедура закидывания в бинарник
  304.         System.out.println("kToBin() is run!000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
  305.        
  306.     } //
  307.  
  308.     // /**Текстовые массивы в бинар (процедура проверки)
  309.     public void textArrayToBin(){
  310.         //Текст главного меню и заголовки уровней
  311.         String MAIN_old[] = {
  312.             "Температура(t)", "Приставки", "Давление(P)", "Длина(L)", "Площадь(S)",
  313.             "Обьем(V)", "Скорость(\u03C5)(TEST)", "Ускорение(\u03AC)(TEST)",
  314.             "Вес(Q)(TEST)","Время(time)","Информация(1010)",
  315.             "Мощность()", "Энергия()",
  316.             "Опции(\u20AA)", "О проекте(?)"
  317.         };
  318.  
  319.         //Текст подуровней
  320.         String text_old[][] = {
  321.             {"атто", "фемто", "пико", "нано", "микро", "мили", "санти", "деци", "1.0", "дека", "гекто", "кило", "мега", "гига", "тера", "пета", "экса"},//Приставки
  322.             {"атм.", "Паскаль", "КГС/мм\u00B2", "КГС/см\u00B2", "КГС/м\u00B2", "мм.вод.ст", "мм.рт.ст", "торр", "Бар"}, //Давление
  323.             {"мк", "мм", "см", "м", "км", "Дюйм", "Фут", "Ярд", "М.Миля", "Миля"}, //длина
  324.             {"см\u00B2", "м\u00B2", "км\u00B2", "Га", "Акр", "Дюйм\u00B2", "Фут\u00B2", "Ярд\u00B2", "миля\u00B2" }, //площадь
  325.             {"Литр", "м\u00B3", "Галон", "Галон(UK)", "мЛитр", "дюйм\u00B3",  "Фут\u00B3", "Ярд\u00B3", "ж.унция"}, //Обьем
  326.             {"м/с", "км/ч", "Узел", "Миля/ч"}, //Скорость
  327.             {"м/с\u00B2", "км/ч\u00B2", "Гал", "мГал"}, //ускорение
  328.             {"кг", "г", "Фунт", "Стоун", "Унция"}, //Вес
  329.             {"мсек", "сек", "мин", "час", "сутки", "недел.", "мес(28)", "мес(30)", "мес(31)", "год"}, //Время
  330.             {"бит", "Кбит", "Мбит", "Гбит", "Тбит", "байт", "Кбайт", "Мбайт", "Гбайт", "Тбайт"}, //Информация
  331.             {"кг\u00B7м\u00B2\u00B7c\u05BE\u00B3", "Вт", "КВт", "лс", "b лс", "э лс", "м лс", "лс UK", "h лс"}, //Мощность
  332.             {"BTU", "CBTU", "IBTU", "mBTU", "tBTU", "cal 15", "cal 20", "d cal", "cal", "erg", "joule", "kcal"}, //Энергия
  333.         };
  334.  
  335.         //Текст подуровня температура
  336.         String temperat_text_old[] = {"\u00B0С", "K", "F"};
  337.  
  338.         //Пояснение к величинам
  339.        
  340. //        String Details_old[][] = {
  341. //            {"",""},//Приставки
  342. //            {"атмосфера", "Паскаль", "килограмм-сила на квадратный милиметр",
  343. //           "килограмм-сила на квадратный сантиметр", "килограмм-сила на квадратный метр", "милиметров водного столба",
  344. //           "милиметров ртутного столба", "торр", "Бар"}, //Давление
  345. //            {"микрон", "Сантиметр", "Метр", "Километр", "Дюйм", "Фут", "Ярд", "Миля"}, //длина
  346. //            {"см\u00B2", "м\u00B2", "км\u00B2", "Гектар", "Акр", "Дюйм\u00B2", "Фут\u00B2",  "миля\u00B2"}, //площадь
  347. //            {"Литр", "м\u00B3", "Галон", "Чашка", "жидкая унция"}, //Обьем
  348. //            {"метров/секунду", "км/час", "Узел", "Миля/час"}, //Скорость
  349. //            {"м/с\u00B2", "км/ч\u00B2", "Гал", "мГал"}, //ускорение
  350. //            {"килограмм", "грамм", "Фунт", "Стоун", "Унция"}, //Вес
  351. //            {"секунда", "минута", "час", "сутки", "неделя", "месяц(30 дней)", "год"}, //Время
  352. //            {"бит", "Килобит", "Мегабит", "Гигабит", "Терабит", "байт", "Килобайт", "Мегабайт", "Гигабайт", "Терабайт"} //Информация
  353. //
  354. //        };
  355.        
  356.  
  357.         String options_old[] = {
  358.             "Тема (оформление)", //Выбор цветового оформления
  359.             "Точность(НЕТ)" //Точность вычисления
  360.         };
  361.  
  362.         //Название темы (оформления)
  363.         String ThemeTitle_old[] = {
  364.             "Оранжевая", "Синяя"
  365.         };
  366.  
  367.  
  368.         try {
  369.             FileConnection fc = (FileConnection) Connector.open("file:///e:/RU");   //!!!!RU!!!!!
  370.  
  371.             if (fc.exists())
  372.                 fc.delete();
  373.            
  374.             fc.create();
  375.             DataOutputStream dos =  fc.openDataOutputStream();
  376.  
  377.             //Записываем данные последовательно
  378.             //Сохраняем "MAIN"
  379.             dos.writeByte(MAIN_old.length); //сохраняем количество векторов
  380.            
  381.             for (int i=0;i<MAIN_old.length;i++) //сохраняем елементы вектора
  382.             {
  383.                 dos.writeUTF(MAIN_old[i]);
  384.                 //dos.writeDouble(); // Push the score into a byte array.
  385.             }
  386.            
  387.             //Сохраняем "text"
  388.             dos.writeByte(text_old.length); //сохраняем количество векторов
  389.  
  390.             for (int i=0;i<text_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
  391.                 dos.writeByte(text_old[i].length);
  392.            
  393.             for (int i=0;i<text_old.length;i++) //сохраняем елементы вектора
  394.                 for (int j=0; j<text_old[i].length;j++)
  395.                 {
  396.                     dos.writeUTF(text_old[i][j]);
  397.                     //dos.writeDouble(); // Push the score into a byte array.
  398.                 }
  399.  
  400.             //Сохраняем "temperat_text"
  401.             dos.writeByte(temperat_text_old.length); //сохраняем количество векторов
  402.            
  403.             for (int i=0;i<temperat_text_old.length;i++) //сохраняем елементы вектора
  404.             {
  405.                 dos.writeUTF(temperat_text_old[i]);
  406.                 //dos.writeDouble(); // Push the score into a byte array.
  407.             }
  408.            
  409.            //Сохраняем "Details"
  410.            
  411. //            dos.writeByte(Details_old.length); //сохраняем количество векторов
  412. //
  413. //            for (int i=0;i<Details_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
  414. //                dos.writeByte(Details_old[i].length);
  415. //
  416. //            for (int i=0;i<Details_old.length;i++) //сохраняем елементы вектора
  417. //                for (int j=0; j<Details_old[i].length;j++)
  418. //                {
  419. //                    dos.writeUTF(Details_old[i][j]);
  420. //                    //dos.writeDouble(); // Push the score into a byte array.
  421. //                }
  422.            
  423.  
  424.             //Сохраняем "options"
  425.             dos.writeByte(options_old.length); //сохраняем количество векторов
  426.  
  427.             for (int i=0;i<options_old.length;i++) //сохраняем елементы вектора
  428.             {
  429.                 dos.writeUTF(options_old[i]);
  430.                 //dos.writeDouble(); // Push the score into a byte array.
  431.             }
  432.             //-------------
  433.  
  434.             //Сохраняем "ThemeTitle"
  435.             dos.writeByte(ThemeTitle_old.length); //сохраняем количество векторов
  436.            
  437.             for (int i=0;i<ThemeTitle_old.length;i++) //сохраняем елементы вектора
  438.             {
  439.                 dos.writeUTF(ThemeTitle_old[i]);
  440.                 //dos.writeDouble(); // Push the score into a byte array.
  441.             }
  442.             //-------------
  443.  
  444.  
  445.                    
  446.            
  447.            
  448.            
  449.              //тут начинается проверка себя на вшивость (MAIN) !!!!!одинарный!!!!!
  450.             DataInputStream dis =  fc.openDataInputStream();
  451.             String[] MAIN_test=null;
  452.  
  453.             MAIN_test = new String[ dis.readByte() ];
  454.              for (int i=0;i<MAIN_test.length;i++)
  455.                 MAIN_test[i]=dis.readUTF();
  456.  
  457.             if (MAIN_old.length==MAIN_test.length) System.out.println("MAIN.length pass"); //сообственно проверка
  458.             else System.out.println("MAIN.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  459.  
  460.             for (int i=0; i<MAIN_old.length; i++)
  461.             {
  462.                 for (int j=0; j<MAIN_old[i].length(); j++)
  463.                 {
  464.                     if (MAIN_old[i].charAt(j) ==  MAIN_test[i].charAt(j) ) System.out.println("MAIN_old["+i+"].charAt("+j+")==MAIN_test["+i+"].charAt("+j+") pass"); //сообственно проверка
  465.                     else System.out.println("MAIN_old["+i+"]!=MAIN_test["+i+"]; MAIN_old["+i+"]="+MAIN_old[i]+";MAIN_test["+i+"]="+MAIN_test[i]+"   fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  466.                 }
  467.                    
  468.             }
  469.             //dis.close();
  470.             //--------------------------------------------------------------------
  471.  
  472.             //тут начинается проверка себя на вшивость (text) !!!!!двойной!!!!!
  473.             //DataInputStream dis =  fc.openDataInputStream();
  474.             String[][] text_test=null;
  475.  
  476.             text_test = new String[ dis.readByte() ][];
  477.  
  478.             for (int i=0;i<text_test.length;i++)
  479.                 text_test[i] = new String[dis.readByte()];
  480.  
  481.             for (int i=0;i<text_test.length;i++)
  482.                 for (int j=0;j<text_test[i].length;j++)
  483.                     text_test[i][j]=dis.readUTF();
  484.  
  485.             if (text_old.length==text_test.length) System.out.println("text_old.length pass"); //сообственно проверка
  486.             else System.out.println("text_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  487.  
  488.             for (int i=0; i<text_old.length; i++)
  489.             {
  490.                 if (text_old[i].length==text_test[i].length) System.out.println("text_old["+i+"].length pass"); //сообственно проверка
  491.                 else System.out.println("text_old["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  492.                
  493.                 for (int j=0; j<text_test[i].length;j++)
  494.                     for (int kk=0; kk<text_old[i][j].length(); kk++)
  495.                         if (text_old[i][j].charAt(kk)==text_test[i][j].charAt(kk)) System.out.println("text_old["+i+"]["+j+"].charAt("+kk+")==text_test["+i+"]["+j+"].charAt("+kk+") pass");
  496.                         else System.out.println("text_old["+i+"]["+j+"].charAt("+kk+")!=text_test["+i+"]["+j+"].charAt("+kk+") fail; text_test["+i+"]["+j+"].charAt("+kk+")="+text_test[i][j].charAt(kk)+", text_test["+i+"]["+j+"].charAt("+kk+")="+text_test[i][j].charAt(kk)+"  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  497.             }
  498.             //dis.close();
  499.             //-------------------------------------------------------------
  500.  
  501.             //тут начинается проверка себя на вшивость (temperat_text) !!!!!одинарный!!!!!
  502.             //DataInputStream dis =  fc.openDataInputStream();
  503.             String[] temperat_text_test=null;
  504.  
  505.             temperat_text_test = new String[ dis.readByte() ];
  506.              for (int i=0;i<temperat_text_test.length;i++)
  507.                 temperat_text_test[i]=dis.readUTF();
  508.  
  509.             if (temperat_text_old.length==temperat_text_test.length) System.out.println("temperat_text_old.length pass"); //сообственно проверка
  510.             else System.out.println("temperat_text_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  511.  
  512.             for (int i=0; i<temperat_text_old.length; i++)
  513.             {
  514.                 for (int j=0; j<temperat_text_old[i].length(); j++)
  515.                     if (temperat_text_old[i].charAt(j)==temperat_text_test[i].charAt(j)) System.out.println("temperat_text["+i+"].charAt("+j+")==temperat_text_test["+i+"].charAt("+j+") pass"); //сообственно проверка
  516.                     else System.out.println("temperat_text_old["+i+"].charAt("+j+")!=temperat_text_test["+i+"].charAt("+j+"); temperat_text_old["+i+"].charAt("+j+")="+temperat_text_old[i].charAt(j)+";temperat_text_test["+i+"].charAt("+j+")="+temperat_text_test[i].charAt(j)+"   fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  517.             }
  518.             //dis.close();
  519.             //--------------------------------------------------------------------
  520.  
  521.             //тут начинается проверка себя на вшивость (Details) !!!!!двойной!!!!!
  522.             //DataInputStream dis =  fc.openDataInputStream();
  523.            
  524. //            String[][] Details_test=null;
  525. //
  526. //            Details_test = new String[ dis.readByte() ][];
  527. //
  528. //            for (int i=0;i<Details_test.length;i++)
  529. //                Details_test[i] = new String[dis.readByte()];
  530. //
  531. //            for (int i=0;i<Details_test.length;i++)
  532. //                for (int j=0;j<Details_test[i].length;j++)
  533. //                    Details_test[i][j]=dis.readUTF();
  534. //
  535. //            if (Details_old.length==Details_test.length) System.out.println("Details_old.length pass"); //сообственно проверка
  536. //            else System.out.println("Details_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  537. //
  538. //            for (int i=0; i<Details_old.length; i++)
  539. //            {
  540. //                if (Details_old[i].length==Details_test[i].length) System.out.println("Details_old["+i+"].length pass"); //сообственно проверка
  541. //                else System.out.println("Details_old["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  542. //
  543. //                for (int j=0; j<Details_test[i].length;j++)
  544. //                    for (int kk=0; kk<Details_old[i][j].length(); kk++)
  545. //                        if (Details_old[i][j].charAt(kk)==Details_test[i][j].charAt(kk)) System.out.println("Details_old["+i+"]["+j+"].charAt("+kk+")==Details_test["+i+"]["+j+"].charAt("+kk+") pass");
  546. //                        else System.out.println("Details_old["+i+"]["+j+"].charAt("+kk+")!=Details_test["+i+"]["+j+"].charAt("+kk+") fail; Details_test["+i+"]["+j+"].charAt("+kk+")="+Details_test[i][j].charAt(kk)+", Details_test["+i+"]["+j+"].charAt("+kk+")="+Details_test[i][j].charAt(kk)+"  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  547. //            }
  548.             //dis.close();
  549.             //-------------------------------------------------------------
  550.  
  551.             //тут начинается проверка себя на вшивость (options) !!!!!одинарный!!!!!
  552.             //DataInputStream dis =  fc.openDataInputStream();
  553.             String[] options_test=null;
  554.  
  555.             options_test = new String[ dis.readByte() ];
  556.              for (int i=0;i<options_test.length;i++)
  557.                 options_test[i]=dis.readUTF();
  558.  
  559.             if (options_old.length==options_test.length) System.out.println("options_old.length pass"); //сообственно проверка
  560.             else System.out.println("options_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  561.  
  562.             for (int i=0; i<options_old.length; i++)
  563.             {
  564.                 for (int j=0; j<options_old[i].length(); j++)
  565.                     if (options_old[i].charAt(j)==options_test[i].charAt(j)) System.out.println("options["+i+"].charAt(j)==options_test["+i+"].charAt("+j+") pass"); //сообственно проверка
  566.                     else System.out.println("options_old["+i+"].charAt("+j+")!=options_test["+i+"].charAt("+j+"); options_old["+i+"].charAt("+j+")="+options_old[i].charAt(j)+";options_test["+i+"].charAt("+j+")="+options_test[i].charAt(j)+"   fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  567.             }
  568.             //dis.close();
  569.             //--------------------------------------------------------------------
  570.  
  571.             //тут начинается проверка себя на вшивость (ThemeTitle) !!!!!одинарный!!!!!
  572.             //DataInputStream dis =  fc.openDataInputStream();
  573.             String[] ThemeTitle_test=null;
  574.  
  575.             ThemeTitle_test = new String[ dis.readByte() ];
  576.              for (int i=0;i<ThemeTitle_test.length;i++)
  577.                 ThemeTitle_test[i]=dis.readUTF();
  578.  
  579.             if (ThemeTitle_old.length==ThemeTitle_test.length) System.out.println("ThemeTitle_old.length pass"); //сообственно проверка
  580.             else System.out.println("ThemeTitle_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  581.  
  582.             for (int i=0; i<ThemeTitle_old.length; i++)
  583.             {
  584.                 for (int j=0; j<ThemeTitle_old[i].length(); j++)
  585.                     if (ThemeTitle_old[i].charAt(j)==ThemeTitle_test[i].charAt(j)) System.out.println("ThemeTitle["+i+"].charAt("+j+")==ThemeTitle_test["+i+"].charAt("+j+") pass"); //сообственно проверка
  586.                     else System.out.println("ThemeTitle_old["+i+"].charAt("+j+")!=ThemeTitle_test["+i+"].charAt("+j+"); ThemeTitle_old["+i+"].charAt("+j+")="+ThemeTitle_old[i].charAt(j)+";ThemeTitle_test["+i+"].charAt("+j+")="+ThemeTitle_test[i].charAt(j)+"   fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  587.             }
  588.             dis.close();
  589.             //--------------------------------------------------------------------
  590.  
  591.  
  592.  
  593.  
  594.  
  595.             dos.close();
  596.             fc.close();
  597.  
  598.             System.out.println("syntax pass");
  599.         } catch (IOException ex) {
  600.             System.out.println("IOException!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  601.             ex.printStackTrace();
  602.         }
  603.  
  604.         //Чтоб я видел что выполнилась процедура закидывания в бинарник
  605.         System.out.println("textArrayToBin() is run!00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
  606.         uroven=-1;
  607.     }//
  608.  
  609. //  /** Коефициенты тем в бинар
  610.     public void themeToBin(){
  611.         int Theme_old[][] = {
  612.             {0x00FFFF00, 0x00FF7700, 0x00110000, 0x00FFFF00, 0x00993300, 0x00CC4400, 0x00662200, 0, 0, 0x00666666, 0x00FFFFFF, 0x00000000, 0x00525151, 0x00D9D9D9}, //оранжевая
  613.             {0x00FFFFFF, 0x0006FA6E5, 0x00110000, 0x00FFFFFF, 0x001C63DC, 0x00277FEC, 0x000F3EC6, 0, 0, 0x003E7EB1, 0x00FFFFFF, 0x00000000, 0x00325896, 0x00FFFFFF} //синяя
  614.         };
  615.  
  616.  
  617.  
  618.         //--------Более оптимальная но, более задрочная процедура (если полномочий нет - бесконца клацать подтверждать чтение запись)-------
  619.         try {
  620.             FileConnection fc = (FileConnection) Connector.open("file:///e:/Th");
  621.  
  622.             if (fc.exists())
  623.                 fc.delete();
  624.             fc.create();
  625.            
  626.             DataOutputStream dos =  fc.openDataOutputStream();
  627.  
  628.             dos.writeByte(Theme_old.length); //сохраняем количество векторов
  629.  
  630.             for (int i=0;i<Theme_old.length;i++) //сохраняем елементы вектора
  631.                 for (int j=0; j<Theme_old[i].length;j++)
  632.                 {
  633.                     dos.writeInt(Theme_old[i][j]); // Push the score into a byte array.
  634.                 }
  635.  
  636.            
  637.             //тут начинается проверка себя на вшивость
  638.             DataInputStream dis =  fc.openDataInputStream();
  639.             int[][] Theme_test=null;
  640.            
  641.             Theme_test = new int[ dis.readByte() ][];
  642.            
  643.             for (int i=0;i<Theme_test.length;i++)
  644.                 Theme_test[i] = new int[ ThemeItemCount ];
  645.  
  646.             for (int i=0;i<Theme_test.length;i++)
  647.                 for (int j=0;j<ThemeItemCount;j++)
  648.                     Theme_test[i][j]=dis.readInt();
  649.  
  650.             if (Theme_old.length==Theme_test.length) System.out.println("Theme.length pass"); //сообственно проверка
  651.             else System.out.println("Theme.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  652.             for (int i=0; i<Theme_old.length; i++)
  653.             {
  654.                 if (Theme_old[i].length==Theme_test[i].length) System.out.println("Theme["+i+"].length pass"); //сообственно проверка
  655.                 else System.out.println("Theme["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  656.                 for (int j=0; j<Theme_old[i].length;j++)
  657.                     if (Theme_old[i][j]==Theme_test[i][j]) System.out.println("Theme_old["+i+"]["+j+"]==Theme_test["+i+"]["+j+"] pass");
  658.                     else System.out.println("Theme_old["+i+"]["+j+"]!=Theme_test["+i+"]["+j+"] fail; Theme_old["+i+"]["+j+"]="+Theme_old[i][j]+", Theme_test["+i+"]["+j+"]="+Theme_test[i][j]+"!!!!!!!!!!!!!!!!!!!!");
  659.             }
  660.             dis.close();
  661.             //----------------------------------------
  662.             dos.close();
  663.             fc.close();
  664.  
  665.         } catch (IOException ex) {
  666.             ex.printStackTrace();
  667.         }
  668. //--------------------------------------------------------------------------------------------------------------------------------
  669.  
  670.         //Чтоб я видел что выполнилась процедура закидывания в бинарник
  671.         System.out.println("themeToBin() is run!000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
  672.                
  673.     }//*/
  674.  
  675.     //Уровень*/
  676.     private int uroven = 0;
  677.  
  678.  
  679.  
  680.     /**Читаем коеф для темы из ресурса*/
  681.     public void read_theme(){
  682.          try {
  683.            
  684.             InputStream is = canvasP.class.getResourceAsStream("Th");
  685.             DataInputStream dis = new DataInputStream(is);
  686.  
  687.            
  688.             ThemeCount = dis.readByte();
  689. //            for (int i=0;i<d;i++)
  690. //            {
  691. //                 dis.readByte();
  692. //                 //System.out.println("k_test["+i+"].lenght"+k_test[i].length);
  693. //            }
  694.  
  695.             Theme = new int[ThemeItemCount];
  696.  
  697.             if (NTheme != 0)
  698.                 dis.skip(NTheme*ThemeItemCount*4);
  699.  
  700.             for (int i=0;i<Theme.length;i++)
  701.                 Theme[i]=dis.readInt();
  702.  
  703.             is.close();
  704.             dis.close();
  705.         } catch (IOException ex) {
  706.             ex.printStackTrace();
  707.         }
  708.        
  709.        
  710.     }
  711.  
  712.     /**Процедура заполняющая массив коефициентов, читает из ресурсов*/
  713.     public void read_k(){
  714.         try {
  715.            
  716.             InputStream is = canvasP.class.getResourceAsStream("k");
  717.             DataInputStream dis = new DataInputStream(is);
  718.  
  719.             byte k_lenght = dis.readByte();
  720.             k = new double[ k_lenght ][];
  721.  
  722.             for (int i=0;i<k_lenght;i++)
  723.             {
  724.                 k[i] = new double[ dis.readByte() ];
  725.                 //System.out.println("k_test["+i+"].lenght"+k_test[i].length);
  726.             }
  727.  
  728.             for (int i=0;i<k.length;i++)
  729.                 for (int j=0;j<k[i].length;j++)
  730.                     k[i][j]=dis.readDouble();
  731.  
  732.             is.close();
  733.             dis.close();
  734.         } catch (IOException ex) {
  735.             ex.printStackTrace();
  736.         }
  737.     }
  738.  
  739.     /***/
  740.     public void read_text(){
  741.  
  742.  
  743.  
  744.         try {
  745.  
  746.             //тут начинается проверка себя на вшивость (MAIN) !!!!!одинарный!!!!!
  747.             InputStream is = canvasP.class.getResourceAsStream("RU");
  748.             DataInputStream dis = new DataInputStream(is);
  749.  
  750.  
  751.             MAIN = new String[ dis.readByte() ];
  752.              for (int i=0;i<MAIN.length;i++)
  753.                 MAIN[i]=dis.readUTF();
  754.  
  755.             //dis.close();
  756.             //--------------------------------------------------------------------
  757.  
  758.             //тут начинается проверка себя на вшивость (text) !!!!!двойной!!!!!
  759.             //DataInputStream dis =  fc.openDataInputStream();
  760.             //String[][] text_test=null;
  761.  
  762.             text = new String[ dis.readByte() ][];
  763.  
  764.             for (int i=0;i<text.length;i++)
  765.                 text[i] = new String[dis.readByte()];
  766.  
  767.             for (int i=0;i<text.length;i++)
  768.                 for (int j=0;j<text[i].length;j++)
  769.                     text[i][j]=dis.readUTF();
  770.  
  771.             //dis.close();
  772.             //-------------------------------------------------------------
  773.  
  774.             //тут начинается проверка себя на вшивость (temperat_text) !!!!!одинарный!!!!!
  775.             //DataInputStream dis =  fc.openDataInputStream();
  776.             //String[] temperat_text_test=null;
  777.  
  778.             temperat_text = new String[ dis.readByte() ];
  779.              for (int i=0;i<temperat_text.length;i++)
  780.                 temperat_text[i]=dis.readUTF();
  781.  
  782.             //dis.close();
  783.             //--------------------------------------------------------------------
  784.  
  785.             //тут начинается проверка себя на вшивость (Details) !!!!!двойной!!!!!
  786.             //DataInputStream dis =  fc.openDataInputStream();
  787.             //String[][] Details_test=null;
  788.  
  789.             /*
  790.             Details = new String[ dis.readByte() ][];
  791.  
  792.             for (int i=0;i<Details.length;i++)
  793.                 Details[i] = new String[dis.readByte()];
  794.  
  795.             for (int i=0;i<Details.length;i++)
  796.                 for (int j=0;j<Details[i].length;j++)
  797.                     Details[i][j]=dis.readUTF();
  798.              */
  799.  
  800.             //dis.close();
  801.             //-------------------------------------------------------------
  802.  
  803.             //тут начинается проверка себя на вшивость (options) !!!!!одинарный!!!!!
  804.             //DataInputStream dis =  fc.openDataInputStream();
  805.             //String[] ThemeTitle_test=null;
  806.  
  807.             options = new String[ dis.readByte() ];
  808.              for (int i=0;i<options.length;i++)
  809.                 options[i]=dis.readUTF();
  810.  
  811.             //dis.close();
  812.             //--------------------------------------------------------------------
  813.  
  814.             //тут начинается проверка себя на вшивость (ThemeTitle) !!!!!одинарный!!!!!
  815.             //DataInputStream dis =  fc.openDataInputStream();
  816.             //String[] ThemeTitle_test=null;
  817.  
  818.             ThemeTitle = new String[ dis.readByte() ];
  819.              for (int i=0;i<ThemeTitle.length;i++)
  820.                 ThemeTitle[i]=dis.readUTF();
  821.  
  822.             dis.close();
  823.             //--------------------------------------------------------------------
  824.  
  825.         } catch (IOException ex) {
  826.             ex.printStackTrace();
  827.         }
  828.  
  829.     }
  830.  
  831.  
  832. /**Тестовая процедура для оптимизации мидлета, конкретно: читает из ресурсов информацию
  833. public void test(){
  834.    
  835.     InputStream IS = canvasP.class.getResourceAsStream("lang");
  836.    
  837.     byte data[] = new byte [8];
  838.     try {
  839.         IS.read(data,0,data.length); //читаем
  840.     } catch (IOException ex) {
  841.         ex.printStackTrace();
  842.     }
  843.    
  844. //    DataInputStream DIS = (DataInputStream) IS;
  845.     String str=null;
  846.  
  847.  
  848.     //http://www.javable.com/docs/articles/unicode/   -java unicode
  849.     //str = new String(data, "UTF8");  -массив байтов в текст Юникод
  850.     //byte[] data = priwet.getBytes("UTF8");  -текст Юникод в массив байтов
  851.  
  852.     try {
  853.         str = new String(data, "UTF16");
  854.     } catch (UnsupportedEncodingException ex) {
  855.         ex.printStackTrace();
  856.     }
  857.  
  858.     System.out.println("str = "+str);
  859.    
  860. }//*/
  861.    
  862.    
  863.    
  864.     /**Процедура проверяющая соотвестсвует ли количество елементов массивов(коефициентов, и названия величин и пояснения)*/
  865.     public void testForMassive(){
  866.         int i=0;
  867.         int j=0;
  868.         int m=0;
  869.         m=java.lang.Math.max(Math.max(k.length, text.length), 0/*Details.length*/);
  870.        
  871.        
  872.              
  873.         for (i=0; i<m;i++)
  874.         {
  875.             if ( k[i].length==text[i].length )
  876.                 j++;
  877.             else
  878.                 System.out.println("TestForMassive FAILED, j="+j);
  879.         }
  880.  
  881.         if (j==m) System.out.println("TestForMassive successful");
  882.        
  883.     }
  884.  
  885.  
  886. /**Перерисовка экрана*/
  887. public void paint(Graphics g) {
  888.  
  889.     Font font=null;
  890.  
  891.     if (g.getClipWidth() < 1175/*175*/)
  892.     {
  893.         g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_MEDIUM));
  894.     } else {g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_MEDIUM));}
  895.  
  896.     font = g.getFont();
  897.  
  898.     if (once)
  899.     {
  900.        
  901.        
  902.         HeightLine = font.getHeight() + 2;
  903.         for (short j = 0; j <= text.length-1; j++){
  904.             o[j] = 0;
  905.             for (short i = 0; i <= text[j].length-1; i++)
  906.             {
  907.                if (font.stringWidth(text[j][i])+4 > o[j])
  908.                {
  909.                    o[j] = font.stringWidth(text[j][i])+4;
  910.                }
  911.             }
  912.         }
  913.  
  914.         uroven = MAIN.length+1;
  915.         once = false;
  916.     }
  917.  
  918.     if (show) {
  919.         if (uroven > 2 && uroven < MAIN.length) {Show(g, font);} else { show = false;}
  920.     } else {
  921.        
  922.         if (uroven>=3 && uroven <= MAIN.length-1) wid = o[uroven-3]; else wid = font.stringWidth("00")+4;
  923.         Fon(g);
  924.         if ( uroven != 1){
  925.            
  926.             g.setColor(Theme[2]);
  927.             int fW;
  928.             if (uroven > MAIN.length+1) {
  929.                 fW = font.stringWidth(options[uroven-(MAIN.length+2)]);
  930.                 g.drawString(options[uroven-(MAIN.length+2)],(g.getClipWidth()-fW)/2, 0 ,0);                
  931.             }
  932.             else {
  933.                 fW = font.stringWidth(MAIN[uroven-2]);
  934.                 g.drawString(MAIN[uroven-2],(g.getClipWidth()-fW)/2, 0 ,0);
  935.             }
  936.            
  937.            
  938.  
  939.  
  940.             if (uroven >=3 && uroven <= MAIN.length-1) {
  941.                 g.setColor(Theme[0]);
  942.                 for (int i = 0; i <= text[uroven-3].length-1; i++){
  943.                     if (i > eN - 1) {  
  944.                         int x = font.stringWidth(text[uroven-3][i]);
  945.                         g.drawString(text[uroven-3][i], (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine)-1, 0); //40=>50
  946.                         if (i != NLinePos-1) {
  947.                             g.drawString( Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][i] / k[uroven-3][NLinePos-1] ) ),
  948.                                     wid+2, (i*HeightLine+HeightLine+2)-2 - eN*HeightLine, 0);//42=>52
  949.                         }
  950.                     }  
  951.                 }
  952.  
  953.            
  954.             } else if (uroven == 2) temperatura1(g, font);
  955.             else if (uroven == MAIN.length) main1(g, font, 1);
  956.             else if (uroven == MAIN.length+1) about1(g, font);
  957.             else if (uroven == MAIN.length+2) main1(g, font, 3);
  958.             else if (uroven == MAIN.length+2+1) precision(g, font);
  959.        
  960.            
  961.             //Если прийдется что-то вводить за пределами конвертера то Добавлять условия сюда
  962.             //(Исключающее ИЛИ "^")
  963.             if (uroven < MAIN.length) RamkaAndVvod(g, font);
  964.         } else main1(g, font, 0);
  965.    
  966.        
  967.        
  968.         if (uroven != MAIN.length+1)
  969.         {
  970.             setScroll(g);
  971.             Ramka(g);
  972.         }
  973.        
  974.         //Отладка Чтоб по голове недали!
  975.         //слово тест в верхних углах экрана
  976.         g.setColor(Theme[4]);
  977.         g.drawString("test",0,0,0);
  978.         g.drawString("test", g.getClipWidth()-font.stringWidth("test") ,0 ,0 );
  979.         //-----------------------------
  980.        
  981.     }
  982.    
  983.       /**MAIN.length+1;*/
  984.       /**
  985.       g.setColor(Theme[0]);
  986.    
  987.       g.drawString( String.valueOf(iii), 0, 0, 0);
  988.  
  989.       g.drawString(  Gen , 42, NLine*20+2, 0); // m
  990.  
  991.       for (int i = 0; i <= S.length-1; i++){
  992.           int x = font.stringWidth(S[i]);
  993.           g.drawString(S[i], (40-x)/2, (i+1)*20, 0);
  994.           if (i != NLine-1) {
  995.               g.drawString( String.valueOf( Double.parseDouble( Gen ) * k_old[i] / k_old[NLine-1] ), 42, i*20+22,0 );
  996.           }
  997.       }
  998. /**--------------Отладочная информация-----------------      
  999.       g.drawString( String.valueOf( test )+" Колво" ,3,142,0 );
  1000.       g.drawString( String.valueOf( Double.parseDouble( Gen ))+" Число" ,3,162,0 );
  1001.       g.drawString( test2+" test2" ,3,182,0 );
  1002.      
  1003.       g.setFont(font.getFont(font.FACE_SYSTEM,font.STYLE_BOLD,font.SIZE_LARGE));
  1004.       g.drawString( String.valueOf( font.stringWidth("Round") ),3,1,0 );
  1005.  
  1006.       g.setFont(font.getFont(font.FACE_SYSTEM,font.STYLE_BOLD,font.SIZE_SMALL));
  1007.       g.drawString( String.valueOf( font.stringWidth("Round") ),33,1,0 );
  1008.       g.drawLine()
  1009.  
  1010.       //g.drawString(String.valueOf( font. ),30,1,0);
  1011. //-----------------------------------------------------*/
  1012.    
  1013.     //Отладочная информация - сводка глобальных переменных  
  1014.     /*
  1015.     System.out.println( "--------------------------------------------");
  1016.     System.out.println( "Precision="+Precision);
  1017.     System.out.println( "NLine="+NLine);
  1018.     System.out.println( "eN="+eN);
  1019.     System.out.println( "MAIN.length="+MAIN.length);
  1020.     System.out.println( "NTheme="+NTheme);
  1021.     //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1022.     System.out.println( "uroven="+uroven);
  1023.     System.out.println( "Gen="+Gen);
  1024.     System.out.println( "NLinePos="+NLinePos);
  1025.     System.out.println( "Star="+Star);
  1026.     System.out.println( "otr="+otr);
  1027.     System.out.println( "RPos="+RPos);
  1028.     System.out.println( "wid="+wid);
  1029.     System.out.println( "show="+show);
  1030.     System.out.println( "once="+once);
  1031.     System.out.println( "PraviyKrayRamki="+PraviyKrayRamki);
  1032.     System.out.println( "OnceInProject="+OnceInProject);
  1033.     System.out.println( "HeightLine="+HeightLine);
  1034.     System.out.println( "ddY="+ddY);
  1035.     System.out.println( "oneS="+oneS);
  1036.     System.out.println( "oneSymb="+oneSymb);
  1037.  
  1038.     //System.out.println( "Precision="+Precision);
  1039.     //System.out.println( "Precision="+Precision);
  1040.     System.out.println( "--------------------------------------------" );// */
  1041.   }
  1042.  
  1043. /** маин форма */
  1044. public void main1(Graphics g, Font font, int number){
  1045.    
  1046.     int a = 0;
  1047.     if (number == 0){
  1048.         int w = g.getClipWidth();
  1049.         int fW = font.stringWidth("Меню");
  1050.        
  1051.         g.setColor(Theme[2]);
  1052.         g.drawString("Меню",(w-fW)/2, 0 ,0);
  1053.        
  1054.         a = MAIN.length;
  1055.     } else if (number == 1) {a = options.length;}
  1056.       else if (number == 3){ a = ThemeTitle.length; }
  1057.    
  1058.     g.setColor(Theme[0]);
  1059.    
  1060.     for (byte i = 0; i < a; i++){
  1061.       if (i > eN - 1) {  
  1062.         int x = font.stringWidth("00");
  1063.         if (i >= 0 && i <= 8) g.drawString("0"+String.valueOf(i+1), (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine), 0); //40=>50}
  1064.         else g.drawString(String.valueOf(i+1), (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine), 0); //40=>50
  1065.        
  1066.         if (number == 0) g.drawString( MAIN[i] , wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0 );//42=>52
  1067.         else if (number == 1) g.drawString( options[i] , wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0 );//42=>52
  1068.         else if (number == 3) g.drawString( ThemeTitle[i], wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0);
  1069.        
  1070.       }
  1071.      
  1072.     }
  1073.    
  1074.     //Ramka(g);
  1075. //-------------отладочная-----------------
  1076. //Double.longBitsToDouble();
  1077. //Short.
  1078. //    String LLL = Double.toString(10000000.0/3.0);
  1079. //    int LLL = text[1].length;
  1080. //    g.drawString( LLL ,130,202,0);
  1081.    
  1082. //----------------------------------------
  1083. }
  1084.  
  1085. /**Меню точность*/
  1086. public void precision(Graphics g, Font font){
  1087.     g.setColor(Theme[0]);
  1088.     int a=g.getClipHeight()/HeightLine-1; //колво строк в экране
  1089.     for (int i=0; i<a; i++){
  1090.         g.drawString(String.valueOf(i+eN)+" знак(ов)",wid, (i+1)*HeightLine,0);
  1091.     }
  1092. }
  1093.  
  1094. public static Double valueOf(String s) throws NumberFormatException
  1095. {
  1096.     return new Double(valueOf(s).doubleValue());
  1097. }
  1098.  
  1099.  
  1100. /**Округляет*/
  1101. public String Round(String str){
  1102.  
  1103.     String part3;
  1104.  
  1105.     System.out.println("------>");
  1106.     System.out.println(str);
  1107.     System.out.println("str.length="+str.length());
  1108.    
  1109. //    if (str.length()>3)
  1110. //        for (int i=0; i<5; i++)
  1111. //            if ( str.charAt( str.length()-i-1 ) == 'e')
  1112. //            {
  1113. //                npl=i;
  1114. //                break;
  1115. //            }
  1116.  
  1117.     int npl = str.indexOf("E");
  1118.     //npl++;
  1119.     System.out.println("npl="+npl);
  1120.  
  1121.     if (npl<0) {
  1122.         npl=str.length();
  1123.         part3="";
  1124.     }
  1125.     else
  1126.     {
  1127.         part3=str.substring(npl);
  1128.     }
  1129.    
  1130.     System.out.println("nplS = "+part3);
  1131.    
  1132.     int np=str.indexOf('.');
  1133.     System.out.println("np="+np);
  1134.  
  1135.     String per0 = str.substring(0, np);
  1136.     System.out.println("per0="+per0);    
  1137.    
  1138.    
  1139.     int mprx= Math.min( Precision+np+1, npl );
  1140.     System.out.println("mprx="+mprx);
  1141.  
  1142.     String per1 = str.substring(np+1, mprx);
  1143.     System.out.println("per1="+per1);
  1144.  
  1145.     //убиваем нули и округляем девятки
  1146.     //if (mprx<str.length())
  1147.         if ( str.charAt(mprx) == '5' ||
  1148.                 str.charAt(mprx) == '4' ||
  1149.                 str.charAt(mprx) == '3' ||
  1150.                 str.charAt(mprx) == '2' ||
  1151.                 str.charAt(mprx) == '1' ||
  1152.                 str.charAt(mprx) == '0' )
  1153.             System.out.println("<5 str.charAt(mprx)="+str.charAt(mprx)+"   UARRRAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!");
  1154.             else
  1155.             System.out.println(">5 str.charAt(mprx)="+str.charAt(mprx)+"   UARRRAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!");
  1156.             //for (int i=0;i<;i++)
  1157.             {
  1158.  
  1159.             }
  1160.  
  1161.             //режет символы после Прецишен, надо сделать округлятель
  1162.    
  1163.     return per0+"|"+"."+"|"+per1+"|"+part3;
  1164.     //return per0+"."+per1+part3;
  1165. }
  1166.  
  1167. /** Температурная форма */
  1168. public void temperatura1(Graphics g, Font font){
  1169.  
  1170.    
  1171.    
  1172.     g.setColor(Theme[0]);
  1173.     for (byte i = 0; i<3; i++){
  1174.           int x = font.stringWidth(temperat_text[i]);
  1175.           g.drawString(temperat_text[i], (wid-x)/2, ((i+1)*HeightLine), 0);//40=>50
  1176.     }
  1177.    
  1178.     g.drawString(  Gen , wid+2, (NLinePos*HeightLine+2)-2, 0); //42=>52
  1179.     if (NLinePos == 1){
  1180.         g.drawString( Round( Double.toString( Double.parseDouble( Gen ) + 273.15 )), wid+2, (1*HeightLine+HeightLine+2)-2,0 );//42=>52
  1181.         g.drawString(  Round( Double.toString(Double.parseDouble( Gen ) * 1.8 + 32.0  )), wid+2, (2*HeightLine+HeightLine+2)-2,0 );//42=>52
  1182.        
  1183.     } else if (NLinePos == 2){
  1184.         g.drawString( Round( Double.toString( Double.parseDouble( Gen ) - 273.15 )), wid+2, (0*HeightLine+HeightLine+2)-2,0 );//42=>52
  1185.         g.drawString( Round( Double.toString( ((Double.parseDouble( Gen ) - 273.15)*1.8)+32 )), wid+2, (2*HeightLine+HeightLine+2)-2,0 );//42=>52
  1186.     } else {
  1187.         g.drawString( Round( Double.toString( ( Double.parseDouble( Gen ) -32.0) / 1.8  )), wid+2, (0*HeightLine+HeightLine+2)-2,0 );//42=>52
  1188.         g.drawString( Round( Double.toString( ((Double.parseDouble( Gen ) - 32.0) / 1.8)+273.15 )), wid+2, (1*HeightLine+HeightLine+2)-2,0 );//42=>52
  1189.     }
  1190.  
  1191.     RamkaAndVvod(g, font);
  1192. }
  1193.  
  1194. /** Рамка с вводом */
  1195. public void RamkaAndVvod(Graphics g, Font font){
  1196.    
  1197.     //Ramka(g);
  1198.  
  1199.     g.setColor(Theme[0]);
  1200.     g.drawString(  Gen , wid+2, (NLinePos*HeightLine+2 - eN*HeightLine)-2, 0); //42=>52
  1201. }
  1202.  
  1203. /**Запуск "о проекте"*/
  1204. public void about1(Graphics g, Font font){
  1205.     g.setColor(Theme[11]);
  1206.     g.fillRect(5,5,g.getClipWidth()-10,g.getClipHeight()-10);
  1207.    
  1208.     g.setColor(Theme[12]);
  1209.     g.fillRect(7,7,g.getClipWidth()-14,g.getClipHeight()-14);
  1210.    
  1211.     g.setColor(Theme[13]);
  1212.     String str[]/*;*/ =
  1213.     {
  1214.         "ТЕСТОВАЯ ВЕРСИЯ (0.31)",
  1215.         "АВТОР НЕ НЕСЕТ",
  1216.         "НИКАКОЙ",
  1217.         "ОТВЕТСТВЕННОСТИ!",
  1218.         "Посвящается группе ",
  1219.         "«М-90», УДХТУ",
  1220.         "Сделал Chemist",
  1221.         "в 2007-2009г",
  1222.         "Замечания на e-mail:",
  1223.         "«Chemist-i@mail.ru»",
  1224.         "Посетите интернет",
  1225.         "страницу",
  1226.         "«Chemist-Dnepr.narod.ru»",
  1227.         "Профиль MIDP-2.0",
  1228.         "Конфигурация CLDC 1.1",
  1229.         "Удачи!",
  1230. //
  1231. //        "i tut mnogo",
  1232. //        "lishnego",
  1233. //        "bazara"
  1234.     };
  1235.  
  1236.  
  1237. //    String strX;
  1238. //    strX = "ТЕСТОВАЯ ВЕРСИЯ (0.30); АВТОР НЕ НЕСЕТ; НИКАКОЙ; ОТВЕТСТВЕННОСТИ!; Посвящается группе; «М-90», УДХТУ; Сделал Chemist в 2007-2009г; Замечания на e-mail:; «Chemist-i@mail.ru»; Посетите интернет страницу; «Chemist-Dnepr.narod.ru»; Профиль MIDP-2.0; Конфигурация CLDC 1.1; Удачи!;";
  1239. //
  1240. //    int j=0;
  1241. //    int k=0;
  1242. //    String tstr = "";
  1243. //    boolean b=false;
  1244. //    do{
  1245. //        tstr = "";
  1246. //        //j=0;
  1247. //        do{
  1248. //            if (tstr.length()>0)
  1249. //                if ( font.stringWidth(tstr)>=(g.getClipWidth()-20) )
  1250. //                {
  1251. //                    //System.out.println("j="+j);
  1252. //                    //break;
  1253. //                    do{
  1254. //                        j--;
  1255. //                        if (j==0 || tstr.charAt(j)==' ' )
  1256. //                        {
  1257. //                            b=true;
  1258. //                            break;
  1259. //                        }
  1260. //                    } while(true);
  1261. //                }
  1262. //            if (b)
  1263. //            {
  1264. //                tstr = tstr.substring(0, j);
  1265. //                break;
  1266. //            }
  1267. //            if ( j==strX.length()-1 ) break;
  1268. //            tstr += strX.charAt(j);
  1269. //            j++;
  1270. //        } while(true);
  1271. //        b=false;
  1272. //
  1273. //        g.drawString(tstr, 10, 10+k*HeightLine, 0);
  1274. //
  1275. //        if(k==100) break;
  1276. //        k++;
  1277. //    } while(true);
  1278.    
  1279.     int hei;
  1280.     int heightLines = (g.getClipHeight()-10)/HeightLine; //колво строк которое влазит в экрарн по высоте
  1281.     if (heightLines>str.length) heightLines=str.length;
  1282.     if (ddY>0) ddY=0;
  1283.     if (ddY<heightLines-str.length) ddY = (byte)(heightLines-str.length);
  1284.     for (byte i = (byte)(-ddY); i < heightLines-ddY; i++){
  1285.         hei = font.stringWidth(str[i]);
  1286.         g.drawString(str[i],(g.getClipWidth()-hei)/2,((i+ddY)*HeightLine)+7,0);
  1287.     }
  1288.     str = new String[0];
  1289.  
  1290.     g.drawString("Далее", 10, g.getClipHeight()-5-HeightLine, 0);
  1291.     g.drawString("Выход", g.getClipWidth()-10-font.stringWidth("Выход"), g.getClipHeight()-5-HeightLine, 0);
  1292.    
  1293. //   g.setColor(Theme[13]);
  1294. //   String str[] ={
  1295. //        "ТЕСТОВАЯ ВЕРСИЯ !!! (13)",
  1296. //        "НЕ ИСПОЛЬЗОВАТЬ ДЛЯ",
  1297. //        "ОТВЕТСТВЕННЫХ",
  1298. //        "РАСЧЕТОВ !!!",
  1299. //        "Сделал Chemist в 2007г",
  1300. //        "Замечания на e-mail:",
  1301. //        "\u00ABAleksCherMy@mail.ru\u00BB",
  1302. //        "Профиль MIDP-2.0",
  1303. //        "Конфигурация CLDC-1.1"
  1304. //    };
  1305. //    
  1306. //    for (byte i = 0; i < str.length; i++){
  1307. //        g.drawString(str[i],10,(i*(HeightLine-2))+10,0);
  1308. //    }
  1309.    
  1310. }
  1311.  
  1312. /** Рисует фон */
  1313. public void Fon(Graphics g){
  1314.     g.setColor(Theme[6]);
  1315.     g.fillRect(0,0,240,320);
  1316.  
  1317.     g.setColor(Theme[1]);
  1318.     g.fillRect(0,0,240,HeightLine);
  1319.     g.fillRect(0,0,wid,320); //40=>50
  1320.    
  1321.    
  1322.     g.setColor(Theme[5]);
  1323.     for (int i = 1; i < 11; i++){
  1324.         g.fillRect(wid,i*2*HeightLine,240,HeightLine); //40=>50
  1325.        g.fillRect(0,(i*2*HeightLine)-HeightLine,wid,HeightLine);//40=>50
  1326.    }
  1327.    
  1328.     g.setColor(Theme[4]);
  1329.     for (int i = 1; i < 22; i++) g.drawLine(0, i*HeightLine-1,240, i*HeightLine-1);
  1330.    
  1331. }
  1332.  
  1333. /** Рамочка */  
  1334. public void Ramka(Graphics g){
  1335.     g.setColor(Theme[3]);
  1336.  
  1337.     g.drawLine(0,HeightLine*NLine - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine - eN*HeightLine); //Верх
  1338.     g.drawLine(0,HeightLine*NLine+HeightLine-2 - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Низ
  1339.     g.drawLine(0,HeightLine*NLine - eN*HeightLine,0,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Лево
  1340.     g.drawLine(g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Право
  1341.   }
  1342.  
  1343. /** Создает число получаемое с клавиатуры */
  1344. public String AddSymbol(String OldExt, int Key) {
  1345.    
  1346.     if (Key == -8 || Key == -10){
  1347.         if (Star > 0) Star -= 1;
  1348.         byte a;
  1349.         if (Double.parseDouble(OldExt) < 0 ) a = 2; else a = 1;
  1350.         if (OldExt.length() > a){
  1351.             OldExt = OldExt.substring(0,OldExt.length()-1);
  1352.         } else OldExt = "0";        
  1353.     } else if ((Key>=KEY_NUM0 && Key<=KEY_NUM9) || Key == KEY_STAR || Key == KEY_POUND ){
  1354.  
  1355.        
  1356.     if ( Double.parseDouble(OldExt) == 0 && Star == 0 && Key != KEY_STAR && Key != KEY_POUND) OldExt = "";
  1357.    
  1358.  
  1359.     if (Key == KEY_NUM0){
  1360.         OldExt += "0";
  1361.     } else if (Key == KEY_NUM1) {
  1362.         OldExt += "1";
  1363.     } else if (Key == KEY_NUM2) {
  1364.         OldExt += "2";
  1365.     } else if (Key == KEY_NUM3){
  1366.         OldExt += "3";
  1367.     } else if (Key == KEY_NUM4){
  1368.         OldExt += "4";
  1369.     } else if (Key == KEY_NUM5){
  1370.         OldExt += "5";
  1371.     } else if (Key == KEY_NUM6){
  1372.         OldExt += "6";
  1373.     } else if (Key == KEY_NUM7){
  1374.         OldExt += "7";
  1375.     } else if (Key == KEY_NUM8){
  1376.         OldExt += "8";
  1377.     } else if (Key == KEY_NUM9){
  1378.         OldExt += "9";
  1379.     } else if (Key == KEY_STAR && Star <= 0){
  1380.         OldExt += ".";
  1381.         Star += 1;
  1382.     } else if (Key == KEY_POUND){
  1383.         if (Double.parseDouble(OldExt) < 0) OldExt = OldExt.substring(1);
  1384.         else if (Double.parseDouble(OldExt) > 0) OldExt = "-"+OldExt;
  1385.     }
  1386.    
  1387.     if (Star > 0 && Key != KEY_STAR && Key != KEY_POUND){
  1388.         Star += 1;
  1389.     }
  1390.    
  1391.    
  1392.     }
  1393.    return OldExt;
  1394. }
  1395.  
  1396. /**Обнулить все переменные уровня*/
  1397. public void Reset1(boolean NL){
  1398.     Gen = "0";
  1399.     Star = 0;
  1400.     otr = false;
  1401.     if (NL) NLine = 1;
  1402. }
  1403.  
  1404. /**расширенное конвертирование
  1405.  Показать на весь экран сколько именно
  1406.  равняется данная величина к вводимой*/
  1407. public void Show(Graphics g, Font font){
  1408.     if (font.stringWidth(Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][NLine-1] / k[uroven-3][NLinePos-1] )))>g.getClipWidth()-10){
  1409.         g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));
  1410.     }
  1411.  
  1412.    
  1413.     g.setColor(Theme[11]);
  1414.     g.fillRect(5,5,g.getClipWidth()-10,g.getClipHeight()-10);
  1415.     g.setColor(Theme[12]);
  1416.     g.fillRect(7,7,g.getClipWidth()-14,g.getClipHeight()-14);
  1417.    
  1418.     g.setColor(Theme[13]);
  1419.     g.drawString( text[uroven-3][NLinePos-1]+":",10,10,0); //Details -> text
  1420.     g.drawString( Gen, 10, 10+HeightLine-2, 0);
  1421.     g.drawString( text[uroven-3][NLine-1]+":",10,10+2*(HeightLine-2),0); ////Details -> text
  1422.     g.drawString( Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][NLine-1] / k[uroven-3][NLinePos-1] )),10,10+3*(HeightLine-2),0);
  1423.  
  1424. }
  1425.  
  1426.  
  1427. /**Скролл. Вычисляет и рисует полоску прокрутки*/
  1428. public void setScroll(Graphics g){
  1429.     int y; //количество строк по вертикали
  1430.  
  1431.     if (uroven == 1) //уровень "главное меню"
  1432.         y = MAIN.length; //количество пунктов главного списка меню
  1433.      else
  1434.         if (uroven == 2) //уровень "температура"
  1435.             y = 3; //количество температур (3)
  1436.         else
  1437.             if (uroven == MAIN.length) //уровень опции
  1438.                 y=options.length;//колво пунктов опций
  1439.             else
  1440.                 if (uroven == MAIN.length+1+1) //уровень "выбор темы (опции)"
  1441.                     y=ThemeCount; //количество тем
  1442.                 else
  1443.                     if (uroven == MAIN.length+1+2) //уровень "точность" (не реализовано) //???
  1444.                         y=PrecCount;// количество точностей !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1445.                     else //иначе
  1446.                         if (uroven >= 3 && uroven <= MAIN.length-1)  //если уровень "конвертируемые величины"
  1447.                             y = text[uroven-3].length; //количество величин в данном списке
  1448.                         else //иначе
  1449.                             y=0; //0
  1450.    
  1451.    
  1452.  
  1453.     if ((y*HeightLine)>g.getClipHeight()-HeightLine) { //если количество строк по вертикали больше максимально возможного количества строк которые могут отображатся
  1454.         PraviyKrayRamki = 8; //то рисуем скролл
  1455.         int x = (g.getClipHeight()-HeightLine)*(g.getClipHeight()-HeightLine) / ( (y*HeightLine)  );
  1456.         int xxx = eN*(g.getClipHeight()-HeightLine)/y;
  1457.  
  1458.         g.setColor(Theme[9]);
  1459.         g.fillRect(g.getClipWidth()-7,HeightLine,7,g.getClipHeight()-HeightLine);
  1460.         g.setColor(Theme[10]);
  1461.         g.fillRect(g.getClipWidth()-5,xxx+HeightLine,3,x);
  1462.     } else PraviyKrayRamki = 1; //иначе не рисуем
  1463. }
  1464.  
  1465. /**Запись в рс данных (Номер темы, и т.д.*/
  1466. public void SaveRS(){
  1467.         RecordStore rs = null;
  1468.         try {
  1469.             rs = RecordStore.openRecordStore ( "Sett", true );
  1470.         }catch( RecordStoreNotFoundException e ){// не существует
  1471.  
  1472.         }catch( RecordStoreException e ){ // какие-то другие ошибки
  1473.         }
  1474.     //
  1475.     // Each score is stored in a separate record, formatted with
  1476.     // the score, followed by the player name.
  1477.     //
  1478.          // returned by addRecord but not used
  1479.     ByteArrayOutputStream baos = new ByteArrayOutputStream();
  1480.     DataOutputStream dos = new DataOutputStream(baos);
  1481.     try {
  1482.             dos.writeInt(NTheme);// Push the score into a byte array.
  1483.     }
  1484.     catch (IOException ioe) {
  1485.     }
  1486.  
  1487.     // Extract the byte array
  1488.     byte[] b = baos.toByteArray();
  1489.     // Add it to the record store
  1490.     try {
  1491.         int id = rs.addRecord(b,0,b.length);
  1492.             rs.setRecord(1,b,0,b.length);
  1493.            
  1494.             byte j[]= new byte[1];
  1495.            
  1496.  
  1497.             j[0] = Precision;
  1498.             id = rs.addRecord(j,0,1);
  1499.             rs.setRecord(2,j,0,1);
  1500.     }
  1501.     catch (RecordStoreException rse) {
  1502.             //System.out.println(rse);
  1503.         //rse.printStackTrace();
  1504.     }
  1505.        
  1506.         try {
  1507.             rs.closeRecordStore();
  1508.         } catch( RecordStoreNotOpenException e ){// уже закрыта
  1509.         } catch( RecordStoreException e ){       // какие-то другие ошибки
  1510.         }
  1511.     }
  1512.  
  1513. /**Загрузка параметров*/
  1514. public void ReadRS(){
  1515.      
  1516.        //--------Код на тесте-------------------------
  1517.        //-----Загрузка и сохранение параметров--------
  1518.        RecordStore rs = null;
  1519.         try {
  1520.             rs = RecordStore.openRecordStore("Sett", true);
  1521.         } catch( RecordStoreNotFoundException e ){ // не существует
  1522.             uroven = MAIN.length+1; //здесь можно поставить уровень выбора языка (ибо этот код выполняется единственный раз при первом запуске)
  1523.             OnceInProject = true;
  1524.         } catch (RecordStoreException ex) { //Какие-то другие ошибки
  1525.             //ex.printStackTrace();
  1526.         }
  1527.        
  1528.        byte b[] = null;
  1529.        byte j[] = {16};
  1530.         try {
  1531.             b = rs.getRecord(1); //NTheme record
  1532.             j = rs.getRecord(2); //Precision record
  1533.         } catch (InvalidRecordIDException ex) {
  1534.             //uroven = MAIN.length+1;
  1535.             b = new byte [4];
  1536.             for (byte i = 0; i < 4; i++) b[i] = 0;
  1537.            
  1538.         } catch (RecordStoreNotOpenException ex) {
  1539.             //ex.printStackTrace();
  1540.         } catch (RecordStoreException ex) {
  1541.             //ex.printStackTrace();
  1542.         }
  1543.        
  1544.     ByteArrayInputStream bais = new ByteArrayInputStream(b);
  1545.     DataInputStream dis = new DataInputStream(bais);
  1546.    
  1547.  
  1548.         try {
  1549.         NTheme = dis.readInt();
  1550.             Precision = j[0];
  1551.     }
  1552.     catch (EOFException eofe) {
  1553.         //System.out.println(eofe);
  1554.         //eofe.printStackTrace();
  1555.     }
  1556.     catch (IOException eofe) {
  1557.         //System.out.println(eofe);
  1558.         //eofe.printStackTrace();
  1559.     }
  1560.  
  1561.         try {
  1562.             rs.closeRecordStore();
  1563.         } catch( RecordStoreNotOpenException e ){// уже закрыта
  1564.         } catch( RecordStoreException e ){       // какие-то другие ошибки
  1565.         }
  1566.        //---------------------------------------------
  1567. }
  1568.  
  1569. /** Обработка событий клавиатуры (нажатие)*/
  1570. protected void keyPressed(int key) {
  1571.     if (uroven == MAIN.length+1) { //если уровень эбаут
  1572.         repaint();
  1573.         if (key == LEFT_SOFTKEY || key == FIRE_KEY || key == KEY_NUM5)
  1574.         {
  1575.             uroven = 1;
  1576.         }
  1577.         else if (key == DOWN_KEY || key == KEY_NUM8) ddY--;
  1578.         else if (key== UP_KEY || key == KEY_NUM2) ddY++;
  1579.         else if (key == RIGHT_SOFTKEY || key == BACK_KEY) EXIT();
  1580.     } else {
  1581.         if (uroven == 1 || uroven == MAIN.length || uroven >= MAIN.length+1){
  1582.             if(key == UP_KEY) {
  1583.                 int a = 1;
  1584.                 if (uroven == 1 || uroven == MAIN.length+1) a = MAIN.length;
  1585.                 else if (uroven == MAIN.length) {a = options.length;}
  1586.                 else if (uroven == MAIN.length+1+1) {a = ThemeCount;}
  1587.                 else if (uroven == MAIN.length+1+2) {a = PrecCount;}//колво точностей
  1588.                
  1589.                 if (NLine == 1) NLine = a; else NLine -=1;
  1590.             }
  1591.             else
  1592.                 if (key == DOWN_KEY) {
  1593.                     int a = 1;
  1594.                     if (uroven == 1 || uroven == MAIN.length+1) a = MAIN.length;
  1595.                     else if (uroven == MAIN.length) {a = options.length;}
  1596.                     else if (uroven == MAIN.length+1+1) {a = ThemeCount;}
  1597.                     else if (uroven == MAIN.length+1+2) {a = PrecCount;}//колво точностей
  1598.                    
  1599.                     if(NLine == a) NLine = 1; else NLine += 1;
  1600.                 }
  1601.             else
  1602.                 if (key == FIRE_KEY || key == LEFT_SOFTKEY) {
  1603.                     if (uroven == 1 ){ //Этот иф занимается вибором в меню опций, и выбором самих опций
  1604.                          uroven = NLine+1;
  1605.                          Reset1(true);
  1606.                          NLinePos = NLine;
  1607.                      } else if (uroven == MAIN.length) { //Если Опции то ...
  1608.                         uroven = (MAIN.length+1) + NLine; //
  1609.                        
  1610.                      } else if (uroven == MAIN.length+1+1) {//Переустановка цвета и сохранение в РМС
  1611.                          if (NTheme != NLine - 1)
  1612.                          {
  1613.                             NTheme = NLine - 1;
  1614.                             SaveRS();
  1615.                             read_theme();
  1616.                          }
  1617.                      } else if (uroven == MAIN.length+1+2) { //походу переустановка точности и запись в РМС
  1618.                          if (Precision != Byte.parseByte(String.valueOf(NLine-1)) )
  1619.                          {
  1620.                              Precision = Byte.parseByte(String.valueOf(NLine-1)) ;
  1621.                              SaveRS();
  1622.                          }
  1623.                          uroven = MAIN.length;
  1624.                          NLine = 1;
  1625.                        
  1626.                      } // else Если уровень ... ;
  1627.                 } else
  1628.                     if (key == BACK_KEY || key == RIGHT_SOFTKEY) {
  1629.                         if (uroven == 1) EXIT(); else {
  1630.                             Reset1(true);
  1631.                             uroven = 1;
  1632.                         }
  1633.                 } else
  1634.                     if (key >= KEY_NUM0 && key <= KEY_NUM9){ //Бистрий визов эллементов гл. меню (только главного)
  1635.                         if (uroven==1)
  1636.                             if (oneSymb)
  1637.                             {
  1638.                                 if (key>=KEY_NUM0 && key<=KEY_NUM1)
  1639.                                 {
  1640.                                     oneS=(byte)(key-48);
  1641.                                     oneSymb=false;
  1642.                                 }
  1643.                             }
  1644.                             else
  1645.                             {
  1646.                                 oneSymb=true;
  1647.                                 uroven = oneS*10+(key-48)+1;
  1648.                                 Reset1(true);
  1649.                                 NLinePos = NLine;
  1650.                             }
  1651.                     }
  1652.  
  1653.         } else {        
  1654.             if (key == BACK_KEY || key == RIGHT_SOFTKEY) {
  1655.                 if (show == true) {show = false;} else {
  1656.                     Reset1(true);
  1657.                     uroven = 1;
  1658.                 }
  1659.                
  1660.                
  1661.             } else if (key == C_KEY || key == GREEN_KEY){
  1662.                 show = false;
  1663.                
  1664.                 NLinePos = NLine;
  1665.                 if (RPos) Reset1(false);
  1666.                 RPos = false;
  1667.                
  1668.                 Gen = AddSymbol(Gen, key);
  1669.             } else if (key == DOWN_KEY){
  1670.                 show = false;
  1671.                
  1672.                 RPos = true;
  1673.  
  1674.                 if (uroven != 2)
  1675.                     if (NLine < text[uroven-3].length) NLine += 1; else NLine = 1;
  1676.                 else if (NLine < 3) NLine += 1; else NLine = 1;
  1677.             } else if (key == UP_KEY){
  1678.                 show = false;
  1679.                
  1680.                 RPos = true;
  1681.  
  1682.                 if (NLine > 1 ) NLine -= 1; else if (uroven != 2) NLine = text[uroven-3].length;
  1683.                 else NLine = 3;
  1684.             } else if((key >= KEY_NUM0 && key <= KEY_NUM9) || key == KEY_STAR || key == KEY_POUND) {
  1685.                 show = false;
  1686.                
  1687.                 NLinePos = NLine;
  1688.                 if (RPos) Reset1(false);
  1689.                 RPos = false;
  1690.  
  1691.                 Gen = AddSymbol(Gen,key);
  1692.             } else if (key == FIRE_KEY || key == LEFT_SOFTKEY){
  1693.                         if (show == true) {show = false;} else {show = true;}
  1694.                        
  1695.                    }
  1696.         }
  1697.  
  1698.      
  1699.     }
  1700.  
  1701.    
  1702.    
  1703.         if (NLine*HeightLine - eN*HeightLine >= getHeight()-HeightLine) eN = NLine-((getHeight()-HeightLine)/HeightLine);
  1704.         if (NLine*HeightLine - eN*HeightLine <= 0) eN = NLine - 1;
  1705.  
  1706.  
  1707.         repaint();
  1708.        
  1709.        
  1710.  
  1711.     }
  1712.    
  1713. /** Обработка событий клавиатуры (отпускание)
  1714. /* protected void keyReleased(int key) {
  1715. * keyPressed(key);
  1716. * }
  1717. */
  1718.  
  1719. /** Обработка событий клавиатуры (повторение)*/
  1720. protected  void keyRepeated(int key) {
  1721.     keyPressed(key);
  1722. }
  1723.  
  1724. /**Выход*/
  1725. public abstract void EXIT();
  1726.  
  1727. //protected void pointerPressed(int x, int y){
  1728. //
  1729. //}
  1730.  
  1731. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement