Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * canvasP.java
- *
- * Created on 20 Август 2007 г., 9:33
- *
- * version 0.31 (040909 2359)
- */
- //import com.sun.midp.dev.GraphicalInstaller;
- import java.io.IOException;
- import java.io.InputStream;
- //import java.io.InputStreamReader;
- import java.io.UnsupportedEncodingException;
- import javax.microedition.lcdui.*;
- //import javax.microedition.lcdui.game.*;
- //import javax.microedition.midlet.MIDlet;
- //import P.Students_Converter_by_Chemist;
- import javax.microedition.rms.*;
- import java.io.DataOutputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.ByteArrayInputStream;
- import java.io.DataInputStream;
- import java.io.EOFException;
- import java.io.OutputStream;
- import java.lang.Math.*;
- /**Работа с файловой системой, используется только для процедуры kToBinOne, в билд не входит */
- import javax.microedition.io.Connector;
- import javax.microedition.io.file.*;//*/
- /**------------------------------------------------------------------------------------------*/
- //import sun.misc.FloatingDecimal;
- /**
- * @author Chemist
- * @version 0.30 (TEST 12)
- */
- public abstract class canvasP extends Canvas { //Canvas => GameCamvas
- // отладка в методе паинт
- // g.setColor(0);
- // g.fillRect(0, 0, 100, HeightLine*2);
- // g.setColor(255, 255, 255);
- // g.drawString(String.valueOf(uroven), 0, 0, 0);
- // g.drawString(String.valueOf(MAIN.length), 0, HeightLine, 0);
- //Константы: клавиатуры
- //СЕ_НОКИА_САМСУНГ
- static final byte UP_KEY = -1;
- static final byte DOWN_KEY = -2;
- static final byte LEFT_LEY = -3;
- static final byte RIGHT_KEY = -4;
- static final byte FIRE_KEY = -5;
- static final byte LEFT_SOFTKEY = -6;
- static final byte RIGHT_SOFTKEY = -7;
- static final byte GREEN_KEY = -10;
- //static final byte RED_KEY = -11;
- static final byte BACK_KEY = -11;
- static final byte C_KEY = -8;
- //МОТОРОЛЛА_СИМЕНС_и_др_говно
- // static final byte UP_KEY = -59;
- // static final byte DOWN_KEY = -60;
- // static final byte LEFT_LEY = -61;
- // static final byte RIGHT_KEY = -62;
- // static final byte FIRE_KEY = -26;
- // static final byte LEFT_SOFTKEY = -1;
- // static final byte RIGHT_SOFTKEY = -4;
- // static final byte GREEN_KEY = -11;
- // static final byte RED_KEY = -12;
- // static final byte BACK_KEY = -11;
- //static final byte C_KEY = -0;
- static final byte PrecCount=17; //количество возможных точностей
- static final byte ThemeItemCount=14; //Количество пунктов в массиве "Темы" (теперь он одномерный)
- // if uroven = MAIN.Lenght - options
- // if uroven = MAIN.Lenght + 1 или 0 - about
- // if uroven = MAIN.Lenght + 1 +1 - Выбор темы
- /**Число с клавиатуры ввиде строки*/
- private String Gen; //
- /**Номер "линии рамки выбора"*/
- private int NLine;//
- /**Если модиф=фалсе то НЛинеПост = НЛине*/
- private int NLinePos; //
- /**относительный коэф*/
- private int eN; //
- /**Через какое кол-во нажетий "с" можно "*" отменять*/
- private int Star; //
- /**Отрицательно ли вводимое число*/
- private boolean otr; //
- /**Сам не помню для чего я его ввел*/
- private boolean RPos; //
- /**Ширина левого отступа*/
- private int wid; //
- /**Показывать ли пояснение*/
- private boolean show; //
- /**выполняется один раз при запуске*/
- private boolean once; //
- /**Коэфициент обозначающий длинну максимального отрезка строки + 3*/
- private int o[]; //
- /**Правий край рамки это число зависить от скролла*/
- private byte PraviyKrayRamki; //
- /**Если труе, то при репаинте сразу запустить "опции"*/
- private boolean OnceInProject = false; //
- /**Номер выбраной темы*/
- private int NTheme = 0; //
- /**Высота линии (default = 20)(Зависит от шрифта телефона)*/
- private int HeightLine; //
- /**Точность. т.е. Количиство знаков после запятой*/
- private byte Precision;
- /**Смещение для абоута*/
- private byte ddY=0; //
- /**Первое, второе число при быстром выборе*/
- private byte oneS=0; //
- /***/
- private boolean oneSymb=true;
- //private boolean bolee; //Если true то список больше чем экран
- //private String test2;
- //private int test; //Так, тест
- //private int iii;
- //private double FL;
- /**Текст главного меню и заголовки уровней*/
- static String MAIN[];
- /**Текст подуровней*/
- static String text[][];
- /**Текст подуровня температура*/
- static String temperat_text[];
- /**Пояснение к величинам*/
- //static String Details[][];
- /**Название темы (оформления)*/
- static String ThemeTitle[];
- /**Набор цветов для каждой темы
- Вложеный массив означает следующее:
- *Цвет:
- *
- *1. текста (Любого);
- *2. заголовка
- *3. текста заголовка
- *4. рамки
- *5. разделяющей слои линии
- *6. 1,3,5, ... ,n прямоугольника слева
- *7. 1,3,5, ... ,n прямоугольника справа
- *8. 1,3,5, ... ,n прямоугольника справа ---------------
- *9. 2,4,6, ... ,n+1 прямоугольника справа --------------
- *10. фона скролла
- *11. скролла
- *12. границы (при расширеном показе)
- *13. фона (при расширеном показе)
- *14. текста (при расширеном показе)
- */
- static int Theme[];
- /**Колво тем в бинарнике (нужно для корректного отображения в меню темы)*/
- static byte ThemeCount=0;
- /**Коэфициенты подуровней (То на что умножается вводимое число чтоб получить результат)*/
- static double k[][];
- /**Меню опций*/
- static String options[];
- /**Указатель на экран устройства*/
- //Display myDisplay;
- /** Конструктор просто устанавливает экран.*/
- public canvasP(Display myDisp) {
- /*
- kToBin();
- textArrayToBin();
- themeToBin();
- //*/
- ReadRS();
- read_k();//Загрузка из бин файла коэфициентов
- read_text(); //Загрузка из бин файла с языком
- read_theme(); //Загрузка из бин файла с цветовым оформлением
- testForMassive();
- Gen = "0";
- otr = false;
- Star = 0;
- NLine = 1;
- uroven = 1;
- eN = 0;
- once = true;
- o = new int[MAIN.length-2];
- //DecimalFormat df = new DecimalFormat("###.########"); //(http://www.velocityreviews.com/forums/t139008-java-double-precision.html)
- //super(false);
- myDisp.setCurrent(this);
- repaint();
- //test();
- }
- /**Процедура закидывающая коефициенты в бинарник и сохраняющая в файловой системе (Используется только на стадии разработки, в билд не входит)
- //specification:
- // 0 byte = k.length; //первый байт - сохраняет количество вложеных массивов в "к"
- // 1 - k.length byte = k[x].length;
- // k.length+1 byte = k[0][0];
- public void kToBin(){
- double k_old[][] = {
- {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}, //Приставки
- {96.7841105354059, 9806650.0, 1.0, 100.0, 1000000.0, 1000000.0, 73556.127270818019531660191116245, 73556.127270818019531660191116245, 98.06650}, //Давление
- {1.0e6, 1.0e3, 100.0, 1.0, 0.001, 39.3700787401575, 3.28083989501312, 1.09361329833771, 5.3995680345572354211663066954644e-4, 6.21371192237e-4},//длина
- {10000.0, 1.0, 0.000001, 0.0001, 0.00024710538, 1550.0031, 10.763910416, 1.19599004630108, 0.000003861},//площадь
- {1000.0, 1.0, 264.172052358148, 219.969248299088, 1000000.0, 61023.7440947323, 35.3146667214886, 1.30795061931439, 33814.022701843},//Обьем
- {1.0, 3.6, 1.9438444924, 2.2374145431},//Скорость
- {1.0, 12960.0, 0.01, 0.00001},//ускорение
- {1.0, 1000, 2.2046226218, 0.15747304442, 35.273961949},//Вес
- {31536000000.0 ,31536000.0, 525600.0, 8760.0, 365.0, 52.142857142857142857142857142857, 13.035714285714285714285714285714, 12.166666666666666666666666666667, 11.774193548387096774193548387097, 1.0}, //Время
- {8796093022208.0, 8589934592.0, 8388608.0, 8192.0, 8.0, 1099511627776.0, 1073741824.0, 1048576.0, 1024, 1.0},//Информация
- {9809.5, 9809.5, 9.8095, 13.1547561878824, 1.0, 13.1494638069705, 13.3372082549427, 13.1547539224889, 13.1487059056918}, //Мощность
- {1.0, 1.00041802233042, 1.00052712434329, 0.999228932179151, 1.00066946708399, 252.055963643748, 252.291028628136, 0.252074030013141, 251.995761111111, 10550558526.2, 1055.05585262, 0.251995761111111}, //Энергия
- };
- //--------Более оптимальная но, более задрочная процедура (если полномочий нет - бесконца клацать подтверждать чтение запись)-------
- try {
- FileConnection fc = (FileConnection) Connector.open("file:///e:/k");
- if (fc.exists())
- fc.delete();
- fc.create();
- DataOutputStream dos = fc.openDataOutputStream();
- dos.writeByte(k_old.length); //сохраняем количество векторов
- for (int i=0;i<k_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
- dos.writeByte(k_old[i].length);
- for (int i=0;i<k_old.length;i++) //сохраняем елементы вектора
- for (int j=0; j<k_old[i].length;j++)
- {
- dos.writeDouble(k_old[i][j]); // Push the score into a byte array.
- }
- //тут начинается проверка себя на вшивость
- DataInputStream dis = fc.openDataInputStream();
- double[][] k_test=null;
- byte k_test_lenght = dis.readByte();
- k_test = new double[ k_test_lenght ][];
- for (int i=0; i<k_test_lenght; i++)
- k_test[i] = new double[dis.readByte()];
- for (int i=0;i<k_test.length;i++)
- for (int j=0;j<k_test[i].length;j++)
- k_test[i][j]=dis.readDouble();
- if (k_old.length==k_test.length) System.out.println("k.length pass"); //сообственно проверка
- else System.out.println("k.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<k_old.length; i++)
- {
- if (k_old[i].length==k_test[i].length) System.out.println("k["+i+"].length pass"); //сообственно проверка
- else System.out.println("k["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int j=0; j<k_old[i].length;j++)
- if (k_old[i][j]==k_test[i][j]) System.out.println("k_old["+i+"]["+j+"]==k_test["+i+"]["+j+"] pass");
- 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]+"!!!!!!!!!!!!!!!!!!!!");
- }
- dis.close();
- //----------------------------------------
- dos.close();
- fc.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- //--------------------------------------------------------------------------------------------------------------------------------
- //Чтоб я видел что выполнилась процедура закидывания в бинарник
- System.out.println("kToBin() is run!000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
- } //
- // /**Текстовые массивы в бинар (процедура проверки)
- public void textArrayToBin(){
- //Текст главного меню и заголовки уровней
- String MAIN_old[] = {
- "Температура(t)", "Приставки", "Давление(P)", "Длина(L)", "Площадь(S)",
- "Обьем(V)", "Скорость(\u03C5)(TEST)", "Ускорение(\u03AC)(TEST)",
- "Вес(Q)(TEST)","Время(time)","Информация(1010)",
- "Мощность()", "Энергия()",
- "Опции(\u20AA)", "О проекте(?)"
- };
- //Текст подуровней
- String text_old[][] = {
- {"атто", "фемто", "пико", "нано", "микро", "мили", "санти", "деци", "1.0", "дека", "гекто", "кило", "мега", "гига", "тера", "пета", "экса"},//Приставки
- {"атм.", "Паскаль", "КГС/мм\u00B2", "КГС/см\u00B2", "КГС/м\u00B2", "мм.вод.ст", "мм.рт.ст", "торр", "Бар"}, //Давление
- {"мк", "мм", "см", "м", "км", "Дюйм", "Фут", "Ярд", "М.Миля", "Миля"}, //длина
- {"см\u00B2", "м\u00B2", "км\u00B2", "Га", "Акр", "Дюйм\u00B2", "Фут\u00B2", "Ярд\u00B2", "миля\u00B2" }, //площадь
- {"Литр", "м\u00B3", "Галон", "Галон(UK)", "мЛитр", "дюйм\u00B3", "Фут\u00B3", "Ярд\u00B3", "ж.унция"}, //Обьем
- {"м/с", "км/ч", "Узел", "Миля/ч"}, //Скорость
- {"м/с\u00B2", "км/ч\u00B2", "Гал", "мГал"}, //ускорение
- {"кг", "г", "Фунт", "Стоун", "Унция"}, //Вес
- {"мсек", "сек", "мин", "час", "сутки", "недел.", "мес(28)", "мес(30)", "мес(31)", "год"}, //Время
- {"бит", "Кбит", "Мбит", "Гбит", "Тбит", "байт", "Кбайт", "Мбайт", "Гбайт", "Тбайт"}, //Информация
- {"кг\u00B7м\u00B2\u00B7c\u05BE\u00B3", "Вт", "КВт", "лс", "b лс", "э лс", "м лс", "лс UK", "h лс"}, //Мощность
- {"BTU", "CBTU", "IBTU", "mBTU", "tBTU", "cal 15", "cal 20", "d cal", "cal", "erg", "joule", "kcal"}, //Энергия
- };
- //Текст подуровня температура
- String temperat_text_old[] = {"\u00B0С", "K", "F"};
- //Пояснение к величинам
- // String Details_old[][] = {
- // {"",""},//Приставки
- // {"атмосфера", "Паскаль", "килограмм-сила на квадратный милиметр",
- // "килограмм-сила на квадратный сантиметр", "килограмм-сила на квадратный метр", "милиметров водного столба",
- // "милиметров ртутного столба", "торр", "Бар"}, //Давление
- // {"микрон", "Сантиметр", "Метр", "Километр", "Дюйм", "Фут", "Ярд", "Миля"}, //длина
- // {"см\u00B2", "м\u00B2", "км\u00B2", "Гектар", "Акр", "Дюйм\u00B2", "Фут\u00B2", "миля\u00B2"}, //площадь
- // {"Литр", "м\u00B3", "Галон", "Чашка", "жидкая унция"}, //Обьем
- // {"метров/секунду", "км/час", "Узел", "Миля/час"}, //Скорость
- // {"м/с\u00B2", "км/ч\u00B2", "Гал", "мГал"}, //ускорение
- // {"килограмм", "грамм", "Фунт", "Стоун", "Унция"}, //Вес
- // {"секунда", "минута", "час", "сутки", "неделя", "месяц(30 дней)", "год"}, //Время
- // {"бит", "Килобит", "Мегабит", "Гигабит", "Терабит", "байт", "Килобайт", "Мегабайт", "Гигабайт", "Терабайт"} //Информация
- //
- // };
- String options_old[] = {
- "Тема (оформление)", //Выбор цветового оформления
- "Точность(НЕТ)" //Точность вычисления
- };
- //Название темы (оформления)
- String ThemeTitle_old[] = {
- "Оранжевая", "Синяя"
- };
- try {
- FileConnection fc = (FileConnection) Connector.open("file:///e:/RU"); //!!!!RU!!!!!
- if (fc.exists())
- fc.delete();
- fc.create();
- DataOutputStream dos = fc.openDataOutputStream();
- //Записываем данные последовательно
- //Сохраняем "MAIN"
- dos.writeByte(MAIN_old.length); //сохраняем количество векторов
- for (int i=0;i<MAIN_old.length;i++) //сохраняем елементы вектора
- {
- dos.writeUTF(MAIN_old[i]);
- //dos.writeDouble(); // Push the score into a byte array.
- }
- //Сохраняем "text"
- dos.writeByte(text_old.length); //сохраняем количество векторов
- for (int i=0;i<text_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
- dos.writeByte(text_old[i].length);
- for (int i=0;i<text_old.length;i++) //сохраняем елементы вектора
- for (int j=0; j<text_old[i].length;j++)
- {
- dos.writeUTF(text_old[i][j]);
- //dos.writeDouble(); // Push the score into a byte array.
- }
- //Сохраняем "temperat_text"
- dos.writeByte(temperat_text_old.length); //сохраняем количество векторов
- for (int i=0;i<temperat_text_old.length;i++) //сохраняем елементы вектора
- {
- dos.writeUTF(temperat_text_old[i]);
- //dos.writeDouble(); // Push the score into a byte array.
- }
- //Сохраняем "Details"
- // dos.writeByte(Details_old.length); //сохраняем количество векторов
- //
- // for (int i=0;i<Details_old.length; i++) //последовательно сохраняем колво елементов каждого вектора
- // dos.writeByte(Details_old[i].length);
- //
- // for (int i=0;i<Details_old.length;i++) //сохраняем елементы вектора
- // for (int j=0; j<Details_old[i].length;j++)
- // {
- // dos.writeUTF(Details_old[i][j]);
- // //dos.writeDouble(); // Push the score into a byte array.
- // }
- //Сохраняем "options"
- dos.writeByte(options_old.length); //сохраняем количество векторов
- for (int i=0;i<options_old.length;i++) //сохраняем елементы вектора
- {
- dos.writeUTF(options_old[i]);
- //dos.writeDouble(); // Push the score into a byte array.
- }
- //-------------
- //Сохраняем "ThemeTitle"
- dos.writeByte(ThemeTitle_old.length); //сохраняем количество векторов
- for (int i=0;i<ThemeTitle_old.length;i++) //сохраняем елементы вектора
- {
- dos.writeUTF(ThemeTitle_old[i]);
- //dos.writeDouble(); // Push the score into a byte array.
- }
- //-------------
- //тут начинается проверка себя на вшивость (MAIN) !!!!!одинарный!!!!!
- DataInputStream dis = fc.openDataInputStream();
- String[] MAIN_test=null;
- MAIN_test = new String[ dis.readByte() ];
- for (int i=0;i<MAIN_test.length;i++)
- MAIN_test[i]=dis.readUTF();
- if (MAIN_old.length==MAIN_test.length) System.out.println("MAIN.length pass"); //сообственно проверка
- else System.out.println("MAIN.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<MAIN_old.length; i++)
- {
- for (int j=0; j<MAIN_old[i].length(); j++)
- {
- 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"); //сообственно проверка
- else System.out.println("MAIN_old["+i+"]!=MAIN_test["+i+"]; MAIN_old["+i+"]="+MAIN_old[i]+";MAIN_test["+i+"]="+MAIN_test[i]+" fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- }
- }
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (text) !!!!!двойной!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- String[][] text_test=null;
- text_test = new String[ dis.readByte() ][];
- for (int i=0;i<text_test.length;i++)
- text_test[i] = new String[dis.readByte()];
- for (int i=0;i<text_test.length;i++)
- for (int j=0;j<text_test[i].length;j++)
- text_test[i][j]=dis.readUTF();
- if (text_old.length==text_test.length) System.out.println("text_old.length pass"); //сообственно проверка
- else System.out.println("text_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<text_old.length; i++)
- {
- if (text_old[i].length==text_test[i].length) System.out.println("text_old["+i+"].length pass"); //сообственно проверка
- else System.out.println("text_old["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int j=0; j<text_test[i].length;j++)
- for (int kk=0; kk<text_old[i][j].length(); kk++)
- 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");
- 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)+" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- }
- //dis.close();
- //-------------------------------------------------------------
- //тут начинается проверка себя на вшивость (temperat_text) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- String[] temperat_text_test=null;
- temperat_text_test = new String[ dis.readByte() ];
- for (int i=0;i<temperat_text_test.length;i++)
- temperat_text_test[i]=dis.readUTF();
- if (temperat_text_old.length==temperat_text_test.length) System.out.println("temperat_text_old.length pass"); //сообственно проверка
- else System.out.println("temperat_text_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<temperat_text_old.length; i++)
- {
- for (int j=0; j<temperat_text_old[i].length(); j++)
- 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"); //сообственно проверка
- 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- }
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (Details) !!!!!двойной!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- // String[][] Details_test=null;
- //
- // Details_test = new String[ dis.readByte() ][];
- //
- // for (int i=0;i<Details_test.length;i++)
- // Details_test[i] = new String[dis.readByte()];
- //
- // for (int i=0;i<Details_test.length;i++)
- // for (int j=0;j<Details_test[i].length;j++)
- // Details_test[i][j]=dis.readUTF();
- //
- // if (Details_old.length==Details_test.length) System.out.println("Details_old.length pass"); //сообственно проверка
- // else System.out.println("Details_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- //
- // for (int i=0; i<Details_old.length; i++)
- // {
- // if (Details_old[i].length==Details_test[i].length) System.out.println("Details_old["+i+"].length pass"); //сообственно проверка
- // else System.out.println("Details_old["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- //
- // for (int j=0; j<Details_test[i].length;j++)
- // for (int kk=0; kk<Details_old[i][j].length(); kk++)
- // 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");
- // 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)+" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- // }
- //dis.close();
- //-------------------------------------------------------------
- //тут начинается проверка себя на вшивость (options) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- String[] options_test=null;
- options_test = new String[ dis.readByte() ];
- for (int i=0;i<options_test.length;i++)
- options_test[i]=dis.readUTF();
- if (options_old.length==options_test.length) System.out.println("options_old.length pass"); //сообственно проверка
- else System.out.println("options_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<options_old.length; i++)
- {
- for (int j=0; j<options_old[i].length(); j++)
- if (options_old[i].charAt(j)==options_test[i].charAt(j)) System.out.println("options["+i+"].charAt(j)==options_test["+i+"].charAt("+j+") pass"); //сообственно проверка
- 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- }
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (ThemeTitle) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- String[] ThemeTitle_test=null;
- ThemeTitle_test = new String[ dis.readByte() ];
- for (int i=0;i<ThemeTitle_test.length;i++)
- ThemeTitle_test[i]=dis.readUTF();
- if (ThemeTitle_old.length==ThemeTitle_test.length) System.out.println("ThemeTitle_old.length pass"); //сообственно проверка
- else System.out.println("ThemeTitle_old.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<ThemeTitle_old.length; i++)
- {
- for (int j=0; j<ThemeTitle_old[i].length(); j++)
- if (ThemeTitle_old[i].charAt(j)==ThemeTitle_test[i].charAt(j)) System.out.println("ThemeTitle["+i+"].charAt("+j+")==ThemeTitle_test["+i+"].charAt("+j+") pass"); //сообственно проверка
- 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- }
- dis.close();
- //--------------------------------------------------------------------
- dos.close();
- fc.close();
- System.out.println("syntax pass");
- } catch (IOException ex) {
- System.out.println("IOException!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- ex.printStackTrace();
- }
- //Чтоб я видел что выполнилась процедура закидывания в бинарник
- System.out.println("textArrayToBin() is run!00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
- uroven=-1;
- }//
- // /** Коефициенты тем в бинар
- public void themeToBin(){
- int Theme_old[][] = {
- {0x00FFFF00, 0x00FF7700, 0x00110000, 0x00FFFF00, 0x00993300, 0x00CC4400, 0x00662200, 0, 0, 0x00666666, 0x00FFFFFF, 0x00000000, 0x00525151, 0x00D9D9D9}, //оранжевая
- {0x00FFFFFF, 0x0006FA6E5, 0x00110000, 0x00FFFFFF, 0x001C63DC, 0x00277FEC, 0x000F3EC6, 0, 0, 0x003E7EB1, 0x00FFFFFF, 0x00000000, 0x00325896, 0x00FFFFFF} //синяя
- };
- //--------Более оптимальная но, более задрочная процедура (если полномочий нет - бесконца клацать подтверждать чтение запись)-------
- try {
- FileConnection fc = (FileConnection) Connector.open("file:///e:/Th");
- if (fc.exists())
- fc.delete();
- fc.create();
- DataOutputStream dos = fc.openDataOutputStream();
- dos.writeByte(Theme_old.length); //сохраняем количество векторов
- for (int i=0;i<Theme_old.length;i++) //сохраняем елементы вектора
- for (int j=0; j<Theme_old[i].length;j++)
- {
- dos.writeInt(Theme_old[i][j]); // Push the score into a byte array.
- }
- //тут начинается проверка себя на вшивость
- DataInputStream dis = fc.openDataInputStream();
- int[][] Theme_test=null;
- Theme_test = new int[ dis.readByte() ][];
- for (int i=0;i<Theme_test.length;i++)
- Theme_test[i] = new int[ ThemeItemCount ];
- for (int i=0;i<Theme_test.length;i++)
- for (int j=0;j<ThemeItemCount;j++)
- Theme_test[i][j]=dis.readInt();
- if (Theme_old.length==Theme_test.length) System.out.println("Theme.length pass"); //сообственно проверка
- else System.out.println("Theme.length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int i=0; i<Theme_old.length; i++)
- {
- if (Theme_old[i].length==Theme_test[i].length) System.out.println("Theme["+i+"].length pass"); //сообственно проверка
- else System.out.println("Theme["+i+"].length fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (int j=0; j<Theme_old[i].length;j++)
- if (Theme_old[i][j]==Theme_test[i][j]) System.out.println("Theme_old["+i+"]["+j+"]==Theme_test["+i+"]["+j+"] pass");
- 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]+"!!!!!!!!!!!!!!!!!!!!");
- }
- dis.close();
- //----------------------------------------
- dos.close();
- fc.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- //--------------------------------------------------------------------------------------------------------------------------------
- //Чтоб я видел что выполнилась процедура закидывания в бинарник
- System.out.println("themeToBin() is run!000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
- }//*/
- //Уровень*/
- private int uroven = 0;
- /**Читаем коеф для темы из ресурса*/
- public void read_theme(){
- try {
- InputStream is = canvasP.class.getResourceAsStream("Th");
- DataInputStream dis = new DataInputStream(is);
- ThemeCount = dis.readByte();
- // for (int i=0;i<d;i++)
- // {
- // dis.readByte();
- // //System.out.println("k_test["+i+"].lenght"+k_test[i].length);
- // }
- Theme = new int[ThemeItemCount];
- if (NTheme != 0)
- dis.skip(NTheme*ThemeItemCount*4);
- for (int i=0;i<Theme.length;i++)
- Theme[i]=dis.readInt();
- is.close();
- dis.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- /**Процедура заполняющая массив коефициентов, читает из ресурсов*/
- public void read_k(){
- try {
- InputStream is = canvasP.class.getResourceAsStream("k");
- DataInputStream dis = new DataInputStream(is);
- byte k_lenght = dis.readByte();
- k = new double[ k_lenght ][];
- for (int i=0;i<k_lenght;i++)
- {
- k[i] = new double[ dis.readByte() ];
- //System.out.println("k_test["+i+"].lenght"+k_test[i].length);
- }
- for (int i=0;i<k.length;i++)
- for (int j=0;j<k[i].length;j++)
- k[i][j]=dis.readDouble();
- is.close();
- dis.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- /***/
- public void read_text(){
- try {
- //тут начинается проверка себя на вшивость (MAIN) !!!!!одинарный!!!!!
- InputStream is = canvasP.class.getResourceAsStream("RU");
- DataInputStream dis = new DataInputStream(is);
- MAIN = new String[ dis.readByte() ];
- for (int i=0;i<MAIN.length;i++)
- MAIN[i]=dis.readUTF();
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (text) !!!!!двойной!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- //String[][] text_test=null;
- text = new String[ dis.readByte() ][];
- for (int i=0;i<text.length;i++)
- text[i] = new String[dis.readByte()];
- for (int i=0;i<text.length;i++)
- for (int j=0;j<text[i].length;j++)
- text[i][j]=dis.readUTF();
- //dis.close();
- //-------------------------------------------------------------
- //тут начинается проверка себя на вшивость (temperat_text) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- //String[] temperat_text_test=null;
- temperat_text = new String[ dis.readByte() ];
- for (int i=0;i<temperat_text.length;i++)
- temperat_text[i]=dis.readUTF();
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (Details) !!!!!двойной!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- //String[][] Details_test=null;
- /*
- Details = new String[ dis.readByte() ][];
- for (int i=0;i<Details.length;i++)
- Details[i] = new String[dis.readByte()];
- for (int i=0;i<Details.length;i++)
- for (int j=0;j<Details[i].length;j++)
- Details[i][j]=dis.readUTF();
- */
- //dis.close();
- //-------------------------------------------------------------
- //тут начинается проверка себя на вшивость (options) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- //String[] ThemeTitle_test=null;
- options = new String[ dis.readByte() ];
- for (int i=0;i<options.length;i++)
- options[i]=dis.readUTF();
- //dis.close();
- //--------------------------------------------------------------------
- //тут начинается проверка себя на вшивость (ThemeTitle) !!!!!одинарный!!!!!
- //DataInputStream dis = fc.openDataInputStream();
- //String[] ThemeTitle_test=null;
- ThemeTitle = new String[ dis.readByte() ];
- for (int i=0;i<ThemeTitle.length;i++)
- ThemeTitle[i]=dis.readUTF();
- dis.close();
- //--------------------------------------------------------------------
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- /**Тестовая процедура для оптимизации мидлета, конкретно: читает из ресурсов информацию
- public void test(){
- InputStream IS = canvasP.class.getResourceAsStream("lang");
- byte data[] = new byte [8];
- try {
- IS.read(data,0,data.length); //читаем
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- // DataInputStream DIS = (DataInputStream) IS;
- String str=null;
- //http://www.javable.com/docs/articles/unicode/ -java unicode
- //str = new String(data, "UTF8"); -массив байтов в текст Юникод
- //byte[] data = priwet.getBytes("UTF8"); -текст Юникод в массив байтов
- try {
- str = new String(data, "UTF16");
- } catch (UnsupportedEncodingException ex) {
- ex.printStackTrace();
- }
- System.out.println("str = "+str);
- }//*/
- /**Процедура проверяющая соотвестсвует ли количество елементов массивов(коефициентов, и названия величин и пояснения)*/
- public void testForMassive(){
- int i=0;
- int j=0;
- int m=0;
- m=java.lang.Math.max(Math.max(k.length, text.length), 0/*Details.length*/);
- for (i=0; i<m;i++)
- {
- if ( k[i].length==text[i].length )
- j++;
- else
- System.out.println("TestForMassive FAILED, j="+j);
- }
- if (j==m) System.out.println("TestForMassive successful");
- }
- /**Перерисовка экрана*/
- public void paint(Graphics g) {
- Font font=null;
- if (g.getClipWidth() < 1175/*175*/)
- {
- g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_MEDIUM));
- } else {g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_MEDIUM));}
- font = g.getFont();
- if (once)
- {
- HeightLine = font.getHeight() + 2;
- for (short j = 0; j <= text.length-1; j++){
- o[j] = 0;
- for (short i = 0; i <= text[j].length-1; i++)
- {
- if (font.stringWidth(text[j][i])+4 > o[j])
- {
- o[j] = font.stringWidth(text[j][i])+4;
- }
- }
- }
- uroven = MAIN.length+1;
- once = false;
- }
- if (show) {
- if (uroven > 2 && uroven < MAIN.length) {Show(g, font);} else { show = false;}
- } else {
- if (uroven>=3 && uroven <= MAIN.length-1) wid = o[uroven-3]; else wid = font.stringWidth("00")+4;
- Fon(g);
- if ( uroven != 1){
- g.setColor(Theme[2]);
- int fW;
- if (uroven > MAIN.length+1) {
- fW = font.stringWidth(options[uroven-(MAIN.length+2)]);
- g.drawString(options[uroven-(MAIN.length+2)],(g.getClipWidth()-fW)/2, 0 ,0);
- }
- else {
- fW = font.stringWidth(MAIN[uroven-2]);
- g.drawString(MAIN[uroven-2],(g.getClipWidth()-fW)/2, 0 ,0);
- }
- if (uroven >=3 && uroven <= MAIN.length-1) {
- g.setColor(Theme[0]);
- for (int i = 0; i <= text[uroven-3].length-1; i++){
- if (i > eN - 1) {
- int x = font.stringWidth(text[uroven-3][i]);
- g.drawString(text[uroven-3][i], (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine)-1, 0); //40=>50
- if (i != NLinePos-1) {
- g.drawString( Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][i] / k[uroven-3][NLinePos-1] ) ),
- wid+2, (i*HeightLine+HeightLine+2)-2 - eN*HeightLine, 0);//42=>52
- }
- }
- }
- } else if (uroven == 2) temperatura1(g, font);
- else if (uroven == MAIN.length) main1(g, font, 1);
- else if (uroven == MAIN.length+1) about1(g, font);
- else if (uroven == MAIN.length+2) main1(g, font, 3);
- else if (uroven == MAIN.length+2+1) precision(g, font);
- //Если прийдется что-то вводить за пределами конвертера то Добавлять условия сюда
- //(Исключающее ИЛИ "^")
- if (uroven < MAIN.length) RamkaAndVvod(g, font);
- } else main1(g, font, 0);
- if (uroven != MAIN.length+1)
- {
- setScroll(g);
- Ramka(g);
- }
- //Отладка Чтоб по голове недали!
- //слово тест в верхних углах экрана
- g.setColor(Theme[4]);
- g.drawString("test",0,0,0);
- g.drawString("test", g.getClipWidth()-font.stringWidth("test") ,0 ,0 );
- //-----------------------------
- }
- /**MAIN.length+1;*/
- /**
- g.setColor(Theme[0]);
- g.drawString( String.valueOf(iii), 0, 0, 0);
- g.drawString( Gen , 42, NLine*20+2, 0); // m
- for (int i = 0; i <= S.length-1; i++){
- int x = font.stringWidth(S[i]);
- g.drawString(S[i], (40-x)/2, (i+1)*20, 0);
- if (i != NLine-1) {
- g.drawString( String.valueOf( Double.parseDouble( Gen ) * k_old[i] / k_old[NLine-1] ), 42, i*20+22,0 );
- }
- }
- /**--------------Отладочная информация-----------------
- g.drawString( String.valueOf( test )+" Колво" ,3,142,0 );
- g.drawString( String.valueOf( Double.parseDouble( Gen ))+" Число" ,3,162,0 );
- g.drawString( test2+" test2" ,3,182,0 );
- g.setFont(font.getFont(font.FACE_SYSTEM,font.STYLE_BOLD,font.SIZE_LARGE));
- g.drawString( String.valueOf( font.stringWidth("Round") ),3,1,0 );
- g.setFont(font.getFont(font.FACE_SYSTEM,font.STYLE_BOLD,font.SIZE_SMALL));
- g.drawString( String.valueOf( font.stringWidth("Round") ),33,1,0 );
- g.drawLine()
- //g.drawString(String.valueOf( font. ),30,1,0);
- //-----------------------------------------------------*/
- //Отладочная информация - сводка глобальных переменных
- /*
- System.out.println( "--------------------------------------------");
- System.out.println( "Precision="+Precision);
- System.out.println( "NLine="+NLine);
- System.out.println( "eN="+eN);
- System.out.println( "MAIN.length="+MAIN.length);
- System.out.println( "NTheme="+NTheme);
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- System.out.println( "uroven="+uroven);
- System.out.println( "Gen="+Gen);
- System.out.println( "NLinePos="+NLinePos);
- System.out.println( "Star="+Star);
- System.out.println( "otr="+otr);
- System.out.println( "RPos="+RPos);
- System.out.println( "wid="+wid);
- System.out.println( "show="+show);
- System.out.println( "once="+once);
- System.out.println( "PraviyKrayRamki="+PraviyKrayRamki);
- System.out.println( "OnceInProject="+OnceInProject);
- System.out.println( "HeightLine="+HeightLine);
- System.out.println( "ddY="+ddY);
- System.out.println( "oneS="+oneS);
- System.out.println( "oneSymb="+oneSymb);
- //System.out.println( "Precision="+Precision);
- //System.out.println( "Precision="+Precision);
- System.out.println( "--------------------------------------------" );// */
- }
- /** маин форма */
- public void main1(Graphics g, Font font, int number){
- int a = 0;
- if (number == 0){
- int w = g.getClipWidth();
- int fW = font.stringWidth("Меню");
- g.setColor(Theme[2]);
- g.drawString("Меню",(w-fW)/2, 0 ,0);
- a = MAIN.length;
- } else if (number == 1) {a = options.length;}
- else if (number == 3){ a = ThemeTitle.length; }
- g.setColor(Theme[0]);
- for (byte i = 0; i < a; i++){
- if (i > eN - 1) {
- int x = font.stringWidth("00");
- if (i >= 0 && i <= 8) g.drawString("0"+String.valueOf(i+1), (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine), 0); //40=>50}
- else g.drawString(String.valueOf(i+1), (wid-x)/2, ((i+1)*HeightLine - eN*HeightLine), 0); //40=>50
- if (number == 0) g.drawString( MAIN[i] , wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0 );//42=>52
- else if (number == 1) g.drawString( options[i] , wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0 );//42=>52
- else if (number == 3) g.drawString( ThemeTitle[i], wid+2, (i*HeightLine+HeightLine+2 - eN*HeightLine)-3,0);
- }
- }
- //Ramka(g);
- //-------------отладочная-----------------
- //Double.longBitsToDouble();
- //Short.
- // String LLL = Double.toString(10000000.0/3.0);
- // int LLL = text[1].length;
- // g.drawString( LLL ,130,202,0);
- //----------------------------------------
- }
- /**Меню точность*/
- public void precision(Graphics g, Font font){
- g.setColor(Theme[0]);
- int a=g.getClipHeight()/HeightLine-1; //колво строк в экране
- for (int i=0; i<a; i++){
- g.drawString(String.valueOf(i+eN)+" знак(ов)",wid, (i+1)*HeightLine,0);
- }
- }
- public static Double valueOf(String s) throws NumberFormatException
- {
- return new Double(valueOf(s).doubleValue());
- }
- /**Округляет*/
- public String Round(String str){
- String part3;
- System.out.println("------>");
- System.out.println(str);
- System.out.println("str.length="+str.length());
- // if (str.length()>3)
- // for (int i=0; i<5; i++)
- // if ( str.charAt( str.length()-i-1 ) == 'e')
- // {
- // npl=i;
- // break;
- // }
- int npl = str.indexOf("E");
- //npl++;
- System.out.println("npl="+npl);
- if (npl<0) {
- npl=str.length();
- part3="";
- }
- else
- {
- part3=str.substring(npl);
- }
- System.out.println("nplS = "+part3);
- int np=str.indexOf('.');
- System.out.println("np="+np);
- String per0 = str.substring(0, np);
- System.out.println("per0="+per0);
- int mprx= Math.min( Precision+np+1, npl );
- System.out.println("mprx="+mprx);
- String per1 = str.substring(np+1, mprx);
- System.out.println("per1="+per1);
- //убиваем нули и округляем девятки
- //if (mprx<str.length())
- if ( str.charAt(mprx) == '5' ||
- str.charAt(mprx) == '4' ||
- str.charAt(mprx) == '3' ||
- str.charAt(mprx) == '2' ||
- str.charAt(mprx) == '1' ||
- str.charAt(mprx) == '0' )
- System.out.println("<5 str.charAt(mprx)="+str.charAt(mprx)+" UARRRAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!");
- else
- System.out.println(">5 str.charAt(mprx)="+str.charAt(mprx)+" UARRRAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!");
- //for (int i=0;i<;i++)
- {
- }
- //режет символы после Прецишен, надо сделать округлятель
- return per0+"|"+"."+"|"+per1+"|"+part3;
- //return per0+"."+per1+part3;
- }
- /** Температурная форма */
- public void temperatura1(Graphics g, Font font){
- g.setColor(Theme[0]);
- for (byte i = 0; i<3; i++){
- int x = font.stringWidth(temperat_text[i]);
- g.drawString(temperat_text[i], (wid-x)/2, ((i+1)*HeightLine), 0);//40=>50
- }
- g.drawString( Gen , wid+2, (NLinePos*HeightLine+2)-2, 0); //42=>52
- if (NLinePos == 1){
- g.drawString( Round( Double.toString( Double.parseDouble( Gen ) + 273.15 )), wid+2, (1*HeightLine+HeightLine+2)-2,0 );//42=>52
- g.drawString( Round( Double.toString(Double.parseDouble( Gen ) * 1.8 + 32.0 )), wid+2, (2*HeightLine+HeightLine+2)-2,0 );//42=>52
- } else if (NLinePos == 2){
- g.drawString( Round( Double.toString( Double.parseDouble( Gen ) - 273.15 )), wid+2, (0*HeightLine+HeightLine+2)-2,0 );//42=>52
- g.drawString( Round( Double.toString( ((Double.parseDouble( Gen ) - 273.15)*1.8)+32 )), wid+2, (2*HeightLine+HeightLine+2)-2,0 );//42=>52
- } else {
- g.drawString( Round( Double.toString( ( Double.parseDouble( Gen ) -32.0) / 1.8 )), wid+2, (0*HeightLine+HeightLine+2)-2,0 );//42=>52
- g.drawString( Round( Double.toString( ((Double.parseDouble( Gen ) - 32.0) / 1.8)+273.15 )), wid+2, (1*HeightLine+HeightLine+2)-2,0 );//42=>52
- }
- RamkaAndVvod(g, font);
- }
- /** Рамка с вводом */
- public void RamkaAndVvod(Graphics g, Font font){
- //Ramka(g);
- g.setColor(Theme[0]);
- g.drawString( Gen , wid+2, (NLinePos*HeightLine+2 - eN*HeightLine)-2, 0); //42=>52
- }
- /**Запуск "о проекте"*/
- public void about1(Graphics g, Font font){
- g.setColor(Theme[11]);
- g.fillRect(5,5,g.getClipWidth()-10,g.getClipHeight()-10);
- g.setColor(Theme[12]);
- g.fillRect(7,7,g.getClipWidth()-14,g.getClipHeight()-14);
- g.setColor(Theme[13]);
- String str[]/*;*/ =
- {
- "ТЕСТОВАЯ ВЕРСИЯ (0.31)",
- "АВТОР НЕ НЕСЕТ",
- "НИКАКОЙ",
- "ОТВЕТСТВЕННОСТИ!",
- "Посвящается группе ",
- "«М-90», УДХТУ",
- "Сделал Chemist",
- "в 2007-2009г",
- "Замечания на e-mail:",
- "«Chemist-i@mail.ru»",
- "Посетите интернет",
- "страницу",
- "«Chemist-Dnepr.narod.ru»",
- "Профиль MIDP-2.0",
- "Конфигурация CLDC 1.1",
- "Удачи!",
- //
- // "i tut mnogo",
- // "lishnego",
- // "bazara"
- };
- // String strX;
- // strX = "ТЕСТОВАЯ ВЕРСИЯ (0.30); АВТОР НЕ НЕСЕТ; НИКАКОЙ; ОТВЕТСТВЕННОСТИ!; Посвящается группе; «М-90», УДХТУ; Сделал Chemist в 2007-2009г; Замечания на e-mail:; «Chemist-i@mail.ru»; Посетите интернет страницу; «Chemist-Dnepr.narod.ru»; Профиль MIDP-2.0; Конфигурация CLDC 1.1; Удачи!;";
- //
- // int j=0;
- // int k=0;
- // String tstr = "";
- // boolean b=false;
- // do{
- // tstr = "";
- // //j=0;
- // do{
- // if (tstr.length()>0)
- // if ( font.stringWidth(tstr)>=(g.getClipWidth()-20) )
- // {
- // //System.out.println("j="+j);
- // //break;
- // do{
- // j--;
- // if (j==0 || tstr.charAt(j)==' ' )
- // {
- // b=true;
- // break;
- // }
- // } while(true);
- // }
- // if (b)
- // {
- // tstr = tstr.substring(0, j);
- // break;
- // }
- // if ( j==strX.length()-1 ) break;
- // tstr += strX.charAt(j);
- // j++;
- // } while(true);
- // b=false;
- //
- // g.drawString(tstr, 10, 10+k*HeightLine, 0);
- //
- // if(k==100) break;
- // k++;
- // } while(true);
- int hei;
- int heightLines = (g.getClipHeight()-10)/HeightLine; //колво строк которое влазит в экрарн по высоте
- if (heightLines>str.length) heightLines=str.length;
- if (ddY>0) ddY=0;
- if (ddY<heightLines-str.length) ddY = (byte)(heightLines-str.length);
- for (byte i = (byte)(-ddY); i < heightLines-ddY; i++){
- hei = font.stringWidth(str[i]);
- g.drawString(str[i],(g.getClipWidth()-hei)/2,((i+ddY)*HeightLine)+7,0);
- }
- str = new String[0];
- g.drawString("Далее", 10, g.getClipHeight()-5-HeightLine, 0);
- g.drawString("Выход", g.getClipWidth()-10-font.stringWidth("Выход"), g.getClipHeight()-5-HeightLine, 0);
- // g.setColor(Theme[13]);
- // String str[] ={
- // "ТЕСТОВАЯ ВЕРСИЯ !!! (13)",
- // "НЕ ИСПОЛЬЗОВАТЬ ДЛЯ",
- // "ОТВЕТСТВЕННЫХ",
- // "РАСЧЕТОВ !!!",
- // "Сделал Chemist в 2007г",
- // "Замечания на e-mail:",
- // "\u00ABAleksCherMy@mail.ru\u00BB",
- // "Профиль MIDP-2.0",
- // "Конфигурация CLDC-1.1"
- // };
- //
- // for (byte i = 0; i < str.length; i++){
- // g.drawString(str[i],10,(i*(HeightLine-2))+10,0);
- // }
- }
- /** Рисует фон */
- public void Fon(Graphics g){
- g.setColor(Theme[6]);
- g.fillRect(0,0,240,320);
- g.setColor(Theme[1]);
- g.fillRect(0,0,240,HeightLine);
- g.fillRect(0,0,wid,320); //40=>50
- g.setColor(Theme[5]);
- for (int i = 1; i < 11; i++){
- g.fillRect(wid,i*2*HeightLine,240,HeightLine); //40=>50
- g.fillRect(0,(i*2*HeightLine)-HeightLine,wid,HeightLine);//40=>50
- }
- g.setColor(Theme[4]);
- for (int i = 1; i < 22; i++) g.drawLine(0, i*HeightLine-1,240, i*HeightLine-1);
- }
- /** Рамочка */
- public void Ramka(Graphics g){
- g.setColor(Theme[3]);
- g.drawLine(0,HeightLine*NLine - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine - eN*HeightLine); //Верх
- g.drawLine(0,HeightLine*NLine+HeightLine-2 - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Низ
- g.drawLine(0,HeightLine*NLine - eN*HeightLine,0,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Лево
- g.drawLine(g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine - eN*HeightLine,g.getClipWidth()-PraviyKrayRamki,HeightLine*NLine+HeightLine-2 - eN*HeightLine); //Право
- }
- /** Создает число получаемое с клавиатуры */
- public String AddSymbol(String OldExt, int Key) {
- if (Key == -8 || Key == -10){
- if (Star > 0) Star -= 1;
- byte a;
- if (Double.parseDouble(OldExt) < 0 ) a = 2; else a = 1;
- if (OldExt.length() > a){
- OldExt = OldExt.substring(0,OldExt.length()-1);
- } else OldExt = "0";
- } else if ((Key>=KEY_NUM0 && Key<=KEY_NUM9) || Key == KEY_STAR || Key == KEY_POUND ){
- if ( Double.parseDouble(OldExt) == 0 && Star == 0 && Key != KEY_STAR && Key != KEY_POUND) OldExt = "";
- if (Key == KEY_NUM0){
- OldExt += "0";
- } else if (Key == KEY_NUM1) {
- OldExt += "1";
- } else if (Key == KEY_NUM2) {
- OldExt += "2";
- } else if (Key == KEY_NUM3){
- OldExt += "3";
- } else if (Key == KEY_NUM4){
- OldExt += "4";
- } else if (Key == KEY_NUM5){
- OldExt += "5";
- } else if (Key == KEY_NUM6){
- OldExt += "6";
- } else if (Key == KEY_NUM7){
- OldExt += "7";
- } else if (Key == KEY_NUM8){
- OldExt += "8";
- } else if (Key == KEY_NUM9){
- OldExt += "9";
- } else if (Key == KEY_STAR && Star <= 0){
- OldExt += ".";
- Star += 1;
- } else if (Key == KEY_POUND){
- if (Double.parseDouble(OldExt) < 0) OldExt = OldExt.substring(1);
- else if (Double.parseDouble(OldExt) > 0) OldExt = "-"+OldExt;
- }
- if (Star > 0 && Key != KEY_STAR && Key != KEY_POUND){
- Star += 1;
- }
- }
- return OldExt;
- }
- /**Обнулить все переменные уровня*/
- public void Reset1(boolean NL){
- Gen = "0";
- Star = 0;
- otr = false;
- if (NL) NLine = 1;
- }
- /**расширенное конвертирование
- Показать на весь экран сколько именно
- равняется данная величина к вводимой*/
- public void Show(Graphics g, Font font){
- if (font.stringWidth(Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][NLine-1] / k[uroven-3][NLinePos-1] )))>g.getClipWidth()-10){
- g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));
- }
- g.setColor(Theme[11]);
- g.fillRect(5,5,g.getClipWidth()-10,g.getClipHeight()-10);
- g.setColor(Theme[12]);
- g.fillRect(7,7,g.getClipWidth()-14,g.getClipHeight()-14);
- g.setColor(Theme[13]);
- g.drawString( text[uroven-3][NLinePos-1]+":",10,10,0); //Details -> text
- g.drawString( Gen, 10, 10+HeightLine-2, 0);
- g.drawString( text[uroven-3][NLine-1]+":",10,10+2*(HeightLine-2),0); ////Details -> text
- g.drawString( Round( Double.toString( Double.parseDouble( Gen ) * k[uroven-3][NLine-1] / k[uroven-3][NLinePos-1] )),10,10+3*(HeightLine-2),0);
- }
- /**Скролл. Вычисляет и рисует полоску прокрутки*/
- public void setScroll(Graphics g){
- int y; //количество строк по вертикали
- if (uroven == 1) //уровень "главное меню"
- y = MAIN.length; //количество пунктов главного списка меню
- else
- if (uroven == 2) //уровень "температура"
- y = 3; //количество температур (3)
- else
- if (uroven == MAIN.length) //уровень опции
- y=options.length;//колво пунктов опций
- else
- if (uroven == MAIN.length+1+1) //уровень "выбор темы (опции)"
- y=ThemeCount; //количество тем
- else
- if (uroven == MAIN.length+1+2) //уровень "точность" (не реализовано) //???
- y=PrecCount;// количество точностей !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- else //иначе
- if (uroven >= 3 && uroven <= MAIN.length-1) //если уровень "конвертируемые величины"
- y = text[uroven-3].length; //количество величин в данном списке
- else //иначе
- y=0; //0
- if ((y*HeightLine)>g.getClipHeight()-HeightLine) { //если количество строк по вертикали больше максимально возможного количества строк которые могут отображатся
- PraviyKrayRamki = 8; //то рисуем скролл
- int x = (g.getClipHeight()-HeightLine)*(g.getClipHeight()-HeightLine) / ( (y*HeightLine) );
- int xxx = eN*(g.getClipHeight()-HeightLine)/y;
- g.setColor(Theme[9]);
- g.fillRect(g.getClipWidth()-7,HeightLine,7,g.getClipHeight()-HeightLine);
- g.setColor(Theme[10]);
- g.fillRect(g.getClipWidth()-5,xxx+HeightLine,3,x);
- } else PraviyKrayRamki = 1; //иначе не рисуем
- }
- /**Запись в рс данных (Номер темы, и т.д.*/
- public void SaveRS(){
- RecordStore rs = null;
- try {
- rs = RecordStore.openRecordStore ( "Sett", true );
- }catch( RecordStoreNotFoundException e ){// не существует
- }catch( RecordStoreException e ){ // какие-то другие ошибки
- }
- //
- // Each score is stored in a separate record, formatted with
- // the score, followed by the player name.
- //
- // returned by addRecord but not used
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- try {
- dos.writeInt(NTheme);// Push the score into a byte array.
- }
- catch (IOException ioe) {
- }
- // Extract the byte array
- byte[] b = baos.toByteArray();
- // Add it to the record store
- try {
- int id = rs.addRecord(b,0,b.length);
- rs.setRecord(1,b,0,b.length);
- byte j[]= new byte[1];
- j[0] = Precision;
- id = rs.addRecord(j,0,1);
- rs.setRecord(2,j,0,1);
- }
- catch (RecordStoreException rse) {
- //System.out.println(rse);
- //rse.printStackTrace();
- }
- try {
- rs.closeRecordStore();
- } catch( RecordStoreNotOpenException e ){// уже закрыта
- } catch( RecordStoreException e ){ // какие-то другие ошибки
- }
- }
- /**Загрузка параметров*/
- public void ReadRS(){
- //--------Код на тесте-------------------------
- //-----Загрузка и сохранение параметров--------
- RecordStore rs = null;
- try {
- rs = RecordStore.openRecordStore("Sett", true);
- } catch( RecordStoreNotFoundException e ){ // не существует
- uroven = MAIN.length+1; //здесь можно поставить уровень выбора языка (ибо этот код выполняется единственный раз при первом запуске)
- OnceInProject = true;
- } catch (RecordStoreException ex) { //Какие-то другие ошибки
- //ex.printStackTrace();
- }
- byte b[] = null;
- byte j[] = {16};
- try {
- b = rs.getRecord(1); //NTheme record
- j = rs.getRecord(2); //Precision record
- } catch (InvalidRecordIDException ex) {
- //uroven = MAIN.length+1;
- b = new byte [4];
- for (byte i = 0; i < 4; i++) b[i] = 0;
- } catch (RecordStoreNotOpenException ex) {
- //ex.printStackTrace();
- } catch (RecordStoreException ex) {
- //ex.printStackTrace();
- }
- ByteArrayInputStream bais = new ByteArrayInputStream(b);
- DataInputStream dis = new DataInputStream(bais);
- try {
- NTheme = dis.readInt();
- Precision = j[0];
- }
- catch (EOFException eofe) {
- //System.out.println(eofe);
- //eofe.printStackTrace();
- }
- catch (IOException eofe) {
- //System.out.println(eofe);
- //eofe.printStackTrace();
- }
- try {
- rs.closeRecordStore();
- } catch( RecordStoreNotOpenException e ){// уже закрыта
- } catch( RecordStoreException e ){ // какие-то другие ошибки
- }
- //---------------------------------------------
- }
- /** Обработка событий клавиатуры (нажатие)*/
- protected void keyPressed(int key) {
- if (uroven == MAIN.length+1) { //если уровень эбаут
- repaint();
- if (key == LEFT_SOFTKEY || key == FIRE_KEY || key == KEY_NUM5)
- {
- uroven = 1;
- }
- else if (key == DOWN_KEY || key == KEY_NUM8) ddY--;
- else if (key== UP_KEY || key == KEY_NUM2) ddY++;
- else if (key == RIGHT_SOFTKEY || key == BACK_KEY) EXIT();
- } else {
- if (uroven == 1 || uroven == MAIN.length || uroven >= MAIN.length+1){
- if(key == UP_KEY) {
- int a = 1;
- if (uroven == 1 || uroven == MAIN.length+1) a = MAIN.length;
- else if (uroven == MAIN.length) {a = options.length;}
- else if (uroven == MAIN.length+1+1) {a = ThemeCount;}
- else if (uroven == MAIN.length+1+2) {a = PrecCount;}//колво точностей
- if (NLine == 1) NLine = a; else NLine -=1;
- }
- else
- if (key == DOWN_KEY) {
- int a = 1;
- if (uroven == 1 || uroven == MAIN.length+1) a = MAIN.length;
- else if (uroven == MAIN.length) {a = options.length;}
- else if (uroven == MAIN.length+1+1) {a = ThemeCount;}
- else if (uroven == MAIN.length+1+2) {a = PrecCount;}//колво точностей
- if(NLine == a) NLine = 1; else NLine += 1;
- }
- else
- if (key == FIRE_KEY || key == LEFT_SOFTKEY) {
- if (uroven == 1 ){ //Этот иф занимается вибором в меню опций, и выбором самих опций
- uroven = NLine+1;
- Reset1(true);
- NLinePos = NLine;
- } else if (uroven == MAIN.length) { //Если Опции то ...
- uroven = (MAIN.length+1) + NLine; //
- } else if (uroven == MAIN.length+1+1) {//Переустановка цвета и сохранение в РМС
- if (NTheme != NLine - 1)
- {
- NTheme = NLine - 1;
- SaveRS();
- read_theme();
- }
- } else if (uroven == MAIN.length+1+2) { //походу переустановка точности и запись в РМС
- if (Precision != Byte.parseByte(String.valueOf(NLine-1)) )
- {
- Precision = Byte.parseByte(String.valueOf(NLine-1)) ;
- SaveRS();
- }
- uroven = MAIN.length;
- NLine = 1;
- } // else Если уровень ... ;
- } else
- if (key == BACK_KEY || key == RIGHT_SOFTKEY) {
- if (uroven == 1) EXIT(); else {
- Reset1(true);
- uroven = 1;
- }
- } else
- if (key >= KEY_NUM0 && key <= KEY_NUM9){ //Бистрий визов эллементов гл. меню (только главного)
- if (uroven==1)
- if (oneSymb)
- {
- if (key>=KEY_NUM0 && key<=KEY_NUM1)
- {
- oneS=(byte)(key-48);
- oneSymb=false;
- }
- }
- else
- {
- oneSymb=true;
- uroven = oneS*10+(key-48)+1;
- Reset1(true);
- NLinePos = NLine;
- }
- }
- } else {
- if (key == BACK_KEY || key == RIGHT_SOFTKEY) {
- if (show == true) {show = false;} else {
- Reset1(true);
- uroven = 1;
- }
- } else if (key == C_KEY || key == GREEN_KEY){
- show = false;
- NLinePos = NLine;
- if (RPos) Reset1(false);
- RPos = false;
- Gen = AddSymbol(Gen, key);
- } else if (key == DOWN_KEY){
- show = false;
- RPos = true;
- if (uroven != 2)
- if (NLine < text[uroven-3].length) NLine += 1; else NLine = 1;
- else if (NLine < 3) NLine += 1; else NLine = 1;
- } else if (key == UP_KEY){
- show = false;
- RPos = true;
- if (NLine > 1 ) NLine -= 1; else if (uroven != 2) NLine = text[uroven-3].length;
- else NLine = 3;
- } else if((key >= KEY_NUM0 && key <= KEY_NUM9) || key == KEY_STAR || key == KEY_POUND) {
- show = false;
- NLinePos = NLine;
- if (RPos) Reset1(false);
- RPos = false;
- Gen = AddSymbol(Gen,key);
- } else if (key == FIRE_KEY || key == LEFT_SOFTKEY){
- if (show == true) {show = false;} else {show = true;}
- }
- }
- }
- if (NLine*HeightLine - eN*HeightLine >= getHeight()-HeightLine) eN = NLine-((getHeight()-HeightLine)/HeightLine);
- if (NLine*HeightLine - eN*HeightLine <= 0) eN = NLine - 1;
- repaint();
- }
- /** Обработка событий клавиатуры (отпускание)
- /* protected void keyReleased(int key) {
- * keyPressed(key);
- * }
- */
- /** Обработка событий клавиатуры (повторение)*/
- protected void keyRepeated(int key) {
- keyPressed(key);
- }
- /**Выход*/
- public abstract void EXIT();
- //protected void pointerPressed(int x, int y){
- //
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement