import java.awt.*; import MainWin; // This class is the information object. It display messages to the // user and a height bar showing the tree height relative to a balance // tree. public class InfoPanel extends Panel { private MainWin Parent; private TextField message; private Label lb1; private Graphics offGraphic; // use for double buffering. private Image offImage; // constructor create the object and initialize the component public InfoPanel(MainWin p) { Parent = p; setBackground(Color.red); message = new TextField(70); message.setEditable(false); lb1 = new Label("Info:"); Font f = new Font("TimesRoman",Font.BOLD,16); message.setForeground(Color.blue); message.setFont(f); message.setBackground(new Color(180,180,180)); lb1.setFont(f); setLayout(new FlowLayout(FlowLayout.LEFT,10,50)); add(lb1); add(message); } // Since the Bar is drawn on the left side of the panel when the // window is resize we need to draw the bar again. public void paint(Graphics g) { drawBar(); } // This method draw the bar on the left side of the panel. public void drawBar() { Graphics g; int num,height; int i; g = getGraphics(); num = Parent.tree.getNodes(); // the num of nodes and the height height = Parent.tree.getHeight(); // of the tree are neded for the // bar drawing. // I create evry time new image so if anyone change the size of // the window the drawing will change correspondingly. offImage = createImage(size().width,size().height); offGraphic = offImage.getGraphics(); offGraphic.setColor(Color.red); offGraphic.fillRect(0,0,size().width,size().height); offGraphic.setColor(new Color(180,180,180)); offGraphic.fill3DRect(size().width-135,5,130,125,true); offGraphic.setColor(Color.black); offGraphic.setFont(new Font("TimesRoman",Font.BOLD,20)); offGraphic.drawString("Tree Depth",size().width-120,25); offGraphic.setFont(new Font("TimesRoman",Font.PLAIN,16)); offGraphic.drawString("Balance Current",size().width-130,120); if (num != 0) { offGraphic.setColor(Color.blue); offGraphic.fillRect(size().width-115,65,20,40); i = (int)(Math.floor((Math.log(num) / Math.log(2))+1)); i = Math.round((float)(height*40)/(float)(i)); offGraphic.setColor(Color.green); offGraphic.fillRect(size().width-50,105-i,20,i); } // painting the off image on the screen g.drawImage(offImage,0,0,this); } // This message update the message in the info area. public void setMessage(String msg) { message.setText(msg); } }