您好,欢迎访问三七文档
GUIandEvent1AWT(AbstractWindowToolkit)2——Container345AWT6AWT(AbstractWindowToolkit)GraphicalUserInterfaceGUIJavaJavaJavaFoundationClassedJFCGUIAPIAWTJavaJFC2DAPISwingAWTAPI……AWTjava.awtGUIGraphicsComponentjava.lang.ObjectCheckboxContainerButton…WindowPanelAppletDialogFrameListAWTComponentjava.awtComponentJavaComponent(paint,repaint,update)(setFont,SetForeground)(SetSize,SetLocation)(ImageObserver)(SetEnable,isEnable,isVisible,isValid)……Button,Checkbox,CheckboxGroup,Choice,Label,List,Canvas,TextComponent,ScrollbarAWTAWTComponentMenuComponentAWTContainerContainerComponentGUIadd()remove()…ContainerContainersetLayout()ContainerFrame,Dialog,Panel,AppletAWTJavaLayoutManagerFlowLayoutBorderLayoutGridLayoutCardLayoutGridBagLayoutLayoutManagerAWTGraphicsGraphicsGraphicsXORPaintXOR……AWTGraphicsLinesdrawLine()RectanglesdrawRect(),fillRect()clearRect()Raisedorloweredrectanglesdraw3DRect()fill3DRect()Round-edgedrectanglesdrawRoundRect()fillRoundRect()OvalsdrawOval()fillOval()ArcsdrawArc()fillArc()PolygonsdrawPolygon()fillPolygon()TextdrawString()ImagedrawImage()AnimationAWTAWTEventEventGUIGIFJEPG……AWTpeersjava.awt.peerawtawtGUIJavaComponentButton,Checkbox,Choice,Label,List——ContainerContainerComponentContainerContainerContainerWindowPanelComponentFrameDialogFileDialogAppletButtonListCheckboxTextfieldAWTContainerWindowPanelWindowDialogJavaDialog——FileDialogFrameFrameFame(String)StringFrame00FrameDemo:Frameimportjava.awt.*;publicclassframeextendsFrame{publicstaticvoidmain(Stringargs[]){Framefr=newFrame(FrameTest);fr.setSize(400,300);fr.setBackground(Color.gray);fr.setVisible(true);}}Demo:Dialogimportjava.awt.*;publicclassmyFrameextendsFrame{publicstaticvoidmain(Stringargs[]){myFramefr=newmyFrame(FrameTest);fr.setSize(400,300);fr.setBackground(Color.white);fr.setVisible(true);fr.showDialog();}publicmyFrame(Strings){super(s);}publicvoidshowDialog(){Dialogfd=newDialog(this,DialogTest,true);fd.setSize(100,100);fd.setBackground(Color.red);fd.setVisible(true);}}PanelPanelPanel()PanelWindowFrameadd()PanelAppletPanelPanelPanel(Frame)FrameFrameWindowEventFrameFrameWindowListenerWindowEventFrameFrame(Panel)(Dialog)FrameDialog(Parent,Title,isModal)//(FileDialog)getFile()(ScrollPane)PanelDialogpublicclassMyFrameextendsFrame{publicstaticvoidmain(Stringargs[]){MyFramefr=newMyFrame(FrameandFileDialogTest);fr.setSize(500,500);fr.setBackground(Color.blue);fr.setVisible(true);fr.showDialog();}publicMyFrame(Stringstr){super(str);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicvoidshowDialog(){FileDialogfd=newFileDialog(this,FileDialog);fd.setVisible(true);}}publicclassMyPanelInFrameextendsFrame{publicMyPanelInFrame(Stringstr){super(str);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicstaticvoidmain(Stringargs[]){MyPanelInFramefr=newMyPanelInFrame(PanelinFrame);Panelpan=newPanel();fr.setSize(500,500);fr.setBackground(Color.green);fr.setLayout(null);pan.setSize(200,200);pan.setBackground(Color.yellow);pan.setLocation(100,100);Buttonb1=newButton(Help);Buttonb2=newButton(Test);pan.add(b1);pan.add(b2);fr.add(pan);fr.setVisible(true);}}AWTnewaddactionAWT(Button)AcitonEventActionListener(Checkbox)“on/off”ItemEventItemListener(CheckboxGroup)——(RadioButton)(Choice)ItemEventItemListenerDemo//Checkboxpan.add(newCheckbox(one,null,true));pan.add(newCheckbox(two,null,false));pan.add(newCheckbox(three,null,false));//CheckboxGroupCheckboxGroupcbg=newCheckboxGroup();add(newCheckbox(“one”,cbg,true));add(newCheckbox(“two”,cbg,false));add(newCheckbox(“three”,cbg,false));//ChoiceChoicech=newChoice();pan.add(ch);ch.add(“Green”);ch.add(“Red”);ch.add(“Blue”);AWT(Label)(TextField)——TextComponentActionEventActionListener(TextArea)——TextComponent(List)ItemEvent//TextFieldTextFieldtf1,tf2,tf3,tf4;tf1=newTextField();//ablanktextfieldtf2=newTextField(,20);//blankfieldof20columnstf3=newTextField(Hello!);//predefinedtextdisplayedtf4=newTextField(Hello,30);//predefinedtextin30columnsDemo//TextAreaadd(newTextArea(Hello,5,40););//ListListlst=newList(4,false);lst.add(Mercury);lst.add(Venus);lst.add(Earth);lst.add(JavaSoft);lst.add(Mars);lst.add(Neptune);add(lst);AWT(Scrollbar)ScrollPane(Canvas)paint()KeyListenerMouseMotionListenerMouseListenerrequestFoucus()mouseClicked()AWT9(MenuBar)FramesetMenuBar()9(Menu)9(MenuItem)ActionListenerActionEvent9(CheckboxMenuItem)ItemListenerItemEvent9(PopupMenu)AWTComponentenableEvents()setText()repaint()repaint()invalidate()AWTpaint()getPreferredSize()getMinimumSize()addActionListener()removeActionListener()AWTEventMulticastercontains()processXXXX()processMouseEvent()……012435401534JavasetLocation(),setSize(),setBounds()setLayout(null)setLocation(),setSize(),setBounds()PanelWindowsFrameJavaFlowLayoutPanelAppletBorderLayoutWindowDialogFrameGridLayoutCardLayoutGridBagLayoutFlowLayoutgetPreferredSize()FlowLayoutpublicFlowLayout()5publicFlowLayout(intalignment)FlowLayout.LEF
本文标题:Java界面设计
链接地址:https://www.777doc.com/doc-4222113 .html