21AWT19AWTAWTAWTAWTAWTAWT22AWTJava23AWTAWTGUIJava20,21.1AWTAWTjava.awtJava21-1AWT21-1AWTClassAWTEventAWTAWTEventMulticasterBorderLayoutNorthSouthEastWestCenterButtonCanvasCardLayoutCheckboxCheckboxGroupCheckboxMenuItem/21AWT471ClassChoiceColorComponentAWTContainerCursorDialogDimensionwidthheightEventEventQueueFileDialogFlowLayoutFontFontMetricsFrameGraphicsGraphicsDeviceGraphicsEnvironmentFontGraphicsDeviceGridBagConstraintsGridBagLayoutGridBagLayoutGridBagConstraintsGridLayoutImageInsetsLabelListMediaTrackerMenuMenuBarMenuComponentMenuItemMenuShortcutPanelPointxyPolygonPopupMenuPrintJob4722JavaClassRectangleRobotAWTJava2,v1.3ScrollbarsScrollPane/SystemColorGUITextAreaTextComponentTextAreaTextFieldTextFieldToolkitAWTWindowJava1.0AWTJava1.1Java221.2AWTPanelFramePanelFrame21-1PanelFrame21.2.1ComponentAWTComponentComponentComponent(1920)Component21AWT47321-1PanelFrame21.2.2ContainerContainerComponentComponentContainerContainerContainerComponent2221.2.3PanelPanelContainerContainerPanelPanelAppletPanelPanelPaneladd()PanelContainerComponentsetLocation(),setSize()setBounds()21.2.4WindowWindowWindowWindowFrame21.2.5FrameFrameWindowFrameComponentContainerPanelWindowMenuContainerInterfaceFrame4742JavaJavaAppletWindowFrame21.2.6CanvasframeCanvasCanvasCanvas21.3FrameFrameFrameFrame()Frame(Stringtitle)titleFrame21.3.1setSize()voidsetSize(intnewWidth,intnewHeight)voidsetSize(DimensionnewSize)newWidthnewHeightDimensionnewSizewidthheightgetSize()DimensiongetSize()Dimensionwidthheight21.3.2framesetVisible()21AWT475voidsetVisible(booleanvisibleFlag)true21.3.3setTitle()framevoidsetTitle(StringnewTitle)newtitle21.3.4frameframesetVisible(false)WindowListenerwindowClosing()windowClosing()21.4frameframeframeframeframeframeinit()start()stop()paint()windowListenerwindowClosing()setVisible(false)frameframesetVisible()setSize()SampleFrameFrameAppletFrameinit()SampleFrameFrameframetitlestart()stop()//Createachildframewindowfromwithinanapplet.importjava.awt.*;4762Javaimportjava.awt.event.*;importjava.applet.*;/*appletcode=AppletFramewidth=300height=50/applet*///CreateasubclassofFrame.classSampleFrameextendsFrame{SampleFrame(Stringtitle){super(title);//createanobjecttohandlewindoweventsMyWindowAdapteradapter=newMyWindowAdapter(this);//registerittoreceivethoseeventsaddWindowListener(adapter);}publicvoidpaint(Graphicsg){g.drawString(Thisisinframewindow,10,40);}}classMyWindowAdapterextendsWindowAdapter{SampleFramesampleFrame;publicMyWindowAdapter(SampleFramesampleFrame){this.sampleFrame=sampleFrame;}publicvoidwindowClosing(WindowEventwe){sampleFrame.setVisible(false);}}//Createframewindow.publicclassAppletFrameextendsApplet{Framef;publicvoidinit(){f=newSampleFrame(AFrameWindow);f.setSize(250,250);f.setVisible(true);}publicvoidstart(){f.setVisible(true);}publicvoidstop(){f.setVisible(false);}publicvoidpaint(Graphicsg){g.drawString(Thisisinappletwindow,10,20);}}21AWT47721.4.1FrameFrameComponentComponentframepaint()repaint()//Handlemouseeventsinbothchildandappletwindows.importjava.awt.*;importjava.awt.event.*;importjava.applet.*;/*appletcode=WindowEventswidth=300height=50/applet*///CreateasubclassofFrame.classSampleFrameextendsFrameimplementsMouseListener,MouseMotionListener{Stringmsg=;intmouseX=10,mouseY=40;intmovX=0,movY=0;SampleFrame(Stringtitle){super(title);//registerthisobjecttoreceiveitsownmouseeventsaddMouseListener(this);addMouseMotionListener(this);//createanobjecttohandlewindoweventsMyWindowAdapteradapter=newMyWindowAdapter(this);//registerittoreceivethoseeventsaddWindowListener(adapter);}//Handlemouseclicked.4782JavapublicvoidmouseClicked(MouseEventme){}//Handlemouseentered.publicvoidmouseEntered(MouseEventevtObj){//savecoordinatesmouseX=10;mouseY=54;msg=Mousejustenteredchild.;repaint();}//Handlemouseexited.publicvoidmouseExited(MouseEventevtObj){//savecoordinatesmouseX=10;mouseY=54;msg=Mousejustleftchildwindow.;repaint();}//Handlemousepressed.publicvoidmousePressed(MouseEventme){//savecoordinatesmouseX=me.getX();mouseY=me.getY();msg=Down;repaint();}//Handlemousereleased.publicvoidmouseReleased(MouseEventme){//savecoordinatesmouseX=me.getX();mouseY=me.getY();msg=Up;repaint();}//Handlemousedragged.publicvoidmouseDragged(MouseEventme){//savecoordinatesmouseX=me.getX();mouseY=me.getY();movX=me.getX();movY=me.getY();msg=*;repaint();}//Handlemousemoved.publicvoidmouseMoved(MouseEventme){//savecoordinatesmovX=me.getX();movY=me.getY();repaint(0,0,100,60);21AWT479}publicvoidpaint(Graphicsg){g.drawString(msg,mouseX,mouseY);g.drawString(Mouseat+movX+,+movY,10,40);}}classMyWindowAdapterextendsWindowAdapter{SampleFramesampleFrame;publicMyWindowAdapter(SampleFramesampleFrame){this.sampleFrame=sampleFrame;}publicvoidwindowClosing(WindowEventwe){sampleFrame.setVisible(false);}}//Appletwindow.publicclassWindowEventsextendsAppletimplementsMouseListener,MouseMotionListener{SampleFramef;Stringmsg=;intmouseX=0,mouseY=10;intmovX=0,movY=0;//Createaframewindow.publicvoidinit(){f=newSampleFrame(HandleMouseEvents);f.setSize(300,200);f.setVisible(t