Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BinaryTree;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.Arrays;
- public class InsertPanel extends javax.swing.JPanel {
- private int inserted;
- private BinaryTree theTree = new BinaryTree();
- int place = 0;
- public InsertPanel() {
- initComponents();
- }
- public void paintComponent(Graphics g){
- super.paintComponents(g);
- int dist = 0;
- int[] nodeList = new int[theTree.size];
- if(inserted > 0 && inserted < 101){
- nodeList[place] = inserted;
- theTree.addNode(inserted);
- inserted = 0;
- place++;
- theTree.inOrderTraverseTree(theTree.root);
- System.out.println('n');
- //show the in order traversed tree in the pannel
- Arrays.sort(theTree.nodeList);
- for(int n = 0; n <= theTree.size - 1; n++){
- if(theTree.nodeList[n] > 0){
- g.drawString("" + theTree.nodeList[n], 25, 115 + dist);
- dist += 15;
- }
- else{}
- }
- }
- else if(inserted == 0){
- g.setColor(Color.red);
- g.drawString("0 is not a viable number", 25, 100);
- }
- else{
- g.setColor(Color.red);
- g.drawString("out of range", 25, 100);
- }
- }
- private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
- inserted = Integer.parseInt(this.newNumber.getText());
- this.newNumber.setText("");
- //inputsLeft--;
- repaint();
- }
- private void newNumberActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- // Variables declaration - do not modify
- private javax.swing.JButton addButton;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JTextField newNumber;
- // End of variables declaration
Add Comment
Please, Sign In to add comment