Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. /*
  2. * Sean Luava
  3. * 4/24/17
  4. */
  5. import javax.swing.*;
  6. import java.awt.*;
  7. public class Keypads
  8. {
  9. private ImageIcon symbolList = new ImageIcon("SLIST.jpg");
  10. private JLabel label = new JLabel();
  11. private JFrame f1 = new JFrame();
  12. private int[][] slist =
  13. {
  14. {1, 2, 3, 4, 5, 6, 7},
  15. {8, 1, 7, 9, 10, 6, 11},
  16. {12, 13, 9, 14, 15, 3, 10},
  17. {16, 17, 18, 5, 14, 11, 19},
  18. {20, 19, 18, 21, 17, 22, 23},
  19. {16, 8, 24, 25, 20, 26, 27}
  20. };
  21.  
  22. public Keypads()
  23. {
  24. label.setIcon(symbolList);
  25. f1.setLayout(new BorderLayout());
  26. f1.add(label);
  27. f1.pack();
  28. }
  29.  
  30. public void run()
  31. {
  32. f1.setVisible(true);
  33. String input = JOptionPane.showInputDialog("Enter all the numbers that matches the symbols you have (spaces):");
  34. f1.setVisible(false);
  35. String[] convert = input.split(" ");
  36. int[] symbols = new int[convert.length];
  37. for(int aa = 0; aa < convert.length; aa++)
  38. {
  39. symbols[aa] = Integer.parseInt(convert[aa]);
  40. }
  41. symbols = order(symbols);
  42. String[] images = getImages(symbols);
  43.  
  44. ImageIcon i1 = new ImageIcon(images[0]);
  45. ImageIcon i2 = new ImageIcon(images[1]);
  46. ImageIcon i3 = new ImageIcon(images[2]);
  47. ImageIcon i4 = new ImageIcon(images[3]);
  48.  
  49. JLabel l1 = new JLabel();
  50. JLabel l2 = new JLabel();
  51. JLabel l3 = new JLabel();
  52. JLabel l4 = new JLabel();
  53.  
  54. l1.setIcon(i1);
  55. l2.setIcon(i2);
  56. l3.setIcon(i3);
  57. l4.setIcon(i4);
  58.  
  59. JFrame f2 = new JFrame();
  60. f2.setLayout(new GridLayout(1, 4));
  61. f2.add(l1);
  62. f2.add(l2);
  63. f2.add(l3);
  64. f2.add(l4);
  65. f2.pack();
  66. f2.setVisible(true);
  67. JOptionPane.showMessageDialog(null, "Press the symbols in this order:");
  68. f2.setVisible(false);
  69. }
  70. private int[] order(int[] s)
  71. {
  72. int[] order = new int[s.length];
  73. int row = 100;
  74. int best = 0;
  75. for(int aa = 0; aa < 6; aa++)
  76. {
  77. for(int bb = 0; bb < 7; bb++)
  78. {
  79. for(int cc = 0; cc < 4; cc++)
  80. {
  81. if(slist[aa][bb] == s[cc])
  82. {
  83. best++;
  84. }
  85. }
  86. }
  87. if(best == 4)
  88. {
  89. row = aa;
  90. break;
  91. }
  92. best = 0;
  93. }
  94. int items = 0;
  95. for(int dd = 0; dd < 7; dd++)
  96. {
  97. for(int ee = 0; ee < 4; ee++)
  98. {
  99. if(slist[row][dd] == s[ee])
  100. {
  101. order[items] = s[ee];
  102. items++;
  103. }
  104. }
  105. }
  106. return order;
  107. }
  108. private String[] getImages(int[] s)
  109. {
  110. String[] ima = new String[4];
  111. for(int aa = 0; aa < 4; aa++)
  112. {
  113. switch(s[aa])
  114. {
  115. case 1:
  116. ima[aa] = "S1.jpg";
  117. break;
  118. case 2:
  119. ima[aa] = "S2.jpg";
  120. break;
  121. case 3:
  122. ima[aa] = "S3.jpg";
  123. break;
  124. case 4:
  125. ima[aa] = "S4.jpg";
  126. break;
  127. case 5:
  128. ima[aa] = "S5.jpg";
  129. break;
  130. case 6:
  131. ima[aa] = "S6.jpg";
  132. break;
  133. case 7:
  134. ima[aa] = "S7.jpg";
  135. break;
  136. case 8:
  137. ima[aa] = "S8.jpg";
  138. break;
  139. case 9:
  140. ima[aa] = "S9.jpg";
  141. break;
  142. case 10:
  143. ima[aa] = "S10.jpg";
  144. break;
  145. case 11:
  146. ima[aa] = "S11.jpg";
  147. break;
  148. case 12:
  149. ima[aa] = "S12.jpg";
  150. break;
  151. case 13:
  152. ima[aa] = "S13.jpg";
  153. break;
  154. case 14:
  155. ima[aa] = "S14.jpg";
  156. break;
  157. case 15:
  158. ima[aa] = "S15.jpg";
  159. break;
  160. case 16:
  161. ima[aa] = "S16.jpg";
  162. break;
  163. case 17:
  164. ima[aa] = "S17.jpg";
  165. break;
  166. case 18:
  167. ima[aa] = "S18.jpg";
  168. break;
  169. case 19:
  170. ima[aa] = "S19.jpg";
  171. break;
  172. case 20:
  173. ima[aa] = "S20.jpg";
  174. break;
  175. case 21:
  176. ima[aa] = "S21.jpg";
  177. break;
  178. case 22:
  179. ima[aa] = "S22.jpg";
  180. break;
  181. case 23:
  182. ima[aa] = "S23.jpg";
  183. break;
  184. case 24:
  185. ima[aa] = "S24.jpg";
  186. break;
  187. case 25:
  188. ima[aa] = "S25.jpg";
  189. break;
  190. case 26:
  191. ima[aa] = "S26.jpg";
  192. break;
  193. case 27:
  194. ima[aa] = "S27.jpg";
  195. break;
  196. }
  197. }
  198. return ima;
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement