/** * FILE: ManFrame.java * AUTHOR: Ivan J Leichtling * INERNET: ivan@columbia.edu * * This file defines a ManFrame, a frame with info about a man. */ import java.awt.*; import java.util.*; public class ManFrame extends Frame { Man m; Button bClose; public ManFrame( Man m ) { this.m = m; setBackground( Color.pink ); setForeground( Color.black ); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout( gbl ); Font f = new Font( "Helvetica", Font.BOLD, 16 ); Label name = new Label( m.getName(), Label.CENTER ); name.setFont( f ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints( name, gbc ); add( name ); Label spacer1 = new Label( "" ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints( spacer1, gbc ); add( spacer1 ); if( m.getEngaged() ) { Label fiancee = new Label( "Fiancee: ", Label.CENTER ); gbc.gridwidth = 1; gbl.setConstraints( fiancee, gbc ); add( fiancee ); PersonButton pb = new PersonButton( m.getFiancee(), true ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints( pb, gbc ); add( pb ); } else if( m.getProposed() ) { Label possible = new Label( "Proposed To: ", Label.CENTER ); gbc.gridwidth = 1; gbl.setConstraints( possible, gbc ); add( possible ); PersonButton pb = new PersonButton( m.getPossible(), true ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints( pb, gbc ); add( pb ); } else { Label none = new Label( "No fiancee or proposals.", Label.CENTER ); gbl.setConstraints( none, gbc ); add( none ); } Label spacer2 = new Label( "" ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints( spacer2, gbc ); add( spacer2 ); Label preferences = new Label( "Preferences:", Label.LEFT ); gbl.setConstraints( preferences, gbc ); add( preferences ); List list = new List(); Enumeration e = m.getPreferences(); while( e.hasMoreElements() ) { list.addItem( ((Person)e.nextElement()).getName() ); } gbc.weighty = 15; gbc.gridheight = 15; gbc.fill = GridBagConstraints.VERTICAL; gbl.setConstraints( list, gbc ); add( list ); Label spacer3 = new Label( "" ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weighty = 1; gbc.gridheight = 1; gbc.fill = GridBagConstraints.NONE; gbl.setConstraints( spacer3, gbc ); add( spacer3 ); bClose = new Button( "Close" ); gbl.setConstraints( bClose, gbc ); add( bClose ); pack(); resize( 200, 400 ); show(); } public boolean handleEvent( Event evt ) { if( evt.id == Event.WINDOW_DESTROY || ( evt.id == Event.ACTION_EVENT && evt.target == bClose ) ) { dispose(); return( true ); } return( super.handleEvent( evt ) ); } }