Guest User

Untitled

a guest
Dec 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package BinaryTree;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.util.Arrays;
  5.  
  6. public class InsertPanel extends javax.swing.JPanel {
  7.  
  8. private int inserted;
  9. private BinaryTree theTree = new BinaryTree();
  10. int place = 0;
  11.  
  12.  
  13. public InsertPanel() {
  14. initComponents();
  15. }
  16.  
  17. public void paintComponent(Graphics g){
  18. super.paintComponents(g);
  19. int dist = 0;
  20. int[] nodeList = new int[theTree.size];
  21.  
  22. if(inserted > 0 && inserted < 101){
  23. nodeList[place] = inserted;
  24. theTree.addNode(inserted);
  25. inserted = 0;
  26. place++;
  27.  
  28. theTree.inOrderTraverseTree(theTree.root);
  29. System.out.println('n');
  30.  
  31. //show the in order traversed tree in the pannel
  32. Arrays.sort(theTree.nodeList);
  33. for(int n = 0; n <= theTree.size - 1; n++){
  34. if(theTree.nodeList[n] > 0){
  35. g.drawString("" + theTree.nodeList[n], 25, 115 + dist);
  36. dist += 15;
  37. }
  38. else{}
  39. }
  40. }
  41. else if(inserted == 0){
  42. g.setColor(Color.red);
  43. g.drawString("0 is not a viable number", 25, 100);
  44. }
  45. else{
  46. g.setColor(Color.red);
  47. g.drawString("out of range", 25, 100);
  48. }
  49. }
  50.  
  51. private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
  52. inserted = Integer.parseInt(this.newNumber.getText());
  53. this.newNumber.setText("");
  54. //inputsLeft--;
  55. repaint();
  56. }
  57.  
  58. private void newNumberActionPerformed(java.awt.event.ActionEvent evt) {
  59. // TODO add your handling code here:
  60. }
  61.  
  62.  
  63. // Variables declaration - do not modify
  64. private javax.swing.JButton addButton;
  65. private javax.swing.JLabel jLabel1;
  66. private javax.swing.JLabel jLabel2;
  67. private javax.swing.JTextField newNumber;
  68. // End of variables declaration
Add Comment
Please, Sign In to add comment