Facebook
From Bitty Human, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 249
  1. package mobileapplication7;
  2.  
  3. import java.util.Random;
  4. import javax.microedition.lcdui.Canvas;
  5. import javax.microedition.lcdui.Font;
  6. import javax.microedition.lcdui.Graphics;
  7.  
  8. /*
  9.  * To change this license header, choose License Headers in Project Properties.
  10.  * To change this template file, choose Tools | Templates
  11.  * and open the template in the editor.
  12.  */
  13. /**
  14.  *
  15.  * @author Bartosz
  16.  */
  17. public class Plotno extends Canvas {
  18.  
  19.     String napis;
  20.     long start, stop;
  21.  
  22.     public Plotno() {
  23.  
  24.     }
  25.  
  26.     protected void paint(Graphics g) {
  27.  
  28.         Random r = new Random();
  29.  
  30.         start = System.currentTimeMillis(); // start timing
  31.  
  32.         for (int i = 0; i < 100; i++) {
  33.  
  34.             Triangle t = new Triangle(r.nextInt(getWidth() + 1), r.nextInt(getWidth() + 1), r.nextInt(getWidth() + 1), r.nextInt(getHeight() + 1), r.nextInt(getHeight() + 1), r.nextInt(getHeight() + 1));
  35.  
  36.             g.setColor(r.nextInt(256), r.nextInt(256), r.nextInt(256));
  37.  
  38.             g.fillTriangle(t.getX1(), t.getY1(), t.getX2(), t.getY2(), t.getX3(), t.getY3());
  39.         }
  40.         stop = System.currentTimeMillis(); // stop timing
  41.  
  42.         napis = Long.toString(stop - start);
  43.         g.setColor(0, 0, 0);
  44.         g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
  45.         g.drawString("Czas rysowania: " + napis + "ms", this.getWidth() / 2, this.getHeight() / 4, Graphics.BASELINE | Graphics.HCENTER);
  46.  
  47.     }
  48.  
  49. //    protected void keyPressed(int kod) {
  50. //        switch (kod) {
  51. //            case KEY_NUM2:
  52. //                napis = "góra";
  53. //                break;
  54. //            case KEY_NUM8:
  55. //                napis = "dół";
  56. //                break;
  57. //            case KEY_NUM4:
  58. //                napis = "lewo";
  59. //                break;
  60. //            case KEY_NUM6:
  61. //                napis = "prawo";
  62. //                break;
  63. //        }
  64. //        this.repaint();
  65. //        serviceRepaints();
  66. //    }
  67. }
  68.