Advertisement
Guest User

aasas

a guest
Apr 30th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. /* MultiPathClient.java
  2. Michael, Sistare
  3. */
  4.  
  5. import java.awt.Graphics;
  6. import javax.swing.JFrame;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class MultiPathClient extends JFrame
  10. {
  11. private final int SIZE = 6;
  12.  
  13. public static boolean [] array;
  14. private static int count1 = 0;
  15. private static int current1 = -1;
  16.  
  17. private boolean firstTime = true;
  18.  
  19. private int key;
  20. private MultiPath mp;
  21.  
  22. public MultiPathClient()
  23. {
  24. super("Illustrating switch .. case");
  25.  
  26. array = new boolean[SIZE];
  27.  
  28. // fill with values false
  29. for (int i = 0; i < array.length; i++)
  30. {
  31. array[i] = false;
  32. }
  33.  
  34. mp = new MultiPath(array, count1, current1);
  35.  
  36. setSize(500, 600);
  37. setVisible(true);
  38. }
  39.  
  40. // ***** Student writes this method
  41. public void workWithSwitch(int value)
  42. {
  43. // Student code starts here:
  44.  
  45.  
  46.  
  47. // Student code ends here.
  48.  
  49. mp.setControl(false);
  50. mp.resetPath();
  51. mp.setCount(0);
  52. mp.setCurrent(-1);
  53. }
  54.  
  55. public void startActivity()
  56. {
  57. boolean goodInput = false;
  58. while (!goodInput)
  59. {
  60. try
  61. {
  62. String answer = JOptionPane.showInputDialog(null, "Enter an integer");
  63.  
  64. if (answer != null)
  65. {
  66. key = Integer.parseInt(answer);
  67. goodInput = true;
  68. }
  69. else
  70. {
  71. System.exit(0);
  72. }
  73. }
  74. catch(Exception e)
  75. {}
  76. }
  77. if (goodInput)
  78. {
  79. firstTime = false;
  80. mp.setControl(true);
  81. workWithSwitch(key);
  82. }
  83. }
  84.  
  85. public static int getCount1()
  86. {
  87. return count1;
  88. }
  89.  
  90. public static int getCurrent1()
  91. {
  92. return current1;
  93. }
  94.  
  95. public static boolean [] getArray()
  96. {
  97. return array;
  98. }
  99.  
  100. private void animate(int index, int value)
  101. {
  102. try
  103. {
  104. mp.setCurrent(value);
  105. mp.setPath(index, true);
  106. mp.addToCount();
  107. repaint();
  108. Thread.sleep(100);
  109. }
  110. catch (InterruptedException e)
  111. {
  112. System.out.println("IE Exception " + e.getMessage());
  113. System.out.println(e.toString());
  114. }
  115. }
  116.  
  117. public void paint(Graphics g)
  118. {
  119. super.paint(g);
  120. if (!firstTime)
  121. {
  122. mp.draw(g);
  123. }
  124. }
  125.  
  126. public static void main(String [] args)
  127. {
  128. MultiPathClient app = new MultiPathClient();
  129. app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  130. PrintArrayT t = new PrintArrayT(app);
  131. t.start();
  132. }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement