fork download
  1. package demo2;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.Random;
  8.  
  9. class isortentry {
  10.  
  11. int type, i, j;
  12. Color c;
  13. String print = null;
  14.  
  15. public isortentry(int type, int i, Color c)//1 means initial color;
  16. {
  17. this.type = type;
  18. this.i = i;
  19. this.c = c;
  20. if (this.type == 1) {
  21. print = "Checking elements " + i;
  22. } else if(this.type==3)
  23. {
  24. print = "Correct position found...";
  25. }
  26.  
  27. }
  28.  
  29. public isortentry(int type, int i, int j)//1 means initial color;
  30. {
  31. this.type = type;
  32. this.i = i;
  33. this.j = j;
  34. // this.c = c;
  35. print = "Right shifting... ";
  36. }
  37.  
  38. }
  39.  
  40.  
  41. public class isortvis extends State {
  42.  
  43. public UIManager uiManager;
  44. Random r = new Random(256);
  45. Color mycolor = new Color(230, 92, 0);
  46. int i = 2, ptr = 1, n = 12, temp, si, sj, cycle;
  47. visunumber[] a = new visunumber[25];
  48. boolean isnew, isswaping;
  49. int pos = 500;
  50.  
  51.  
  52. ArrayList<isortentry> log = new ArrayList<isortentry>();
  53. int list[] = new int[25];
  54. int scale;
  55. boolean isrunning;
  56. Iterator itr;
  57. isortentry cur;
  58.  
  59. public isortvis(Handler handler) {
  60. super(handler);
  61. uiManager = new UIManager(handler);
  62. isnew = true;
  63. uiManager.addObject(new UIImageButton(800, 450, 128, 48, Assets.back_bt, new ClickListener() {
  64. @Override
  65. public void onClick() {
  66. handler.getMouseManager().setUIManager(null);
  67. handler.getGame().algomain.init(2);
  68. handler.getMouseManager().setUIManager(handler.getGame().algomain.getUIManager());
  69. State.setState(handler.getGame().algomain);
  70. isnew = true;
  71. isswaping = false;
  72. setFps(10, 500);
  73. }
  74. }));
  75.  
  76. uiManager.addObject(new textclick(300, 500, 40, 40, "1", new ClickListener() {
  77. public void onClick() {
  78. setFps(3, 300);
  79. }
  80. }));
  81. uiManager.addObject(new textclick(350, 500, 40, 40, "2", new ClickListener() {
  82. public void onClick() {
  83. setFps(5, 350);
  84. }
  85. }));
  86. uiManager.addObject(new textclick(400, 500, 40, 40, "3", new ClickListener() {
  87. public void onClick() {
  88. setFps(7, 400);
  89. }
  90. }));
  91. uiManager.addObject(new textclick(450, 500, 40, 40, "4", new ClickListener() {
  92. public void onClick() {
  93. setFps(9, 450);
  94. }
  95. }));
  96. uiManager.addObject(new textclick(500, 500, 40, 40, "5", new ClickListener() {
  97. public void onClick() {
  98. setFps(10, 500);
  99. }
  100. }));
  101. }
  102.  
  103. private void swap(visunumber a[], int in, int jn) {
  104. visunumber temp = a[in];
  105. a[in] = a[jn];
  106. a[jn] = temp;
  107.  
  108. }
  109.  
  110.  
  111. private void swapt(int a[], int in, int jn) {
  112. int temp = a[in];
  113. a[in] = a[jn];
  114. a[jn] = temp;
  115.  
  116. }
  117.  
  118. void insertionSort() {
  119. int i, key, j;
  120. for (i = 1; i < n; i++) {
  121. key = list[i];
  122. log.add(new isortentry(1, i, Color.RED));
  123. j = i - 1;
  124. while (j > 0 && list[j] > key) {
  125. list[j + 1] = list[j];
  126. log.add(new isortentry(2, j, j+1));
  127. j = j - 1;
  128. }
  129. list[j + 1] = key;
  130. log.add(new isortentry(3, j+1, Color.white));
  131. }
  132. }
  133.  
  134.  
  135. public void init() {
  136. n = 15;
  137. for (int k = 0; k <=15; k++) {
  138. int rand = 5 + r.nextInt(35);
  139. a[k] = new visunumber(rand, mycolor, 400, 300 - rand * 5, rand * 5, 30);
  140. // ori[k] = a[k];
  141. list[k] = rand;
  142. }
  143. list[0]=-1;
  144. insertionSort();
  145. isswaping = false;
  146. i = 0;
  147.  
  148. itr = log.iterator();
  149. isrunning = true;
  150. setFps(2, 350);
  151. scale = 0;
  152. isswaping = false;
  153. // play = true;
  154.  
  155. }
  156.  
  157. @Override
  158. public void tick() {
  159.  
  160. uiManager.tick();
  161. if (!isswaping) {
  162. if (isrunning && scale == 0) {
  163. if (itr.hasNext()) {
  164. cur = (isortentry) itr.next();
  165. } else {
  166. for (int i = 0; i < n; i++) {
  167. a[i].setColor(Color.white);
  168. isrunning = false;
  169. }
  170. }
  171. if (cur != null) {
  172. // cp = cur.print;
  173. }
  174. scale = 1;
  175. } else {
  176. scale--;
  177. }
  178. }
  179.  
  180. }
  181.  
  182. @Override
  183. public void render(Graphics g) {
  184. g.drawImage(Assets.blankbg, 0, 0, null);
  185.  
  186. g.setColor(Color.white);
  187. g.setFont(Assets.title);
  188. g.drawString("I Sort", 300, 40);
  189.  
  190. g.setColor(Color.white);
  191. g.setFont(Assets.consolett);
  192. g.drawString("Speed: ", 220, 520);
  193. g.drawString("^", pos + 10, 500);
  194. uiManager.render(g);
  195.  
  196.  
  197. if (!isswaping) {
  198. if (cur != null) {
  199. if (cur.type == 1) {
  200. a[cur.i].setY(a[cur.i].y +a[cur.i].h);
  201. a[cur.i].setColor(Color.red);
  202. } else if(cur.type==2)
  203. {
  204. swap(a, cur.i, cur.j);
  205. }
  206. else if(cur.type==3)
  207. {
  208. a[cur.i].setY(a[cur.i].y - a[cur.i].h);
  209. a[cur.i].setColor(Color.white);
  210. }
  211. }
  212. cur = null;
  213. }
  214.  
  215. for (int i = 1; i < n; i++) {
  216. a[i].drawbox(g, i);
  217.  
  218. }
  219. }
  220. @Override
  221. public UIManager getUIManager() {
  222. return uiManager;
  223. }
  224.  
  225. @Override
  226. public void init(int i) {
  227. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  228. }
  229.  
  230. public void setFps(int n, int i) {
  231. pos = i;
  232. handler.getGame().setFps(n);
  233. }
  234. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: unknown type name 'package'
package demo2;
^
prog.cpp:3:1: error: unknown type name 'import'
import java.awt.Color;
^
prog.cpp:3:12: error: expected ';' after top level declarator
import java.awt.Color;
           ^
           ;
prog.cpp:4:1: error: unknown type name 'import'
import java.awt.Graphics;
^
prog.cpp:4:12: error: expected ';' after top level declarator
import java.awt.Graphics;
           ^
           ;
prog.cpp:5:1: error: unknown type name 'import'
import java.util.ArrayList;
^
prog.cpp:5:12: error: expected ';' after top level declarator
import java.util.ArrayList;
           ^
           ;
prog.cpp:6:1: error: unknown type name 'import'
import java.util.Iterator;
^
prog.cpp:6:12: error: expected ';' after top level declarator
import java.util.Iterator;
           ^
           ;
prog.cpp:7:1: error: unknown type name 'import'
import java.util.Random;
^
prog.cpp:7:12: error: expected ';' after top level declarator
import java.util.Random;
           ^
           ;
prog.cpp:12:5: error: unknown type name 'Color'
    Color c;
    ^
prog.cpp:13:5: error: unknown type name 'String'
    String print = null;
    ^
prog.cpp:15:11: error: expected ':'
    public isortentry(int type, int i, Color c)//1 means initial color;
          ^
          :
prog.cpp:15:40: error: unknown type name 'Color'
    public isortentry(int type, int i, Color c)//1 means initial color;
                                       ^
prog.cpp:29:11: error: expected ':'
    public isortentry(int type, int i, int j)//1 means initial color;
          ^
          :
prog.cpp:17:13: error: member reference type 'isortentry *' is a pointer; did you mean to use '->'?
        this.type = type;
        ~~~~^
            ->
prog.cpp:18:13: error: member reference type 'isortentry *' is a pointer; did you mean to use '->'?
        this.i = i;
        ~~~~^
            ->
prog.cpp:19:13: error: member reference type 'isortentry *' is a pointer; did you mean to use '->'?
        this.c = c;
        ~~~~^
            ->
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
stdout
Standard output is empty