import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; import java.io.IOException; public class SlideShow extends MIDlet implements Runnable { public static Random rnd; public Thread thread; public Canv canv; public Display display; public Image image; public Image up, down; public int number, k, bar; public int[] T; public int[] R; public int[] G; public int[] B; public int[] X; public int[] Y; public int[] W; public int[] H; public int[] S; private Graphics g; public String[] str; public SlideShow() { canv = new Canv(this); } public void startApp() { try { up = Image.createImage("/up.png"); down = Image.createImage("/down.png"); } catch(IOException ioe) {} T = R = G = B = X = Y = W = H = S = new int[10]; rnd = new Random(); thread = new Thread(this); image = Image.createImage(canv.getWidth(), canv.getHeight()); g = image.getGraphics(); str = new String[5]; bar = 5; firstinit(); int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (day == 1 || day ==7 || day ==0) { str[0] = "Отдыхай"; str[1]="сегодня выходной"; str[2]="можешь сделать"; str[3]="домашнее"; str[4]="задание"; number = 5; } if (day == 2) { ponedelnik(); number = 1; } if (day == 3) { vtornik(); number = 2; } if (day == 4) { sreda(); number = 3; } if (day == 5) { chetverg(); number = 4; } if (day == 6) { patnitsa(); number = 5; } display = Display.getDisplay(this); display.setCurrent(canv); thread.start(); } public void pauseApp() {} public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void command() { if (number <= 5) { number++; if (number > 5) number = 1; } if (number == 1) ponedelnik(); if (number == 2) vtornik(); if (number == 3) sreda(); if (number == 4) chetverg(); if (number == 5) patnitsa(); } public void setImage(String[] s) { try { thread.sleep(500); } catch(InterruptedException ie) {} g.setColor(0, 0, 0); g.fillRect(0, 0, image.getWidth(), image.getHeight()); for (int i = 0; i <= canv.getWidth(); i++) { g.drawImage(up, i, 0, Graphics.LEFT | Graphics.TOP); g.drawImage(down, i, canv.getHeight() - 60, Graphics.LEFT | Graphics.TOP); } play(); g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE)); g.setColor(0, 0, 255); g.drawString(s[0], image.getWidth() / 2 - g.getFont().stringWidth(s[0]) / 2, 3, Graphics.LEFT | Graphics.TOP); g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_MEDIUM)); k = canv.getHeight() / 2 - (g.getFont().getHeight() * 6) / 2; g.setColor(255, 255, 0); g.drawString(s[1], bar, k, Graphics.LEFT | Graphics.TOP); g.drawString(s[2], bar, k + g.getFont().getHeight() * 2, Graphics.LEFT | Graphics.TOP); g.drawString(s[3], bar, k + g.getFont().getHeight() * 4, Graphics.LEFT | Graphics.TOP); g.drawString(s[4], bar, k + g.getFont().getHeight() * 6, Graphics.LEFT | Graphics.TOP); g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); g.setColor(255, 255, 255); g.drawString("Функции", 3, canv.getHeight() - (g.getFont().getHeight() + 3), Graphics.LEFT | Graphics.TOP); g.drawString("Далее", canv.getWidth() - (g.getFont().stringWidth("Далее") + 3), canv.getHeight() - (g.getFont().getHeight() + 3), Graphics.LEFT | Graphics.TOP); canv.repaint(); } public void ponedelnik() { str[0] = "Понедельник"; str[1] = "Информатика(55)"; str[2] = "Англ. язык(52)"; str[3] = "Электротехн(301)"; str[4] = "Электротехн(2 нед)(301)"; } public void vtornik() { str[0] = "Вторник"; str[1] = "Черчение(1 гр.)(62)"; str[2] = "Укр. язык(42)"; str[3] = "Электротехн(301)"; str[4] = "Математика(72)"; } public void sreda() { str[0] = "Среда"; str[1] = "История Украины(81)"; str[2] = "Физ-ра"; str[3] = "Биология(74)"; str[4] = "Черчение(2 гр)(62)"; } public void chetverg() { str[0] = "Четверг"; str[1] = "Экономика(210)"; str[2] = "Физика(73)"; str[3] = "Культурология(80)"; str[4] = "Специализация(2 нед)(301)"; } public void patnitsa() { str[0] = "Пятница"; str[1] = "Горное дело(316)"; str[2] = "Электротехн(301)"; str[3] = " "; str[4] = " "; } public void run() { while (true) setImage(str); } public static int random(int min, int max) { return min + ((rnd.nextInt() >>> 1) % (max - min)); } public void firstinit() { for (int i = 0; i < 10; i++) { T[i] = random(1, 3); R[i] = random(1, 255); G[i] = random(1, 255); B[i] = random(1, 255); X[i] = random(1, canv.getWidth()); Y[i] = random(1,100 ); W[i] = random(1, 50); H[i] = random(1, 50); S[i] = random(1, 4); } } public void secondinit(int a) { T[a] = random(1, 3); R[a] = random(1, 255); G[a] = random(1, 255); B[a] = random(1, 255); X[a] = random(1, canv.getWidth()); Y[a] = random(1, 100); W[a] = random(1, 50); H[a] = random(1, 50); S[a] = random(1, 4); } public void play() { for (int i = 0; i < 10; i++) { g.setColor(100, 100, 100); if (T[i] == 1) { g.drawRect(X[i], Y[i]-100, W[i], H[i]); } if (T[i] == 2) { g.fillRect(X[i], Y[i]-100, W[i], H[i]); } Y[i] += S[i]; g.drawString(T[i]+" "+R[i]+" "+G[i]+" "+B[i]+" "+X[i]+" "+Y[i]+" "+W[i]+" "+H[i]+" "+S[i], bar, 15*i, Graphics.LEFT | Graphics.TOP); if (Y[i] > canv.getHeight()) secondinit(i); } } }