import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import java.io.*; public class Aspects extends MIDlet implements CommandListener { private TextField sun, moon, mercury, venus, mars, jupiter, saturn, uran, neptun, pluton; private Form form; private Display display; private Command exit; private Command equal; private static Aspects midlet; private double[] planet = new double[10]; private EqAspects canvas; public double[] l = new double[10]; boolean error; public Aspects() { midlet = this; form = new Form("Введите абсолютные градусы планет"); exit = new Command("Выход", 5, Command.EXIT); equal = new Command("Расчёт", 5, Command.SCREEN); display = Display.getDisplay(this); } public void startApp() { sun = new TextField("Солнце", "", 6, TextField.DECIMAL); moon = new TextField("Луна", "", 6, TextField.DECIMAL); mercury = new TextField("Меркурий", "", 6, TextField.DECIMAL); venus = new TextField("Венера", "", 6, TextField.DECIMAL); mars = new TextField("Марс", "", 6, TextField.DECIMAL); jupiter = new TextField("Юпитер", "", 6, TextField.DECIMAL); saturn = new TextField("Сатурн", "", 6, TextField.DECIMAL); uran = new TextField("Уран", "", 6, TextField.DECIMAL); neptun = new TextField("Нептун", "", 6, TextField.DECIMAL); pluton = new TextField("Плутон", "", 6, TextField.DECIMAL); form.append(sun); form.append(moon); form.append(mercury); form.append(venus); form.append(mars); form.append(jupiter); form.append(saturn); form.append(uran); form.append(neptun); form.append(pluton); form.addCommand(exit); form.addCommand(equal); form.setCommandListener(this); display.setCurrent(form); } public void commandAction(Command c, Displayable d) { if (c == exit) { destroyApp(false); notifyDestroyed(); } if (c == equal) { try { planet[0] = Float.parseFloat(sun.toString()); planet[1] = Float.parseFloat(moon.toString()); planet[2] = Float.parseFloat(mercury.toString()); planet[3] = Float.parseFloat(venus.toString()); planet[4] = Float.parseFloat(mars.toString()); planet[5] = Float.parseFloat(jupiter.toString()); planet[6] = Float.parseFloat(saturn.toString()); planet[7] = Float.parseFloat(uran.toString()); planet[8] = Float.parseFloat(neptun.toString()); planet[9] = Float.parseFloat(pluton.toString()); error = false; } catch (NumberFormatException e) { error = true; } showOnDisplay(); } } public static Aspects getMidlet() { return midlet; } public void showOnDisplay() { if (error) { Form f = new Form("error"); f.addCommand(exit); f.setCommandListener(this); display.setCurrent(f); } else { canvas = new EqAspects(); display.setCurrent(canvas); } } public double getSun() { int arg0 = (int) planet[0]; double arg1 = ((planet[0]-arg0)*100)/60; l[0] = (arg1*100-arg1)/100+arg0; return l[0]; } public double getMoon() { int arg0 = (int) planet[1]; double arg1 = ((planet[1]-arg0)*100)/60; l[1] = (arg1*100-arg1)/100+arg0; return l[1]; } public double getMercury() { int arg0 = (int) planet[2]; double arg1 = ((planet[2]-arg0)*100)/60; l[2] = (arg1*100-arg1)/100+arg0; return l[2]; } public double getVenus() { int arg0 = (int) planet[3]; double arg1 = ((planet[3]-arg0)*100)/60; l[3] = (arg1*100-arg1)/100+arg0; return l[3]; } public double getMars() { int arg0 = (int) planet[4]; double arg1 = ((planet[4]-arg0)*100)/60; l[4] = (arg1*100-arg1)/100+arg0; return l[4]; } public double getJupiter() { int arg0 = (int) planet[5]; double arg1 = ((planet[5]-arg0)*100)/60; l[5] = (arg1*100-arg1)/100+arg0; return l[5]; } public double getSaturn() { int arg0 = (int) planet[6]; double arg1 = ((planet[6]-arg0)*100)/60; l[6] = (arg1*100-arg1)/100+arg0; return l[6]; } public double getUran() { int arg0 = (int) planet[7]; double arg1 = ((planet[7]-arg0)*100)/60; l[7] = (arg1*100-arg1)/100+arg0; return l[7]; } public double getNeptun() { int arg0 = (int) planet[8]; double arg1 = ((planet[8]-arg0)*100)/60; l[8] = (arg1*100-arg1)/100+arg0; return l[8]; } public double getPluton() { int arg0 = (int) planet[9]; double arg1 = ((planet[9]-arg0)*100)/60; l[9] = (arg1*100-arg1)/100+arg0; return l[9]; } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } public class EqAspects extends Canvas { private Aspects midlet; private double[] laz = new double[10]; private double[][] pl = new double[10][10]; private double[] orbis = {15, 12, 7, 7, 8, 9, 9, 6, 6, 6}; private int[][] a; private int width, height; private int x, y; public EqAspects() { super(); setFullScreenMode(true); width = getWidth(); height = getHeight(); midlet = Aspects.getMidlet(); laz[0] = midlet.getSun(); laz[1] = midlet.getMoon(); laz[2] = midlet.getMercury(); laz[3] = midlet.getVenus(); laz[4] = midlet.getMars(); laz[5] = midlet.getJupiter(); laz[6] = midlet.getSaturn(); laz[7] = midlet.getUran(); laz[8] = midlet.getNeptun(); laz[9] = midlet.getPluton(); x = 0; y = 0; } public void deltaPl() { for (int i = 0; i<10; i++) { for (int j = 0; j<10; j++) { if (i == j) { j++; } if (laz[i] > laz[j]) { pl[i][j] = laz[i] - laz[j]; } else { pl[i][j] = laz[j] - laz[i]; } } } } public void eqAspects() { for (int i = 0; i<10; i++) { for (int k = 0; k<10; k++) { if (i==k) k++; if (pl[i][k] >= 0 && pl[i][k] <= ((orbis[i] + orbis[k])/2)) { a[i][k] = 0; pl[i][k] = ((orbis[i] + orbis[k])/2) - pl[i][k]; } else if (pl[i][k] >= (60 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (60 + ((orbis[i] + orbis[k])/2)) && pl[i][k] >= 60) { a[i][k] = 1; pl[i][k] -= 60; } else if (pl[i][k] >= (60 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (60 + ((orbis[i] + orbis[k])/2)) && pl[i][k] <= 60) { a[i][k] = 2; pl[i][k] = 60 - pl[i][k]; } else if (pl[i][k] >= (90 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (90 + ((orbis[i] + orbis[k])/2)) && pl[i][k] >= 90) { a[i][k] = 3; pl[i][k] -= 90; } else if (pl[i][k] >= (90 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (90 + ((orbis[i] + orbis[k])/2)) && pl[i][k] <= 90) { a[i][k] = 4; pl[i][k] = 90 - pl[i][k]; } else if (pl[i][k] >= (120 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (120 + ((orbis[i] + orbis[k])/2)) && pl[i][k] >= 120) { a[i][k] = 5; pl[i][k] -= 120; } else if (pl[i][k] >= (120 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (120 + ((orbis[i] + orbis[k])/2)) && pl[i][k] <= 120) { a[i][k] = 6; pl[i][k] = 120 - pl[i][k]; } else if (pl[i][k] >= (180 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (180 + ((orbis[i] + orbis[k])/2)) && pl[i][k] >= 60) { a[i][k] = 7; pl[i][k] -= 180; } else if (pl[i][k] >= (180 - ((orbis[i] + orbis[k])/2)) && pl[i][k] <= (180 + ((orbis[i] + orbis[k])/2)) && pl[i][k] <= 180) { a[i][k] = 8; pl[i][k] = 180 - pl[i][k]; } else if (pl[i][k] >= 29 && pl[i][k] <= 31 && pl[i][k] >= 30) { a[i][k] = 9; pl[i][k] -= 30; } else if (pl[i][k] >= 29 && pl[i][k] <= 31 && pl[i][k] <= 30) { a[i][k] = 10; pl[i][k] = 30 - pl[i][k]; } else if (pl[i][k] >= 44 && pl[i][k] <= 46 && pl[i][k] >= 45) { a[i][k] = 11; pl[i][k] -= 45; } else if (pl[i][k] >= 44 && pl[i][k] <= 46 && pl[i][k] <= 45) { a[i][k] = 12; pl[i][k] = 45 - pl[i][k]; } else if (pl[i][k] >= 149 && pl[i][k] <= 151 && pl[i][k] >= 150) { a[i][k] = 13; pl[i][k] -= 150; } else if (pl[i][k] >= 149 && pl[i][k] <= 151 && pl[i][k] <= 150) { a[i][k] = 14; pl[i][k] = 150 - pl[i][k]; } else a[i][k] = 15; } } } public void paint(Graphics g) { g.setColor(0, 0, 0); g.fillRect(0, 0, 400, 520); deltaPl(); eqAspects(); for (int i = 0; i<10; i++) { for (int k = 0; k<10; k++) { if (i == k) k++; switch (a[i][k]) { case 0: g.setColor(100, 100, 100); g.drawString("0`", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 1: g.setColor(0, 200, 200); g.drawString("60`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 2: g.setColor(0, 200, 200); g.drawString("60`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 3: g.setColor(0, 0, 200); g.drawString("90`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 4: g.setColor(0, 0, 200); g.drawString("90`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 5: g.setColor(0, 200, 0); g.drawString("120`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 6: g.setColor(0, 200, 200); g.drawString("120`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 7: g.setColor(200, 0, 0); g.drawString("180`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 8: g.setColor(0, 200, 0); g.drawString("180`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 9: g.setColor(150, 0, 150); g.drawString("30`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 10: g.setColor(150, 0, 150); g.drawString("30`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 11: g.setColor(150, 0, 150); g.drawString("45`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 12: g.setColor(150, 0, 150); g.drawString("45`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 13: g.setColor(150, 0, 150); g.drawString("150`<", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; case 14: g.setColor(150, 0, 150); g.drawString("150`>", (x+(i*30)), (y+(k*15)), Graphics.RIGHT|Graphics.TOP); g.drawString(""+pl[i][k], (x+(i*30)), ((y+(k*15))+20), Graphics.RIGHT|Graphics.TOP); break; } } } } }