第05章-图形用户界面设计

上传人:zhan****gclb 文档编号:220238625 上传时间:2023-06-29 格式:PPT 页数:69 大小:1.44MB
收藏 版权申诉 举报 下载
第05章-图形用户界面设计_第1页
第1页 / 共69页
第05章-图形用户界面设计_第2页
第2页 / 共69页
第05章-图形用户界面设计_第3页
第3页 / 共69页
资源描述:

《第05章-图形用户界面设计》由会员分享,可在线阅读,更多相关《第05章-图形用户界面设计(69页珍藏版)》请在装配图网上搜索。

1、1.概述2.事件处理3.基本控制组件4.布局设计5.常用容器组件第五章 图形用户界面设计1概述n用户界面(User Interface)n用户与计算机系统(各种程序)交互的接口2GraphicalGraphicalUser InterfaceUser InterfaceNatural Natural User InterfaceUser Interface19901990GUIGUIMultiple WindowsMultiple WindowsMenusMenus19951995InternetInternetHyperlinksHyperlinksSearch EnginesSearch

2、EnginesDigital DecadeDigital DecadeXMLXMLWeb ServicesWeb ServicesSmart devicesSmart devicesNatural LanguageNatural LanguageMultimodal(speech,ink)Multimodal(speech,ink)Personal AssistantPersonal AssistantCommand lineCommand line19851985PCPCUser Interface Evolutionn-Kai Fu Lee in 20033概述nJava GUI的发展1.

3、AWT(Java 1.0)nAWT(Abstract Window Toolkit):抽象窗口工具包n概念设计实现(about 1 month)n字体设计(四种),界面显示(二流水准)2.Swing(Lightweight Components,Java 1.1)nSwing was the code name of the project that developed the new componentsnSwing API(附加包,Add-on package)3.JFC(Java 2)nJFC(Java Foundation Classes):Java基础类nJFC encompass

4、a group of features to help people build graphical user interfaces(GUIs).nJFC 是指包含在 Java 2 平台内的一整套图形和用户界面技术nJFC was first announced at the 1997 JavaOne developer conference 4概述nJFC(Java Foundation Classes)1.AWT(Abstract Window Toolkit)n一些用户界面组件(Component)n事件响应模型(Event-handling model)n布局管理器(Layout ma

5、nager)n绘图和图形操作类,如Shape、Font、Color类等2.Swing Components(Swing组件,JFC的核心)na set of GUI components with a pluggable look and feel(包括已有的AWT组件(Button、Scrollbar、Label等)和更高层的组件(如tree view、list box、tabbed panes等)nThe pluggable look and feel lets you design a single set of GUI components that can automatically

6、 have the look and feel of any OS platform(Microsoft Windows,Solaris,Macintosh).n基于Java 1.1 Lightweight UI Framework5概述nJFC(Java Foundation Classes)3.Java 2D(advanced 2D graphics and imaging)nGraphics?nImaging?4.Print Servicen打印文档、图形、图像n设定打印属性和页面属性n发现打印机(IPP,Internet Printing Protocol)6概述nJFC(Java F

7、oundation Classes)5.Input Method Frameworkntext editing components to communicate with input methods and implement a well-integrated text input user interfacen用Java语言开发输入法6.Accessibility:辅助功能,帮助伤残人士nscreen readers,speech recognition systems,refreshable braille displays7.Drag&DropnDrag and Drop enabl

8、es data transfer both across Java programming language and native applications,between Java programming language applications,and within a single Java programming language application.7图形用户界面的构成n什么是组件?n构成图形用户界面的元素,拿来即用n用图形表示(能在屏幕上显示,能和用户进行交互)nButton、Checkbox、Scrollbar、Choice、Frame8图形用户界面的构成n一些特定的Jav

9、a类njava.awt包njavax.swing包n容器组件(Container):可包含其他组件n顶层容器:Dialog,Frame,Windown一般用途容器:Panel,ScrollPanen特定用途容器:InternalFramen非容器组件:必须要包含在容器中nButton,Checkbox,Scrollbar,Choice,Canvas9图形用户界面的构成nAWT组件 java.awt包ComponentButton,Canvas,Checkbox,Choice,Label,List,ScrollbarTextComponentTextAreaTextFieldContainerP

10、anelWindowScrollPaneDialogFrameMenuComponentMenuBarMenuItem10图形用户界面的构成nSwing组件 javax.swing包njava.awt.Component|-java.awt.Container|-java.awt.Window|-java.awt.Frame|-javax.swing.JFramenjava.awt.Component|-java.awt.Container|-javax.swing.JComponent|-JComboBox,JFileChooser,JInternalFrame JLabel,JList,J

11、MenuBar,JOptionPane,JPanel JPopupMenu,JProgressBar,JScrollBar JScrollPane,JSeparator,JSlider,JSpinner JSplitPane,JTabbedPane,JTable JTextComponent,JToolBar,JTree等11图形用户界面的实现1.选取组件2.设计布局3.响应事件n应用原则nSwing比AWT提供更全面、更丰富的图形界面设计功能nJava 2平台支持AWT组件,但鼓励用Swing组件n主要讲述AWT和Swing的图形界面设计12图形用户界面的实现n简单实例import java

12、x.swing.*;import java.awt.event.*;public class HelloWorldSwing public static void main(String args)JFrame f=new JFrame(“Swing1);JLabel label=new JLabel(Hello!);f.getContentPane().add(label);f.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););f.setSize(200,

13、200);f.setVisible(true);import java.awt.*;import java.awt.event.*;public class HelloWorldAWT public static void main(String args)Frame f=new Frame(AWT1);Label label=new Label(Hello!);f.add(label);f.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););f.setSiz

14、e(200,200);f.setVisible(true);131.概述2.事件处理3.基本控制组件4.布局设计5.常用容器组件第五章 图形用户界面设计14事件处理n界面设计(静态)n界面动起来!n通过事件触发对象的响应机制n事件?鼠标移动、鼠标点击、键盘键入等n事件处理机制n事件源n事件对象n事件监听者n如何实现1.实现(implements)事件监听接口(interface)产生一个监听器对象(Listener)2.监听谁?将该监听器对象注册到组件对象中3.编写事件响应方法15事件处理import javax.swing.*;import java.awt.*;import java.aw

15、t.event.*;public class Beeper extends JApplet implements ActionListener JButton button;public void init()button=new JButton(Click Me);getContentPane().add(button,BorderLayout.CENTER);button.addActionListener(this);public void actionPerformed(ActionEvent e)System.out.println(“Click me once”);java.awt

16、.event.ActionListener (interface)public void actionPerformed(ActionEvent e)javax.swing.JButton(class)public void addActionListener(ActionListener l)16事件处理n事件分类Act that results in the event Listener type User clicks a button,presses Return while typing in a text field,or chooses a menu item ActionLis

17、tener User closes a frame(main window)WindowListener User presses a mouse button while the cursor is over a component MouseListener User moves the mouse over a component MouseMotionListener Component becomes visible ComponentListener Component gets the keyboard focus FocusListener Table or list sele

18、ction changes ListSelectionListener 17事件处理n事件分类1.interface java.awt.event.ActionListenernpublic void actionPerformed(ActionEvent e)2.interface java.awt.event.WindowListenernpublic void windowOpened(WindowEvent e)npublic void windowClosing(WindowEvent e)npublic void windowClosed(WindowEvent e)npublic

19、 void windowIconified(WindowEvent e)npublic void windowDeiconified(WindowEvent e)npublic void windowActivated(WindowEvent e)npublic void windowDeactivated(WindowEvent e)18事件处理n事件分类3.interface java.awt.event.MouseListenernpublic void mouseClicked(MouseEvent e)npublic void mousePressed(MouseEvent e)np

20、ublic void mouseReleased(MouseEvent e)npublic void mouseEntered(MouseEvent e)npublic void mouseExited(MouseEvent e)4.interface java.awt.event.MouseMotionListenernpublic void mouseDragged(MouseEvent e)nInvoked when a mouse button is pressed on a component and then draggednpublic void mouseMoved(Mouse

21、Event e)nInvoked when the mouse cursor has been moved onto a component but no buttons have been pushed19事件处理n鼠标事件public class MouseEventDemo.implements MouseListener ./Register for mouse events on blankArea(TextArea)and applet blankArea.addMouseListener(this);public void mousePressed(MouseEvent e)sa

22、ySomething(Mouse pressed;#of clicks:“+e.getClickCount(),e);public void mouseReleased(MouseEvent e)saySomething(Mouse released;#of clicks:+e.getClickCount(),e);public void mouseEntered(MouseEvent e)saySomething(Mouse entered,e);public void mouseExited(MouseEvent e)saySomething(Mouse exited,e);public

23、void mouseClicked(MouseEvent e)saySomething(Mouse clicked(#of clicks:“+e.getClickCount()+),e);void saySomething(String eventDescription,MouseEvent e)textArea.append(eventDescription+detected on“+e.getComponent().getClass().getName()+.+newline);20事件处理n多个监听器(Listener)多个组件public class MultiListener.imp

24、lements ActionListener .button1.addActionListener(this);button2.addActionListener(this);button2.addActionListener(new Eavesdropper(bottomTextArea);public void actionPerformed(ActionEvent e)topTextArea.append(e.getActionCommand()+newline);class Eavesdropper implements ActionListener .public void acti

25、onPerformed(ActionEvent e)myTextArea.append(e.getActionCommand()+newline);21第五章 图形用户界面设计1.概述2.事件处理3.基本控制组件4.布局设计5.常用容器组件22AWT组件(java.awt.*)Component Button Canvas ChoiceCheckBoxLabelListTextComponentScrollbarTextFieldTextArea ContainerScrollPaneFrameFileDialogPanelWindowDialogApplet23基本控制组件n使用步骤:n创建

26、基本控制组件类的对象,指定对象属性;n将组件对象加入到制定容器的适当位置(布局设计);n创建事件对象的监听者。nSwing组件(javax.swing.*)24按钮和标签n按钮(Button)n创建按钮npublic Button()npublic Button(String label)n常用方法npublic String getLabel()npublic void setLabel(String label)npublic void setActionCommand(String s)npublic String getActionCommand(String s)n事件响应njava

27、.awt.event.ActionListener(接口)nvoid actionPerformed(ActionEvent e)25按钮和标签n标签(Label)n创建标签npublic Label()npublic Label(String s)npublic Label(String s,int alignment)n常用方法npublic String getText()npublic void setText(String s)npublic void setAlignment(int alignment)n事件响应n不引发事件26使用标签的例子import java.awt.*;i

28、mport java.applet.*;public class Exam5_3 extends Applet Label lab1,lab2;TextField text1,text2;public void init()lab1=new Label(“输入姓名”);lab2=new Label(“输入年龄”);lab1.setBackground(Color.red);lab2.setBackground(Color.green);text1=new TextField(10);text2=new TextField(10);add(lab1);add(text1);add(lab2);a

29、dd(text2);27使用标签的例子28文本框和文本区n文本框(TextField)nTextComponent类的子类n创建文本框npublic TextField()npublic TextField(int size)npublic TextField(String s)npublic TextField(String s,int size)n常用方法npublic void setText(String s)npublic String getText()npublic void setEchochar(char c)npublic void setEditable(boolean

30、b)n事件响应njava.awt.event.TextListener(接口)njava.awt.event.ActionListener(接口)29文本框和文本区n文本区(TextArea)nTextComponent类的子类n创建文本区npublic TextArea()npublic TextArea(String s)npublic TextArea(int rows,int columns)npublic TextArea(String s,int rows,int columns)npublic TextArea(String s,int rows,int columns,int

31、scrollbars)nSCROLLBARS_BOTH,SCROLLBARS_NONEnSCROLLBARS_VERTICAL_ONLYnSCROLLBARS_HORIZONTAL_ONLYn常用方法npublic void append(String s)npublic void insert(String s,int index)npubilc void replaceRange(String s,int start,int end)n事件响应njava.awt.event.TextListener(接口)nvoid textValueChanged(TextEvent e)30使用文本框

32、的例子import java.awt.*;import java.awt.event.*;import java.applet.*;public class Exam5_4 extends Applet implements ActionListenerLabel lab1,lab2,lab3;TextField text1,text2,text3;String str;int i;float f;public void init()lab1=new Label(“输入整形数:”);add(lab1);text1=new TextField(“0”,30);text1.addActionLis

33、tener(this);add(text1);lab2=new Label(“输入浮点数:”);add(lab2);text2=new TextField(“0.0”,30);text2.addActionListener(this);add(text2);lab3=new Label(“输入字符串:”);add(lab3);text3=new TextField(“0.0”,30);text3.addActionListener(this);add(text3);31使用文本框的例子public void actionPerformed(ActionEvent e)i=Integer.par

34、seInt(text1.getText();f=(Float.valueOf(text2.getText().floatValue();str=text3.getText();repaint();public void paint(Graphics g)g.drawString(“整形数=”+i,20,120);g.drawString(“浮点数=”+f,20,150);g.drawString(“字符串=”+str,20,180);32单复选框和列表n复选框(Checkbox)n创建复选框npublic Checkbox()npublic Checkbox(String s)npublic

35、TextField(String s,boolean state)n常用方法npublic boolean getState()npublic void setState(boolean b)npublic void setLabel(String s)npublic String getLabel()n事件响应njava.awt.event.ItemListener(接口)nvoid itemStateChanged(ItemEvent e)33单复选框和列表n单选按钮组(CheckboxGroup)n创建单选按钮组npublic Checkbox(String label,boolean

36、state,CheckboxGroup group)npublic Checkbox(String label,CheckboxGroup group,boolean state)n常用方法n与复选框相同n事件响应n与复选框相同34单复选框和列表n列表(List)n创建列表npublic List()npublic List(int n)npublic List(int n,boolean b)n常用方法npublic void add(String s)npublic void add(String s,int n)npublic void remove(int n)npublic void

37、 removeAll()npublic int getSelectedIndex()npublic String getSelectedItem()n事件响应njava.awt.event.ItemListener(接口)njava.awt.event.ActionListener(接口)35下拉列表和滚动条n下拉列表(Choice)n创建下拉列表npublic Choice()n常用方法npublic int getSelectedIndex()npublic String getSelectedItem()npublic void select(int index)npublic void

38、 select(String item)npublic void add(String s)npublic void add(String s,int index)npublic void remove(int index)npublic void remove(String item)npublic void removeAll()n事件响应njava.awt.event.ItemListener(接口)36下拉列表和滚动条n滚动条(Scrollbar)n创建滚动条npublic Scrollbar(int orientation,int value,int visible,int mini

39、mum,int maximum)n常用方法npublic void setUnitIncrement(int n)npublic void setBlockIncrement(int n)npublic int getUnitIncrement()npublic int getBlockIncrement()npublic int getValue()n事件响应njava.awt.event.AdjustmentListener(接口)nvoid adjustmentValueChanged(AdjustmentEvent e)37使用下列列表的例子import java.awt.*;impo

40、rt java.awt.event.*;import java.applet.*;public class Exam5_8 extends Applet implements ItemListener Choice cho;TextField text;public void init()text=new TextField(10);cho=new Choice();cho.add(“red”);cho.add(“yellow”);cho.add(“green”);cho.add(“blue”);add(cho);add(text);cho.addItemListener(this);publ

41、ic void itemStateChanged(ItemEvent e)if(e.getItemSelectable()=cho)String s=cho.getSelectedItem();text.setText(s);38使用下列列表例子39画布n画布(Canvas)n创建画布npublic Canvas()n常用方法npublic void setSize()npublic void paint(Graphics g)n事件响应njava.awt.event.MouseMotionListener(接口)njava.awt.event.MouseListener(接口)njava.a

42、wt.event.KeyListener(接口)401.概述2.事件处理3.基本控制组件4.布局设计5.常用容器组件第五章 图形用户界面设计41布局管理n决定组件在界面中所处的位置和大小 n六种布局管理器(Layout Manager)n两种简单布局njava.awt.FlowLayout (JDK 1.0)njava.awt.GridLayout (JDK 1.0)n两种特定用途布局njava.awt.BorderLayout (JDK 1.0)njava.awt.CardLayout (JDK 1.0)n两种灵活布局njava.awt.GridBagLayout(JDK 1.0)njava

43、x.swing.BoxLayout42布局管理nFlowLayout(java.awt.FlowLayout)n所有组件从左往右排成一行n 一行排满后转到下一行从左往右排n居中、左对齐、右对齐import java.awt.*;import javax.swing.*;public class FlowWindow extends JFrame public FlowWindow()Container contentPane=getContentPane();contentPane.setLayout(new FlowLayout();contentPane.add(new JButton(B

44、utton 1);contentPane.add(new JButton(2);contentPane.add(new JButton(Button 3);contentPane.add(new JButton(Long-Named Button 4);contentPane.add(new JButton(Button 5);public static void main(String args)FlowWindow win=new FlowWindow();win.setTitle(FlowLayout);win.pack();win.setVisible(true);public voi

45、d pack()Causes this Window to be sized to fit the perferred size and layouts of its subcomponents43布局管理nGridLayout(java.awt.GridLayout)n将空间划分为由行和列组成的网格单元,每个单元放一个组件,网格单元大小相同(宽度和高度)n指定行数和列数import java.awt.*;import javax.swing.*;public class GridWindow extends JFrame public GridWindow()Container conten

46、tPane=getContentPane();contentPane.setLayout(new GridLayout(0,2);contentPane.add(new JButton(Button 1);contentPane.add(new JButton(2);contentPane.add(new JButton(Button 3);contentPane.add(new JButton(Long-Named Button 4);contentPane.add(new JButton(Button 5);public static void main(String args)GridW

47、indow win=new GridWindow();win.setTitle(FlowLayout);win.pack();win.setVisible(true);public GridLayout(int rows,int cols)rows and cols can be zero,which means that any number of objects can be placed in a row or in a column44布局管理nBorderLayout(java.awt.BorderLayout)nBorderLayout is the default layout

48、manager for every content pane n上北、下南、左西、右东、中Container contentPane=getContentPane();/contentPane.setLayout(new BorderLayout();contentPane.add(new JButton(Button 1(NORTH),BorderLayout.NORTH);contentPane.add(new JButton(2(CENTER),BorderLayout.CENTER);contentPane.add(new JButton(Button 3(WEST),BorderLa

49、yout.WEST);contentPane.add(new JButton(Long-Named Button 4(SOUTH),BorderLayout.SOUTH);contentPane.add(new JButton(Button 5(EAST),BorderLayout.EAST);45布局管理nCardLayout(java.awt.CardLayout)n两个或多个组件共享相同的显示空间,在不同的时间显示不同的组件46布局管理nGridBagLayout(java.awt.GridBagLayout)n最精细、最灵活的布局管理n将空间划分为由行和列组成的网格单元,每个单元放一个

50、组件,网格单元大小可以不同(宽度和高度)47布局管理nBoxLayout(javax.swing.BoxLayout)n将组件放在一行或一列JPanel jpv=new JPanel();jpv.setLayout(new BoxLayout(jpv,BoxLayout.Y_AXIS);for(int i=0;i 5;i+)jpv.add(new JButton(+i);JPanel jph=new JPanel();jph.setLayout(new BoxLayout(jph,BoxLayout.X_AXIS);for(int i=0;i 5;i+)jph.add(new JButton(

51、+i);Container cp=getContentPane();cp.add(BorderLayout.EAST,jpv);cp.add(BorderLayout.SOUTH,jph);容器的嵌套(面板的嵌套,相互包含)48第五章 图形用户界面设计1.概述2.事件处理3.基本控制组件4.布局设计5.常用容器组件49概述n容器n可包含其他组件和容器nContainer类的子类n无边框容器:Panel,Appletn有边框容器:Window,Frame,Dialog,FieldDialogn可自动处理滚动操作的容器:Scrollpane ContainerScrollPaneFrameFile

52、DialogPanelWindowDialogApplet50容器n常用方法n添加组件:add()n获取制定的组件ngetComponent(int x,int y)ngetComponent(int index)n从容器中移出组件nremove(Component c)nremove(int index)nremoveAll()n设置容器布局:setLayout()51容器n面板(Panel)n无边框容器n顺序布局(FlowLayout)nApplet子类52窗口和菜单njava.awt.Window:最顶层容器nWindow(Frame f)nshow()nBorderLayout布局nj

53、ava.awt.Frame:有边框容器n构造方法nFrame()nFrame(String title)nBorderLayout布局n常用方法ngetTitle()nsetTitle(String s)nsetVisible(boolean b)nsetBounds(int a,int b,int width,int height)nsetBackground(Color c)npack()nsetSize(int width,int height)ndispose()nadd()nremove()53使用Frame容器的例子import java.awt.*;import java.awt

54、.event.*;public class Exam5_18 public static void main(String args)MyFrame mf=new MyFrame();class MyFrame extends Frame implements ActionListener,MouseListener,WindowListener Button but;String str;String mouseClickCnt=“单击单击”;Dimension currentPos=new Dimension();int clickCnt=0;MyFrame()super(“我制作的窗口我

55、制作的窗口”);but=new Button(“按钮按钮”);setLayout(new FlowLayout();add(but);but.addActionListener(this);addMouseListener(this);addWindowListener(this);pack();show();54使用Frame容器的例子public void paint(Graphics g)str=“单击了单击了”+clickCnt+“次按钮次按钮”;g.drawString(str,10,40);g.drawString(“鼠标鼠标”+mouseClickCnt+“位置位置:(”+cur

56、rentPos.width+“,”+currentPos.height+“)”,10,70);public void actionPerformed(ActionEvent e)if(e.getSource()=but)clickCnt+;repaint();public void mouseClicked(MouseEvent e)currentPos.width=e.getX();currentPos.height=e.getY();if(e.getClickCount()=1)mouseClickCnt=“单击单击”;else mouseClickCnt=“双击双击”;repaint()

57、;55使用Frame容器的例子public void mousePressed(MouseEvent e);public void mouseReleased(MouseEvent e);public void mouseEntered(MouseEvent e);public void mouseExited(MouseEvent e);public void windowClosing(WindowEvent e)dispose();System.exit(0);public void windowOpened(WindowEvent e);public void windowClosed

58、(WindowEvent e);public void windowIconified(WindowEvent e);public void windowDeiconified(WindowEvent e);public void windowActivated(WindowEvent e);public void windowDeactivated(WindowEvent e);56菜单组件njava.awt.MenuBar类nMenuBar()nsetMenuBar(菜单对象)njava.awt.Menu类njava.awt.MenuItem类njava.awt.CheckboxMenuI

59、tem类njava.awt.PopupMenu类MenuComponentMenuBarCheckboxMenuItemPopupMenuMenuItem Menu57使用菜单组件的例子import java.awt.*;import java.awt.event.*;public class Exam5_19 extends Frame implements ActionListener,ItemListener TextField text;public Exam5_19()super(“我的菜单窗口我的菜单窗口”);setSize(300,200);public void init()M

60、enuBar myB=new MenuBar();setMenuBar(myB);Menu m1=new Menu(“文件文件”);m1.add(new MenuItem(“打开打开”);MenuItem m11=new MenuItem(“保存保存”);m11.setEnabled(false);m1.add(m11);m1.addSeparator();m1.add(“退出退出”);m1.addActionListener(this);myB.add(m1);58使用菜单组件的例子Menu m2=new Menu(“编辑编辑”);m2.add(“复制复制”);Menu m21=new Me

61、nu(“颜色颜色”);m21.add(“前景色前景色”);m21.add(“背景色背景色”);m21.addActionListener(this);m2.add(m21);m2.addSeparator();CheckboxMenuItem mycmi=new CheckboxMenuItem(“全选全选”);mycmi.addItemListener(this);m2.add(mycmi);m2.addActionListener(this);myB.add(m2);Menu m3=new Menu(“帮助帮助”);m3.add(“关于关于”);m3.addActionListener(t

62、his);myB.setHelpMenu(m3);text=new TextField();add(“South”,text);59使用菜单组件的例子public static void main(String args)Exam5_19 myMenu=new Exam5_19();myMenu.init();myMenu.setVisible(true);public void itemStateChanged(ItemEvent e)text.setText(“状态改变状态改变”);public void actionPerformed(ActionEvent e)text.setText

63、(e.getActionCommand();if(e.getActionCommand()=“退出退出”)System.exit(0);60对话框njava.awt.Dialog类n有边框和标题,可独立使用的容器nDialog(Frame f)nDialog(Frame f,boolean b)nDialog(Frame f,String s)nDialog(Frame f,String s,boolean b)nsetTitle()/getTitle()nsetModal()/setSize()/setVisible()n操作步骤n创建一个窗口类n创建一个对话框类n设置对话框大小n创建主类,

64、启动和初始化窗口和对话框类61对话框njava.awt.FileDialog类nDialog类的子类n构造方法nFileDialog(Frame f)nFileDialog(Frame f,String s)nFileDialog(Frame f,String s,int m)n常用方法ngetDirectory()nsetDirectory()nsetFile()62关于Swing的设计63界面设计n设计流程1.顶层容器nJFrame对象主窗口nJDialog对象二级窗口nJApplet对象applet程序在浏览器窗口中的显示区域2.内容面板nJFrame f=new JFrame(“Swi

65、ng1);JLabel label=new JLabel(Hello!);f.getContentPane().add(label);n面板的嵌套(面板包含面板)n设计布局3.在内容面板中添加组件64界面设计Frame内容面板内容面板内容面板TextFieldSliderComboxTextFieldSliderCombox65界面设计66应用实例n应用实例菜单的构造JMenuBar menuBar;JMenu menu,submenu;JMenuItem menuItem;JCheckBoxMenuItem cbMenuItem;JRadioButtonMenuItem rbMenuItem

66、;menuBar=new JMenuBar();menu=new JMenu(A Menu);menuBar.add(menu);menuItem=new JMenuItem(A text-only menu item);menu.add(menuItem);menuItem=new JMenuItem(Both text and icon,new ImageIcon(images/middle.gif);menu.add(menuItem);menuItem=new JMenuItem(new ImageIcon(images/middle.gif);menu.add(menuItem);menu.addSeparator();ButtonGroup group=new ButtonGroup();rbMenuItem=new JRadioButtonMenuItem(A radio button menu item);rbMenuItem.setSelected(true);group.add(rbMenuItem);menu.add(rbMenuItem);rbMenuItem=

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!