Java界面设计

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

GUIandEvent1AWT(AbstractWindowToolkit)2——Container345AWT6AWT(AbstractWindowToolkit)GraphicalUserInterfaceGUIJavaJavaJavaFoundationClassedJFCGUIAPIƒAWTJavaJFCƒ2DAPIƒSwingAWTƒAPIƒ……AWTjava.awtGUIGraphicsComponentjava.lang.ObjectCheckboxContainerButton…WindowPanelAppletDialogFrameListAWTƒComponentjava.awtComponentJavaComponent(paint,repaint,update)(setFont,SetForeground)(SetSize,SetLocation)(ImageObserver)(SetEnable,isEnable,isVisible,isValid)……Button,Checkbox,CheckboxGroup,Choice,Label,List,Canvas,TextComponent,ScrollbarAWTAWTƒComponentMenuComponentAWTƒContainerContainerComponentGUIƒadd()remove()…ƒContainerContainersetLayout()ContainerFrame,Dialog,Panel,AppletAWTƒJavaLayoutManagerƒFlowLayoutƒBorderLayoutƒGridLayoutƒCardLayoutƒGridBagLayoutLayoutManagerAWTƒGraphicsGraphicsGraphicsƒƒƒƒXORPaintƒXORƒ……AWTGraphicsƒLinesdrawLine()ƒRectanglesdrawRect(),fillRect()clearRect()ƒRaisedorloweredrectanglesdraw3DRect()fill3DRect()ƒRound-edgedrectanglesdrawRoundRect()fillRoundRect()ƒOvalsdrawOval()fillOval()ƒArcsdrawArc()fillArc()ƒPolygonsdrawPolygon()fillPolygon()ƒTextdrawString()ƒImagedrawImage()ƒAnimationAWTƒAWTEventEventƒGUIƒGIFJEPGƒƒ……AWTƒpeersjava.awt.peerawtawtGUIJavaComponentButton,Checkbox,Choice,Label,List——ContainerContainerComponentContainerContainerContainerWindowPanelComponentFrameDialogFileDialogAppletButtonListCheckboxTextfieldAWTContainerWindowPanelWindowƒDialogJavaDialog——FileDialogƒFrameFrameFame(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()AWTƒ9(MenuBar)FramesetMenuBar()9(Menu)9(MenuItem)ActionListenerActionEvent9(CheckboxMenuItem)ItemListenerItemEvent9(PopupMenu)AWTComponentƒenableEvents()ƒsetText()repaint()repaint()invalidate()AWTƒpaint()getPreferredSize()getMinimumSize()ƒaddActionListener()removeActionListener()AWTEventMulticasterƒcontains()ƒprocessXXXX()processMouseEvent()……012435401534JavaƒsetLocation(),setSize(),setBounds()ƒsetLayout(null)setLocation(),setSize(),setBounds()PanelWindowsFrameJavaƒFlowLayoutPanelAppletƒBorderLayoutWindowDialogFrameƒGridLayoutƒCardLayoutƒGridBagLayoutFlowLayoutgetPreferredSize()FlowLayoutpublicFlowLayout()5publicFlowLayout(intalignment)FlowLayout.LEF

1 / 74
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功