/* * ConstructView.java *  * Copyright (C) 1996 :)uane Steward <duane@mit.edu>. */import java.awt.*;import java.lang.*;public class constructview3_1 extends java.applet.Applet{	public int construct_position_x = 125, construct_position_y = 30;		Construct root = new Construct("Healthy", "Unhealthy");	public int widthh, heightt, halfwidth = 80;	Label Title_label;	public void init() {        try {        	this.setLayout(new BorderLayout());        	Title_label = new Label("Constructus \"Image\" Structure ",        													Label.CENTER);        	add("North", Title_label);        	add("East", new Scrollbar(Scrollbar.VERTICAL, 1, 0, 0, 100));        	add("South", new Scrollbar(Scrollbar.HORIZONTAL, 50, 0, 0, 100));        	root.insert_sibling("Does Not Smoke","Smokes");        	root.insert_sibling("More Exercise","Less Exercise");        	root.insert_sibling("Normal Breathing","Coughing");        	root.insert_sibling("Younger","Older");        	root.insert_sibling("High Energy","Less Energy");        } catch (ConstructFoundException e) {			Title_label = new Label(e.toString());        } catch (ConstructError e) {			Title_label = new Label(e.toString());        	}        widthh = root.width * halfwidth * 2 + 60;        heightt = root.branch_depth * 30 + 70;        resize(widthh, heightt);		construct_position_x = root.width * halfwidth + 20;		construct_position_y = 25;   }	public boolean handleEvent(Event evt) {		if (evt.target instanceof Scrollbar) {	    	switch (((Scrollbar)evt.target).getOrientation()) {	    		case Scrollbar.VERTICAL:					int v =  ((Scrollbar)evt.target).getValue();					construct_position_y = 25 - (v * (heightt - 70)/100);					repaint();   // calls update method of applet class which refills entire panel w/ bkgd					break;	    		case Scrollbar.HORIZONTAL:					int h =  ((Scrollbar)evt.target).getValue();					construct_position_x = ((h * widthh - 60)/ 100) - 10;					repaint();   // calls update method of applet class which refills entire panel w/ bkgd					break;				};			};		return true;		}	public void update(Graphics g) { // overwrite the update to selectively repaint bkgd		g.setColor(getBackground());//		g.fillRect(5, 5, Math.min(widthh - 26,574), heightt - 26);		g.fillRect(0, 0, widthh - 20, heightt - 40);		g.setColor(getForeground());		paint(g);		} 	public void paint(Graphics g) {		try {			root.draw(construct_position_x, construct_position_y, g);//			g.setColor(getBackground());//			g.fillRect(0, 0, widthh, 1);//			for (int n = 2; n < 5; n +=1) {//				g.setColor(Color.gray);//				g.drawLine(0+n,0+n,Math.min(widthh -17-n,600-17-n), 0+n);//				g.drawLine(0+n,0+n,0+n,heightt - 17-n);//				g.setColor(Color.darkGray);//				g.drawLine(Math.min(widthh -17-n,600-17-n),//							0+n,Math.min(widthh -17-n,600-17-n),heightt - 17-n);//				g.drawLine(0+n,heightt - 17-n,//							Math.min(widthh -17-n,600-17-n), heightt - 17-n);//				};//				g.setColor(Color.black);//				g.draw3DRect(0+n,0+n,//					Math.min(widthh -17-2*n,600-17-2*n),heightt - 17-2*n,false);			}		catch (Exception e) {			g.drawString("Method constructview.paint(g) failed " + e, 10,10);		}	}}