     3 

     GUI 

     GUI (Graphical User Interface    
)    .     
  ,      
""  ,   Windows-95, X-Window, Macintosh, OS/2. 
    -  Java     
       ,   
  .     oe  
Java  AWT (Abstract Windows Toolkit    
   ). AWT     
   ,     
.  ,  AWT   Windows,   
 .  Java-  GUI    , 
  ,   Window     
  .        
      .    , 
      Java 
      . 

    77 


     GUI: HelloX 

     HelloX   Java-    ActiveX, 
      .    Visual J++ 
          
ActiveX,       7. ,     
HelloWorld   1        
  ,    :  
 "Hello, <X>",  X     . 
       
     ( ),  
  .   HelloX  : 

     3.1.  HelloX 

import   java.awt.*; 

// HelloX:  .       
// .    GUI HelloX. 
public class HelloX { 
	//   main:    , 
	public static void main( String[] astrArgs) { 
		if(1 == astrArgs.length) {
		    HelloX gui = new HelloX(astrArgs[0]);   
		} else {
		    System.err.println("Usage: Java HelloX <display-string>"); 
		}
	} 
	//  HelloX:     . 
	//  GUI     
	//  HelloXComponent. 
                 public HelloX(String strDisplay) { 
		//        . 
		Frame f = new Frame("HelloX Example Program"); 
		f.setLayout(new BorderLayout()); 
		//f.resize(300, 200); deprecated
		f.setSize(300, 200); 
		//   string display. 
		HelloXComponent c = new HelloXComponent(strDisplay); 
		//     , 
		f.add("Center", c); 
		f.show(); //
	}
}

class HelloXComponent extends Canvas { 
	//    display string   . 
	public HelloXComponent(String strDisplay) { 
		m_strDisplay = new String(strDisplay); 
	} 


    78	Visual J++:   


	//  paint ()     
	// . 
	public void paint(Graphics g) { 
		String strDisplay = "Hello," + m_strDisplay + "!"; 
		FontMetrics fm = g.getFontMetrics(); 
		int cxText = (getSize().width / 2) - (fm.stringWidth(strDisplay)/2); 
		int cyText = (getSize().height / 2)- (fm.getHeight()/2); 
		// int cxText = (size().width / 2) - (fm.textWidth(strDisplay)/2); deprecated
		// int cyText = (size().height / 2) - (fm.textHeight(strDisplay)/2); deprecated
	 	g.drawString(strDisplay, cxText, cyText); 
	} 
	// ,   private, 
	private String m_strDisplay = null; 
} 



      HelloX  Visual J++ 

       HelloX  Visual J++    : 
    1.    Visual J++. 
    2.     New   File,     Choose 
,     .     
   (  msdev\Project,   
  ),    HelloX (    
,   VJ++     ). 
     ,     Developer Studio,    
    ,   HelloX. , 
     .     HelloX. 
    3.     Insert   New Java Class.    Name 
  Create New Class  HelloX.  Extends  Package 
 .    Public, ,  
 HelloX    public.   . 
    4.          HelloX  , 
  . 
    5.     Insert   New Java Class.      
  HelloXComponent,     Canvas,  
  Extends   Canvas. 
      ,   Rebuild All   Build   
 HelloX   . 

     

      HelloX       "Hello, <>". 
 ,   HelloXComponent,    

     3.  GUI 79 

Canvas     Java.awt.  Canvas    
Component.      . 3.1. 

    . 3.1.  ,     HelloXComponent 

     AWT     GUI   Component. 
Component      Canvas,    , 
,        .  
     ,    
GUI-.      : 
    	   /; 
    	     ; 
    	  ; 
    	 . 
         5,    
   Component    . 

     / 

         . ,    
Cancel  ,        
.    HelloX   HelloXComponent  
Frame,     ,  . 
     ,     Component,  
  Container.      ,  
 Container    Component.        
 .    ,   , 
   (contain)  ?  ,  
 ,   .  

    80	Visual J++:   

   ,    
  ,    . 
           . 
   Container    Component,   
    , ,   ,  
   ,  ..   
/     (. 3.2). 
   /    
.  AWT    ,     
 .        
 HelloX  Frame. 
         -  Component, 
   getParent().     ,  
   . 

    . 3.2.  /  GUI  Java 


        

     , GUI-,  ,    ^ 
,    -,  , ,  
   . . ,    
 ,   (bounds)    
 (bounding rectangle).    
  (size) . 

     3.  GUI 81 

        ,   
    .   Component  bounds()  
size()     Rectangle  Dimension,  
   . 
       HelloX   paint(),  ,  
 ,        
 "Hello, <X>"   size().      
  bounds(). ,          
 .     ,   
location()  Component  ,     
.   size()  location()    ,   
,   bounds(). 
        Component   ,  
 .  move()    ,   
 .  resize()   ,    
 . ,        
   ,        
   ,  ,   ,  
  .  reshape()   
        
 . 
            
.        
.     Java   . 
          
    . ,   
BorderLayout,     HelloX,   
,       Frame.   Java  
   GUI-     
 . 
            , 
      .     
 (enabled),   (disabled).     
.      . 
,    .   
    .       
     Component disabled()  enabled().  
isEnabled() ,    . 
        (visible)   (hidden).  
 ,     (showing)   (not 
showing).  ,    ,    
.   ,      

    82	Visual J++:   

,    ,  .    
        . , 
      ,     
 ,  .       
  ,   .   Component 
isShowing() ,     (     
     ). 
      ,        
    .      
. , ,    ,  
     ,     
.        ,    
  .  hide()  show()  Component  
    . ( ,   show()  
, .  :  show()   ,  
       ,  
   .)

      

     Java     .  (events)   
   ,    
GUI-    ,   . 
 Java      Event.    
   Java-    
.       .   
 ,       
,         
.    ,        
-,   GUI-,    
  . 
     handleEvent()  Component  ,   
      .    
       Component  Java  
  handleEvent()  .     
Event.   Event  ,      
  . 
     HelloX    ,     
,   .   3.2,    
 HelloX,      .  
,       ,  
 "Hello, <X>". 

     3.  GUI 83 


     3.2.  HelloX,  ,     

import   java.awt.*; 

class HelloXComp2 extends Canvas { 
	//        . 
	public HelloXComp2 (String strDisplay)  { 
		m_strDisplay = new String(strDisplay); 
	}

	//  handleEvent() ,   
	//      ,   
	// ,   . 
	public boolean handleEvent(Event evt)  { 
		if(Event.MOUSE_MOVE == evt.id) 
			return mouseMove(evt, evt.x, evt.y); 
		return false; 
	} 

	//  mouseMove()    
	//     , 
	public boolean mouseMove(Event evt, int x, int y) { 
		m_cxText = x; 
		m_cyText = y; 
		repaint(); 
		return true; 
	}
	
	//  paint() ,    
	//  .       
	//  , 
	public void paint(Graphics g) { 
		String strDisplay = "Hello, " + m_strDisplay + "!"; 
		g.drawstring(strDisplay, m_cxText, m_cyText); 
	} 

	// Private-. // 
	private String m_strDisplay = null;
	private int m_cxText = 0; 
	private int m_cyText = 0; 
} 

     . 3.3          
HelloX.     .   HelloXComp2 
  handleEvent()       
     .    
  {event handler). 

    84	Visual J++:   


    . 3.3.    HelloX 

       ,    Component. 
  handleEvent()     
o  switch,     
 Component    .   HelloXComp2 (  
 HelloXComp)    ,    
.         handleEvent(), 
       mouseMove()  Component. 
          public- id 
 Event.   Event     , 
   .     Event 
    .     
,     .  ,  
      .   , 
  ,   key. 
      key   ,     
 .  ,    modifiers, , 
   [Shift], [Ctrl], [Esc] (  Java )  [Alt]. 
     ,   
     modifiers   SHIFT, CTRL, 
ESC, ALT. 
     clickCount    ,   
 ,     .    
    2. e arg    
.     . ,  ,  
      , 

     3.  GUI 85 

  arg    ,    
   .  . 3.1    , 
    ,     
 ,    ,   handleEvent()  
  .        Component  
,    ,    . 

     3.1.    

     		 			  
    Event 

   ACTION_EVENT		      		action(Event, arg) 
				 . 

   GOT_FOCUS		  "   		gotFocus(Event, arg) 
				".    
				   
				 . 

   KEY_PRESS		 . 		keyPress(Event, key) 
				 modifiers  
				  
				. 

   KEY_RELEASE		 . Modifiers		keyRelease(Event, key) 
				  . 

   LIST_SELECT		  . -    	 
				  , 
				   . 

   LIST_DESELECT		  . -    	 
				  ,  
				   . 

   LOST_FOCUS		      		lostFocus(Event, arg) 
				  .  
				    
				  . 

   MOUSE_DOWN       	  			mouse Down (Event, x, ) 

   MOUSE_DRAG 		  -   		mouseDrag(Event, x, ) 
				   . 

   MOUSE_ENTER         	   -    		mouseEnter(Event, x, ) 
				  . 

   MOUSE_EXIT		  -    		mouseExit(Event, x, ) 
				  . 

   MOUSE_MOVE		          		mouseMove(Event, x, ) 
				 . 


    86 Visual J++:   


     		 			  Event 

   SCROLL_LINE_UP,	        -    	     
   SCROLL_LINE_DOWN,	   -
   SCROLL_PAGE_UP, 	  . 
   SCROLL_PAGE_DOWN	  -. 
				 . 


     handleEvent()   .  true   , 
     handleEvent()    
.  false   ,       
. 
        .   
   (   handleEvent()   false),  
     . .   ,   
         Component 
     ,     Container,  
    .    ,   
 ,       
.    ,  mouseMove()  keyDown(),  
  . 

       

            , ,  
    .    
 ,           . 
     AWT     Component,  Canvas.  
       ,   
   .  Java     
      .  
 ,       
 : 
    1.         Canvas  java.awt. 
    2.         ,  
         public-       . 
         ,    (   0-100%,   
              )     
                ,   private, 
            ,      
              public-   
          setPercentage()  getPercentage(). 


     3.  GUI	87 


    3.       (  Component)  
    ,      
     .    
 ,    paint()  . 
          .   
  Checkbox  AWT.      
 .         
.   3.3    TwoStateComp,   
    .    
  ,   0,    , 
  1. 

     3.3.   TwoStateComp  Component 

import   java.awt.*;

class TwoStateComp extends Canvas
{	
	/* ***************** 
	 * /.	
	 ****************** */ 
	public TwoStateComp( Image imgState0, Image imgState1)  {
		m_aimgStates[0] = imgState0;
		m_aimgState1[1] = imgState1;
	}
	/* ********	
	 *Publoc-  .
	******** */ 
	public void  setState(int  nNewState)    { 
		if((nNewState  <  0)  ||  (nNewState  >  1)) 
			throw(new IllegalArgumentException(s_strErrorInvalidStateValue)) 
		m_state = nNewState; 
		repaint();
	}
	public void paint(Graphics g)   { 
		//        5. 
		g.drawlmage(m_aimgStates[m_state] , 0, 0, this); 
	}
	//////////         
	//   . 
	public boolean mojiseDown (Event evt, int x, int y)   { 
		m_fMouseDown = true; 
		repalnt(); 
		return true; 
	} 


    88	Visual J++:   


	public boolean mouseEnter(Event evt, int x, int y)   { 
		m_fMouseInBounds = true; 
		repaint(); 
		return true; 
	} 
	public boolean mouseExit(Event evt, int x, int y)  { 
		m__InBounds =  false;
		repaint () ;
		rreturn true;    
	}
	public boolean mouseUp (Event evt, int x, int y)   { 
		if(m_fMouseDown && m_fMouseInBounds)  { 
			Event evt2 = new Event(this, Event.ACTION_EVENT, null); 
			getParent().postEvent (evt) ; 
		}
		m_fMouseDown = false; 
		return true; 
	} 

	/* ******** 
	* Private- . 
	********** */
	private Image[]	m_aimgStates = new Image[2]; 
	private int		m_state = 0; 
	private boolean	m_fMouseDown = false; 
	private boolean	m_fMouseInBounds = false; 

	/* ******** 
	*  private-. 
	******** */ 
	private static final String s_strErrorInvalidStateValue = 
		"Error: TwoState Comp may only have states 0 or 1."; 
    } 



        

      ,    (   ) 
  .      
 Container.      Component,  
   ,    
(contain)  .    Component   
 : 
           ; 
           . 

     3.  GUI 89 

         Container   add() 
 Container: 

    myContainer.add(myComponent); 

           (  
)         .  
    ,   .  
      ,    
,    .  ,  
 add()     HelloX   
     . 
           remove()  
Container.     Container (  . 3.2) 
     . 

     3.2.    Container    

    		 

    removeAll	    .       
			    . 
    getComponent	 n-  . 
    getComponents	      . 
    locate		  (, ),     , 
			      . 


     :     

     ,         
 .       
  Java   ,    
(Layout Manager).          
LayoutManager.          
    . 
         ,   
  .         
 .  ,   FlowLayout 
          , 
     . 
    ,       
  ,    
(validation).      , , 
    (valid)   (invalid). 

    90 Visual J++:   

      ,      
 -.    ,   
  ,    -  .  
 .    
,    validate()  Container.  
   ,  validate()   .   
 ,    layoutContamer()  
 .        
-,      : 
    1.       . 
    2.       .  
preferredSize()  Component   Dimension,  
    . 
    3.         
   . 
    ,   preferredSize()  Component,  
  .     . 
minimumSize()  Component   , 
   ,      
.        
    ,    minimumSize(). 
           
     Windows .  Windows 
      
.           
 .  Visual J++ ResourceWizard   
,  DialogLayout.     
     ,       
  .    ,    
 ?        , 
    (     , 
    )?      
  .       
   . 
     setLayout()  Container ,    
   .      
 HelloX,         
 BorderLayout: 

    Frame f = new Frame("HelloX Example Program"); 
    f.setLayout(new BorderLayout()); 


     .  GUI	91 


       

          ,   
 Java,    DialogLayout,   
ResourceWizard        Java. 

    FlowLayout 

    FlowLayout    .     
        ,  
   .     ,   
   ,    
 .  FlowLayout     
,      .  Java,    
      FlowLayout, 
  . 3.4.        
,      . 

    . 3.4. ,      FlowLayout 


    BorderLavout 

      BorderLayout      
.    North, South, East, West  Center.  
       (, 
,   ).  Center    . 
 North  South   ,      
,    ,     
.  East  West  ,     
 ,  ,      
   .  Center    
.         add() 
 Container,   . ,   HelloX  
HelloXComponent    GUI      Center: 

    HelloXComponent  = new HelloXComponent(strDisplay); 
    f.add("Center", c); 


    92 Visual J++:   


    GridLayout 

      GridLayout       
.  GridLayout  ,     
    GridLayout. ,    
          (. 3.5)  
  GridLayout.         
 ,      . 

    . 3.5. ,      GridLayout 

    Panel p = new Panel(); 
    p.setLayout(new GridLayout(3, 2) ) ; 
    p.add(new Button("Upper Left")); 
    p.add(new Button("Upper Right")); 
    p.add(new Button ("Middle Left")); 
    p.add(new Button("Middle Right")); 
    p.addfnew Button("Lower Left")); 
    p.add(new Button("Lower Right")); 


    CardLayout 

      CardLayout     , 
   .     ,     
    .  ,    
,   first(), next(), last()  show()  
CardLayout.   ,     . 
    TabbedPanel,     
    CardLayout    
 "  ". 

     3.  GUI 93 


    GridBagLayout 

    GridBagLayout       , 
   Java.        , 
    .   ,  
  GridLayout,   .  GridBagLayout 
     ,       
      . ,   
 GridBagLayout,   . 3.6. 

    . .6. ,      GridBagLayout 

      ,    GridBagLayout,   
 ,         
 GridBagConstraints.    ,   
   ,    .  
 GridBagConstraints   public-,   
 ,     .    
,    setConstraints(),     
   .      
GridBagConstraints  . 

    Anchor 

    ,     ,     
 .         
: GridBagConstraints.NORTH, GridBagConstraints.EAST, 
GridBag-Constraints.WEST, GridBagConstraints.SOUTH, 
GridBagConstraints.NORTHEAST, GridBagConstraints.NORTHWEST, 
GridBagConstraints. SOUTHEAST, GridBagConstraints. SOUTHWEST  
GridBagConstraints.CENTER. 

    Insets 

    ,        
  , ,     . 

    ipadx 

    ,        X 
    . 

    94 Visual J++:   


    ipady 

    ,        Y   
  . 

    gridx  gridy 

         ,    
.       () ,  
   . 

    gridwidth 

      ,    .  
GridBagConstraints.REMAINDER   ,      
 .  GridBagConstraints.RELATIVE ,    
,  . 

    gridheight 

       ,   gridwidth,   . 

    weightx 

    ,         
.      ,    
       weightx.  
      .   
     0        . 

    weighty 

      weightx,      . 

    DialogLayout 

       ,   ResourseWizard   
    Java    Dialog   
    DialogLayout. 
    DialogLayout      ,   
    Java.     
  (X,Y)  ,    .  
       (dialog units). 
     ,  1/8   1/4  
    .      , 
      Windows,     
  .        
       .   
    

     3.  GUI	95 

    . ,     
     .    
      ..  
    ,   - 
  . 

        

           
     .    
  .     
      :   
.         - 
 ,         .  , 
      . 
            
SplitterLayout,         splitter. 
       ,    
         . 
   ,   SplitterLayout     
      ,      
.      SplitterLayout. 

     3.4.    SplitterLayout 

public class SplitterLayout implements LayoutManager  { 
	public SplitterLayout( int cRows, int cCols ) ( 
		m__cRows = cRows ; 
		m_cCols = cCols; 
		m_anRowHeight = new int [m_cRows]; 
		m_anColWidth = new int[m_cCols]; 
	} 

	/* ********
	* Public- . 
	********   "/ 

	public void setColWidth(int iCol, int cxWidth) { 
		m_anColWidth[iCol] = cxWidth; 
	} 
	public void setRowHeight(int iRow, int cyHeight)  {
		m_anRowHeight[iRow] = cyHeight; 
	} 


    96 Visual J++:   


	/* ******** 
	* Private- . 
	******** * / 

	private int m_cCols = 0; 
	private int m_cRows = 0; 
	private int[ ] m_anColWidth = null; 
	private int[ ] m_anRowHeight = null; 
} 

      LayoutManager    ,  
     .   
         
 SplitterLayout. 

    addLayoutComponent( String name, Component comp ) 

            
    .   GridBagLayout, 
          
GridBagConstraint,    .   
BorderLayout    ,    ,  
  . . 
      SplitterLayout      
 ,         : 

    public  void addLayoutComponent(String  name,   Component  comp)    {} 


    removeLayoutComponent(Component comp) 

      addLayoutComponent()  removeLayoutComponent() 
      .  
 SplitterLayout      : 

    public void removeLayoutComponent(Component comp) (} 


    preferredLayoutSize(Container parent) 

         Dimension,  
   .   
        
 preferredSize().      
 (insets), ..    .,    
 .   SplitterLayout   
         
   : 

    public Dimension preferredLayoutSize(Container parent) { 
	Dimension d = new Dimension(parent.insets().left + 
	parent.insets ().right, parent.insets().top + 


     .  GUI	97 


	    parent.insets () .bottom); 
	for(int i=0; i<m_anColWidth.length; i + + ) 
	    d.width += m_anColWidth[i]; 
	for(int j=0; j<m_anRowHeight.length; j++) 
	    d.height += m_anRowHeight[j]; 
	return d; 
   } 


    minimumLayoutSize(Container parent) 

      preferredLayoutSize().    Dimension, 
  .      , 
    ,   ,   
   .    
SplitterLayout     ,     
   ,     preferredLayoutSize(): 

    public Dimension minimumLayoutSize(Container parent) { 
	    return preferredLayoutSize(parent) ; 
    } 


    layoutContainer(Container parent) 

            
.          
     .   
    SplitterLayout : 

    public void layoutContainer(Container parent) { 
	Component[ ] aComps = parent.getComponents(); 
	 int xAccum = 0; 
	int yAccum = 0; 
    	for(int i=0, int y=0; ((i<aComps.length) && (y<m_cRows)); i++, y++)  { 
		for (int x=0; ( (KaComps . length) && (x<m_cCols) ) ; i + +, x + -t-)  { 
			aComp[i].reshape(xAccum, yAccum, m_anColWidth[x],  m_anRowHeight[y]); 
			xAccum += m_anColWidth[x]; 
		} 
		 xAccum = 0; 
		yAccum += m anRowHeight[y]; 
	}
   }


    98	Visual J++:   


      null    LayoutManager 

             ,  
   ,    ,   
  .     ,   
 ,     rnove(), resize()  
reshape()  Component. 
        ,   
   null: 

    myContainer.setLayout(null); 

       ,        
,    move(), resize(), reshape() : 

    myContainer.add( myCompl ); 
    myContainer.add( myComp2 ); 
    .....
    myComp1.move( 0, 0 ); 
    myComp2.resize(100, 75); 

    myComp2.reshape(80, 0, 100, 75); 
    ........

         . -,    move(), 
resize()  reshape()  ,      
   .       ( 
    show()).  ,   
/        
  .         
     ,       . 
    -,        
 GUI    .   ,  
     ,  . 
 ,    GUI   ,    
    ,    
 Java.   .  ,    
TabbedPanel ( 3.5)    ,      
     . 
            
,       .  , 
     

     3.  GUI 99 

       , 
..      . ( -  
   , ,   ,  .) 
        
   VerticalLayout.   VerticalLayout  
      FlowLayout,    X  Y 
 . 

        

              
 (tabbed dialog),      Windows 95  
Windows NT 4.x.     ,    
   ,    "".   
       
 .       Java   
  . 
          TabbedPanel,  
    .  TabbedPanel   
    .    , 
       addTab()  TabbedPanel 
  ,        
.  . 3.7   ,   
TabbedPanel.   TabbedPanel    removeTab(), 
selectTab(), getSelectedTabName()  getSelectedTabPanel(). 


    . 3. 7.    


    100 Visual J++:   

        TabbedPanel,    
TabbedPanel.      ,   
    BorderLayout.     
,   .   .   
 ,     ,  . 
  .       
 , ,  ( )    
   .    TabbedPanel  
 .    ,  ,  
  . 
       TabbedPanel     
  TwoStateComp.   ,    
 ,            
 "1",    .     
TabbedPanel  : 

     3.5.  TabbedPanel 

    import   java.awt.*; 
    import j ava . util.Hashtable;
    import Java.util.Enumeration; 
    public class TabbedPanel extends Panel 
    { 
	 / *  ******** 
	 * /. 
	 ******** */
	public TabbedPanel()  { 
		 //       
		 // flow-layout. 
		 Panel m_panelTabs= new Panel ();. 
		 m_panelTabs.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); 

		 //   card-layout    
		 // . 
		 Panel m_panelPanels = new Panel (); 
  		m_CardLayoutForPanels = new CardLayout(0, 0); 
		m_panelPanels.setLayout(m_CardLayoutForPanels); 

		//     TabbedPanel. 
		setLayout(new BorderLayout ()); 
		add("North", m_panelTabs); 
		add("Center", m panelPanels) ; 
	}

	/* ***********
	* Public- . 
	************* */


     .  GUI 1O1 


	public boolean addTab( String strName, Image imgSelected,  
                       Image imgUnselected, Component compPanel )  { 
		String strNameCopy = new String( strName ); 
		//  ,     , 
		if(m_hashNameToTab.contains( strNameCopy )) 
			return false; 
		//   TwoStateComp  
		//  . 
		TwoStateComp tsc = new TwoStateComp( imgSelected, imgUnselected) , 
		m_hashNameToTab.put( strNameCopy, tsc ) ; 
		m_hashNameToCompPanel.put( strName, compPanel); 
		rnjpanelTabs .add (tsc) ; 
		m_panelPanels.add(strNameCopy, compPanel); 
		//    ,   . 
		if(l == m_hashNameToTab.size() ) 
			selectTab (strNameCopy); 
		return true; 
	}
	public boolean removeTab(String strName) { 
		//  ,     . 
		Component tsc = (Component)m_hashNameToTab.get(strName) 
		Component compPanel = (Component)m_hashNameToCompPanel.get(strName) 
		if (null == tsc) 
			return false; 
		//  -,    . 
		m_hashNameToTab.remove(strName); 
		m_hashNameToCompPanel.remove(strName); 
		m_panelTabs.remove(tsc); 
		m_panelPanels.remove(compPanel); 
		//   ,     
		// .      
		//  - , 
		if(m_strSelectedTab == strName) { 
			m_strSelectedTab = null; 
			Enumeration enumKeys = m_hashNameToTab.keys() ; 
			if(enumKeys.hasMoreElements() ) { 
				String strNewSelectedTab = 
                                                                             (String)enumKeys.nextElement(); 
				selectTab(strNewSelectedTab); 
			}
		}
		return true; 
	} 


    1O2	Visual J++:   

	public boolean selectTab(String strName) { 
		//     ,   , 
		if(strName == m_strSelectedTab) 
			return true; 
		//  ,   false,  
		//     . 
		TwoStateComp tsc = (TwoStateComp)m_hashNameToTab.get(strName) 
		if ( null == tsc )     
			return false; 
		//    .  . 
		TwoStateComp tscOldSelectedTab = 
		    (TwoStateComp)m__hashNameToTab.get(m_strSelectedTab); 
		if ( null != tsc ) 
			tsc.setState( 0 ); 
		//   ,   comp , 
		tsc.setState( 1 ) ; 
		m_cardLayoutForPanels.show(m_panelPanels, strName); 
		m_strSelectedTab = new String(strName); 
 		//   ,   . 
		Event evt = new Event (this, Event .ACTION_EVENT, strName); 
		Container parent = getParent () ;   
		if (null != parent) 
			postEvent( evt ); 
		return true;     
	} 
	public   String  getSelectedTabName()    { 
		return  new  String(m_strSelectedTab) ; 
	} 
	public  Component  getSelectedTabPanel()    { 
		return   ( Component )m_hashNameToCompPanel.get(m_strSelectedTab), 
	) 
   }

     ACTION_EVENT  ,     
 ,   TabbedPanel  ,   
    TwoStateComp,  . TabbedPanel 
   ACTION_EVENT   ,  
   .     action()
 : 

    public boolean action (Event evt, Object what) { 
	//        
	// TwoStateComps,       
	//     . 
	if (!(evt.target instanceof TwoStateComp)) 
		return false; 
	TwoStateComp tsc = (TwoStateComp)evt.target; 
	if ( !m hashNameToTab.contains( tsc ) ) 


     3.  GUI	103 

		return false; 
	Enumeration enumKeys = m_hashNameToTab.keys(); 
	String strName = null; 
	for( strName = null; enumKeys.hasMoreElements() ; )  { 
		String str = (String) enumKeys.nextElement(); 
		if(tsc == m_hashNameToTab.get(str))  ( 
			strName = str; 
			break; 
		}
	} 
	selectTab(strName) ; 
	Event evt2 = new Event(this, Event.ACTION_EVENT, strName); 
	getParent() .postEvent(evt2) ; 
	return true; 
   }

   / * ******** 
     * Private- . 
     ******** * / 
   private Panel	m_panelTabs; 
   private Panel	m_panelPanels; 
   private CardLayout	m_CardLayoutForPanels; 
   private Hashtable	m_hashNameToTab; 
   private Hashtable	m_hashNameToCompPanel; 
   private String	m_strSelectedTab; 
}

     

     ,      
  Component,    .   
   .      , 
    .   , 
 ,     .    
     ,   . 
        . 
        ,     
,      .   
Java      ,   
  .      
FlowLayout, BorderLayout, CardLayout, GridLayout  GridBagLayout.  
       ,     
   

    104	Visual J++:   

  . ResourceWizard      
   DialogLayout,      
    .     
   "" . ,    
   ,    
DialogLayout   .     
,      ,   
move(), resize()  reshape().       
   . 
