Custopootimus

Untitled

Feb 12th, 2013
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Frame;
  3. import java.awt.Graphics;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6.  
  7.  
  8. public class DataOrganizer extends Frame implements MouseListener{
  9.  
  10. private Buttons randomButton, maxButton, minButton, removeButton;
  11.  
  12. private final int BUTTON_WIDTH = 96;
  13. private final int BUTTON_HEIGHT = 32;
  14.  
  15. private Item highlighted = new Item(0,0,0);
  16.  
  17. private int x, y;
  18.  
  19. private DataCollection data = new DataCollection();
  20.  
  21. public DataOrganizer(){
  22. System.out.println("I don't really know what goes here yet");
  23.  
  24. // Window Initialization
  25. setSize(1024, 350);
  26.  
  27. setTitle("Program 01");
  28. setResizable(false);
  29. CloseWindow window = new CloseWindow();
  30. setBackground(Color.GRAY);
  31. addWindowListener(window);
  32. setVisible(true);
  33.  
  34. // MouseListener to search for mouse input
  35. addMouseListener(this);
  36.  
  37.  
  38. // Constructors for buttons
  39. randomButton = new Buttons("Randomize", Color.green, 50, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
  40. maxButton = new Buttons("Maximum", Color.yellow, 50, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
  41. minButton = new Buttons("Minimum", Color.orange, 50, 200, BUTTON_WIDTH, BUTTON_HEIGHT);
  42. removeButton = new Buttons("Remove", Color.red, 50, 250, BUTTON_WIDTH, BUTTON_HEIGHT);
  43. }
  44.  
  45. public void paint(Graphics pane){
  46.  
  47. // Null checks for buttons
  48. if (randomButton != null)
  49. randomButton.paint(pane);
  50. if (maxButton != null)
  51. maxButton.paint(pane);
  52. if (minButton != null)
  53. minButton.paint(pane);
  54. if (removeButton != null)
  55. removeButton.paint(pane);
  56.  
  57. if (data != null)
  58. showGraphs(pane);
  59. }
  60.  
  61. public void showGraphs(Graphics pane){
  62. data.reset();
  63. while (data.hasNext()== true){
  64. data.next().paint(pane);
  65. }
  66. if (highlighted!=null)
  67. data.reset(highlighted);
  68.  
  69. }
  70. @Override
  71. public void mouseClicked(MouseEvent e) {
  72. // TODO Auto-generated method stub
  73.  
  74. }
  75.  
  76. @Override
  77. public void mouseEntered(MouseEvent e) {
  78. // TODO Auto-generated method stub
  79.  
  80. }
  81.  
  82. @Override
  83. public void mouseExited(MouseEvent e) {
  84. // TODO Auto-generated method stub
  85.  
  86. }
  87.  
  88. @Override
  89. public void mousePressed(MouseEvent e) {
  90. // TODO Auto-generated method stub
  91. x = e.getX();
  92. y = e.getY();
  93.  
  94. if (randomButton.isInside(x, y)){
  95. randomButton.flip();
  96. highlighted = null;
  97. repaint();
  98. }
  99.  
  100. if (maxButton.isInside(x, y)){
  101. maxButton.flip();
  102. repaint();
  103. }
  104.  
  105. if (minButton.isInside(x, y)){
  106. minButton.flip();
  107. repaint();
  108. }
  109.  
  110. if (removeButton.isInside(x, y)){
  111. removeButton.flip();
  112. highlighted = null;
  113. repaint();
  114. }
  115.  
  116. }
  117.  
  118. public void mouseReleased(MouseEvent e) {
  119. // TODO Auto-generated method stub
  120.  
  121. if (randomButton.isInside(x, y)){
  122. randomButton.flip();
  123. System.out.println("1");
  124. data.randomize();
  125. repaint();
  126. }
  127.  
  128. if (maxButton.isInside(x, y)){
  129. maxButton.flip();
  130. Item largest = new Item(0, 0,Integer.MIN_VALUE);
  131. for(Item currentItem; (currentItem = data.next()) != null;) {
  132. if (currentItem.getValue()>largest.getValue())
  133. largest = currentItem;
  134. }
  135. highlighted = largest;
  136. data.reset(largest);
  137. repaint();
  138. }
  139.  
  140. if (minButton.isInside(x, y)){
  141. minButton.flip();
  142. Item smallest = new Item(0, 0,Integer.MAX_VALUE);
  143. for(Item currentItem; (currentItem = data.next()) != null;) {
  144. if (currentItem.getValue()<smallest.getValue())
  145. smallest = currentItem;
  146. }
  147. highlighted = smallest;
  148. data.reset(largest)
  149. repaint();
  150. }
  151.  
  152. if (removeButton.isInside(x, y)){
  153. removeButton.flip();
  154. System.out.println("4");
  155. repaint();
  156. }
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment