www.pudn.com > Java_UML_library.rar > MainWindow.java


// 
//  Unified Library Application 
//  Case study in Unified Modeling Language Toolkit 
// 
//  MainWindow.java 
// 
// 
//  Copyright (c) 1998 John Wiley & Sons, Inc. All rights reserved. 
//  Reproduction or translations of this work beyond that permitted 
//  in Section 117 of the 1976 United States Copyright Act without 
//  the express written permission of the copyright owner is unlawful. 
//  Requests for further information should be addressed to Permissions 
//  Department, John Wiley & Sons, Inc. The purchaser may make back-up 
//  copies for his/her own use only and not for distribution or resale. 
//  The Publisher assumes no responsibility for errors, omissions, or 
//  damages, caused by the use of these programs of from the use of the 
//  information contained herein. 
 
package ui; 
import bo.*; 
import util.ObjId; 
 
import java.awt.*; 
import java.applet.*; 
 
public class MainWindow extends Frame implements ResultOfFindTitle, ResultOfFindBorrower { 
	private Image image; 
	private Toolkit toolkit; 
 
 
	public void paint(Graphics gr) 
    { 
        gr.drawImage(image,0,0,this); 
    } 
 
	void LendItem_Action(Event event) { 
		LendItemFrame fr = new LendItemFrame(); 
		fr.show(); 
	} 
 
	void ReturningItem_Action(Event event) { 
		ReturnItemFrame fr = new ReturnItemFrame(); 
		fr.show(); 
	} 
 
	void ReserveTitle_Action(Event event) { 
		ReservationFrame fr = new ReservationFrame(); 
		fr.show(); 
	} 
 
	void RemoveReservation_Action(Event event) { 
		CancelReservationFrame fr = new CancelReservationFrame(); 
		fr.show(); 
	} 
 
	void Title_Action(Event event) { 
		TitleInfoWindow titlewin = new TitleInfoWindow(); 
		titlewin.show(); 
	} 
 
	void Borrower_Action(Event event) { 
		BorrowerInfoWindow infowin = new BorrowerInfoWindow(); 
		infowin.show(); 
	} 
 
	void BrowseAll_Action(Event event) { 
		BrowseWindow bw = new BrowseWindow(); 
		bw.show(); 
	} 
 
	void InsertTitle_Action(Event event) { 
	    TitleFrame fr = new TitleFrame(); 
		fr.show(); 
	} 
 
	void UpdateTitleItems_Action(Event event) { 
		FindTitleDialog dlg = new FindTitleDialog(this,true); 
		dlg.show(); 
	} 
 
	void InsertBorrower_Action(Event event) { 
		BorrowerFrame fr = new BorrowerFrame(); 
		fr.show(); 
	} 
 
	void UpdateBorrower_Action(Event event) { 
		FindBorrowerDialog dlg = new FindBorrowerDialog(this,true); 
		dlg.show(); 
	} 
 
	void About_Action(Event event) { 
		//{{CONNECTION 
		// Action from About Create and show as modal 
		(new AboutDialog(this, true,toolkit)).show(); 
		//}} 
	} 
 
	void Exit_Action(Event event) { 
		//{{CONNECTION 
		// Action from Exit Create and show as modal 
		(new QuitDialog(this, true)).show(); 
		//}} 
	} 
 
	public void resultTitle(ObjId t) 
	{ 
	    UpdateTitleFrame frame = new UpdateTitleFrame(t,false); 
		frame.show(); 
	} 
 
	public void resultBorrower(ObjId b) 
	{ 
	    UpdateBorrowerFrame frame = new UpdateBorrowerFrame(b,false); 
	    frame.show(); 
	} 
 
	public MainWindow() { 
        toolkit = getToolkit(); 
 
		//{{INIT_CONTROLS 
		setLayout(null); 
		addNotify(); 
		resize(insets().left + insets().right + 371,insets().top + insets().bottom + 221); 
		setFont(new Font("Dialog", Font.PLAIN, 12)); 
		setTitle("Unified Library Application"); 
		//}} 
        image = toolkit.getImage("book.jpg"); 
		//{{INIT_MENUS 
		mainMenuBar = new java.awt.MenuBar(); 
 
		menu1 = new java.awt.Menu("Functions"); 
		menu1.add("Lend Item"); 
		menu1.add("Return Item"); 
		menu1.add("Reserve Title"); 
		RemoveReservation = new java.awt.MenuItem("Remove Reservation"); 
		menu1.add(RemoveReservation); 
		menu1.addSeparator(); 
		menu1.add("Exit"); 
		mainMenuBar.add(menu1); 
 
		menu5 = new java.awt.Menu("Information"); 
		menu5.add("Title"); 
		menu5.add("Borrower"); 
		BrowseAll = new java.awt.MenuItem("Browse All"); 
		menu5.add(BrowseAll); 
		mainMenuBar.add(menu5); 
 
		menu2 = new java.awt.Menu("Maintenance"); 
		menu2.add("Insert Title"); 
		menu2.add("Update Title / Items"); 
		menu2.add("Insert Borrower"); 
		menu2.add("Update Borrower"); 
		mainMenuBar.add(menu2); 
 
		menu3 = new java.awt.Menu("Help"); 
		mainMenuBar.setHelpMenu(menu3); 
		menu3.add("About"); 
		mainMenuBar.add(menu3); 
		setMenuBar(mainMenuBar); 
		//$$ mainMenuBar.move(24,192); 
		//}} 
	} 
 
 
    public synchronized void show() { 
    	super.show(); 
    } 
 
	public boolean handleEvent(Event event) { 
    	if (event.id == Event.WINDOW_DESTROY) { 
		    (new QuitDialog(this, true)).show(); 
            return true; 
    	} 
		return super.handleEvent(event); 
	} 
 
	public boolean action(Event event, Object arg) { 
		if (event.target instanceof MenuItem) { 
			String label = (String) arg; 
 
			if (label.equalsIgnoreCase("Reserve Title")) { 
				ReserveTitle_Action(event); 
				return true; 
			} else 
			if (event.target == BrowseAll) { 
				BrowseAll_Action(event); 
				return true; 
			} else 
			if (event.target == RemoveReservation) { 
				RemoveReservation_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("RemoveReservation")) { 
				RemoveReservation_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Insert Borrower")) { 
				InsertBorrower_Action(event); 
				return true; 
			}else 
			if (label.equalsIgnoreCase("About")) { 
				About_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Title")) { 
				Title_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Borrower")) { 
				Borrower_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Update Title / Items")) { 
				UpdateTitleItems_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Insert Title")) { 
				InsertTitle_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Update Borrower")) { 
				UpdateBorrower_Action(event); 
				return true; 
			}else 
			if (label.equalsIgnoreCase("Return Item")) { 
				ReturningItem_Action(event); 
				return true; 
			} else 
			if (label.equalsIgnoreCase("Lend Item")) { 
				LendItem_Action(event); 
				return true; 
			} else 
				if (label.equalsIgnoreCase("Exit")) { 
					Exit_Action(event); 
					return true; 
			} 
		} 
		return super.action(event, arg); 
	} 
 
 
	//{{DECLARE_CONTROLS 
	//}} 
 
	//{{DECLARE_MENUS 
	java.awt.MenuBar mainMenuBar; 
	java.awt.Menu menu1; 
	java.awt.MenuItem RemoveReservation; 
	java.awt.Menu menu5; 
	java.awt.MenuItem BrowseAll; 
	java.awt.Menu menu2; 
	java.awt.Menu menu3; 
	//}} 
}