Java語言程序設(shè)計(jì)(下)課件_第1頁
Java語言程序設(shè)計(jì)(下)課件_第2頁
Java語言程序設(shè)計(jì)(下)課件_第3頁
Java語言程序設(shè)計(jì)(下)課件_第4頁
Java語言程序設(shè)計(jì)(下)課件_第5頁
已閱讀5頁,還剩271頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Java語言程序設(shè)計(jì)馬 皓1第1頁,共276頁。第四章 Applet及其應(yīng)用Applet概述Applet類Applet程序與HTML文件Applet的應(yīng)用2第2頁,共276頁。Applet概述Java程序的兩種基本形式Java Application(應(yīng)用程序),可獨(dú)立運(yùn)行Java Applet(小程序),嵌入在瀏覽器中運(yùn)行介紹Applet的結(jié)構(gòu)特點(diǎn)、實(shí)現(xiàn)方法、工作原理掌握Applet的編輯、編譯和運(yùn)行方法3第3頁,共276頁。一個Applet小程序的例子import java.applet.Applet;import java.awt.Graphics;public class Exam4_

2、1 extends Applet String str;public void init() str = “Here is an Applet”;public void paint(Graphics g) g.drawString(str, 100, 100);4第4頁,共276頁。HTML文件超文本標(biāo)記語言(HTML)WWW瀏覽器Applet小程序嵌入在/寫入在HTML文件中從WWW服務(wù)器下載到本地WWW瀏覽器由WWW瀏覽器中的Java解釋器來運(yùn)行5第5頁,共276頁。HTML文件實(shí)現(xiàn)過程Applet小程序編寫,編譯,得到字節(jié)碼文件javac Exam4_1.java嵌入到HTML文件中,保

3、存為Exam4_1.html6第6頁,共276頁。HTML文件瀏覽器打開Exam4_1.html文件7第7頁,共276頁。Applet的特點(diǎn)通常作為Applet類的子類,格式如下:public class 類名 extends Applet 嵌入在HTML文件中,利用WWW瀏覽器或Appletviewer來運(yùn)行利用了WWW瀏覽器或Appletviewer所提供的圖形用戶界面功能8第8頁,共276頁。Applet的工作原理Applet源程序字節(jié)碼文件嵌入到HTML文件WWW瀏覽器打開 該HTML文件9第9頁,共276頁。第四章 Applet及其應(yīng)用Applet概述Applet類Applet程序與

4、HTML文件Applet的應(yīng)用10第10頁,共276頁。Applet類的繼承關(guān)系java.lang.Objectjava.awt.Componentjava.awt.Containerjava.awt.Paneljava.applet.Applet默認(rèn)情況下,Applet類使用FlowLayout布局管理器11第11頁,共276頁。Applet類的主要方法init()方法完成初始化操作在Applet程序第一次加載時調(diào)用,僅執(zhí)行一次start()方法啟動Applet主線程運(yùn)行重啟時也被調(diào)用(reload或返回)paint()方法將結(jié)果輸出/繪制到界面上被自動調(diào)用(啟動后/窗口改變/repaint

5、()調(diào)用)12第12頁,共276頁。Applet類的主要方法stop()方法暫停Applet程序執(zhí)行destroy()方法終止Applet程序執(zhí)行,釋放所占用的資源13第13頁,共276頁。Applet類的主要方法import java.applet.Applet;import java.awt.*;public class Exam extends Applet public void init( ) /初始化Applet程序public void start( ) /啟動Applet線程public void paint(Graphics g) /繪制輸出顯示信息public void s

6、top( ) /暫停線程public void destroy( ) /釋放系統(tǒng)資源,結(jié)束線程14第14頁,共276頁。第四章 Applet及其應(yīng)用Applet概述Applet類Applet程序與HTML文件Applet的應(yīng)用15第15頁,共276頁。HTML文件超文本標(biāo)記語言(HTML)和Html文件開始和結(jié)束的標(biāo)記和WWW瀏覽器窗口標(biāo)題內(nèi)容的標(biāo)記和Html文件在瀏覽器窗口中顯示內(nèi)容的標(biāo)記和嵌入到Html文件中Applet程序的標(biāo)記16第16頁,共276頁。Applet程序的標(biāo)記參數(shù)17第17頁,共276頁。Applet小程序import java.applet.Applet;import

7、java.awt.*;public class Exam4_3 extends Applet String str;int x, y, h;Font fnt;public void init() str = getParameter(“string”);h = Integer.parseInt(getParameter(“size”);x = Integer.parseInt(getParameter(“x1”);y = Integer.parseInt(getParameter(“y1”);fnt = new Font(“TimesRoman”, Font.BOLD, h);public v

8、oid paint(Graphics g) g.setColor(Color.red);g.setFont(fnt);g.drawString(str, x, y);18第18頁,共276頁。Applet小程序19第19頁,共276頁。第四章 Applet及其應(yīng)用Applet概述Applet類Applet程序與HTML文件Applet的應(yīng)用20第20頁,共276頁。繪制圖形設(shè)置字體java.awt.Font類設(shè)置文本的字體(包括字型和字號)構(gòu)造方法public Font(String name, int style int size)設(shè)置顏色java.awt.Color類控制顏色,Color類

9、已包含13個顏色常量構(gòu)造方法public Color(int r, int g, int b)public Color(float r1, float g1, float b1)21第21頁,共276頁。繪制圖形繪制文本繪制字符串public void drawString(String s, int x, int y)繪制字符public void drawString(char c, int offset, int number int x, int y)繪制字節(jié)public void drawString(byte b, int offset, int number int x, int

10、 y)22第22頁,共276頁。Applet小程序import java.applet.Applet;import java.awt.*;public class Exam4_4 extends Applet public void paint(Graphics g) Font font1, font2, font3;font1 = new Font(“Serif”, Font.BOLD, 20);font2 = new Font(“Monospaced”, Font.BOLD+Font.ITALIC, 24);font3 = new Font(“SansSerif”, Font.PLAIN,

11、 16);g.setFont(font1);g.drawString(“Serif 20 point BOLD”, 30, 20);g.setFont(font2);g.drawString(“Monospaced 24 point BOLD + ITALIC”, 30, 80);g.setFont(font3);g.drawString(“SansSerif 16 point PLAIN”, 30, 50);int size = font2.getSize();int style = font1.getStyle();String name = font2.getName();String

12、str = name + “ “ + style + “ “ + size;g.drawString(str, 30, 110);23第23頁,共276頁。Applet小程序24第24頁,共276頁。Applet小程序import java.applet.Applet;import java.awt.*;public class Exam4_6 extends Applet Font font1 = new Font(“TimesRoman”, Font.ITALIC, 25);Font font2 = new Font(“Braggadcoio”, Font.BOLD, 40);public

13、 void paint(Graphics g) String str = “I love Beijing!”;Color mycolor = new Color(192, 64, 200);g.setFont(font1);g.setColor(mycolor);g.drawString(str, 30, 40);Color darker = mycolor.darker();g.setColor(darker);g.drawString(str, 50, 80);Color brighter = mycolor.brighter();g.setColor(brighter);g.drawSt

14、ring(str, 70, 120);g.setFont(font2);g.setColor(Color.red);g.drawString(str, 30, 170);g.setColor(Color.white);g.drawString(str, 32, 169);25第25頁,共276頁。Applet小程序26第26頁,共276頁。繪制圖形繪制幾何圖形畫直線void drawLine(int x1, int y1, int x2, int y2)畫矩形void drawRect(int x, int y, int width, int height)void fillRect(int

15、x, int y, int width, int height)void clearRect(int x, int y, int width, int height)void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)void draw3DRect(int x, int y, int width, int height, boolean b)void fill3DRect(int x, int y, int width, int height, boolean b)27第27頁,

16、共276頁。繪制圖形繪制幾何圖形畫圓弧和橢圓void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)void drawOval(int x, int y, int width, int height)void fillOval(int x, int y, int width, int height)28第28頁,共276頁。Applet小

17、程序import java.applet.Applet;import java.awt.*;public class Exam4_8 extends Applet public void paint(Graphics g) int x0 =10, y0=20, X=150, Y=80, L, c;int arc = 0, N=10;double xy=1.0*(X-Y)/N/2;g.setColor(Color.red);g.fillRect(x0, y0, X, X);for(int i=0; i =N; i+) L=(int)(X-2*i*xy); arc=Y*i/N; c=i*240/N

18、; g.setColor(new Color(c, c, c); g.drawRoundRect(int)(x0+i*xy), (int)(y0+i*xy), L, L, arc, arc);g.setColor(Color.blue);g.draw3DRect(200, y0, X, X, true);g.setColor(Color.green);g.fill3DRect(400, y0, Y, Y, false);29第29頁,共276頁。Applet小程序30第30頁,共276頁。繪制圖形繪制幾何圖形畫多邊形public void drawPolygon(int xPoints, in

19、t yPoints, int Points)public void fillPolygon(int xPoints, int yPoints, int Points)public void drawPolygon(Polygon p)public void fillPolygon(Polygon p)Polygon類構(gòu)造方法Polygon()Polygon(int xPoints, int yPoints, int numberOfPoints)31第31頁,共276頁。演示圖像定義圖像對象java.awt.Image類圖像高度和寬度int getHeight(ImageObserver ob

20、server)int getWidth(ImageObserver observer)獲取圖像信息方法Image getImage(URL url, String name)顯示圖像的操作drawImage(Image img, int x, int y, ImageObserver observer)drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)32第32頁,共276頁。Applet小程序import java.applet.Applet;import java.awt.*;p

21、ublic class Exam4_13 extends Applet public void paint(Graphics g) Image pic;pic = getImage(getDocumentBase(), “edonkey.jpg”);int x0 = 10, y0 = 30;int w = pic.getWidth(this);int h = pic.getHeight(this);g.drawImage(pic, x0, y0, w/8, h/8, this);g.drawImage(pic, x0+150, y0, w/12, h/12, this);g.drawImage

22、(pic, x0+150, y0+100, w/15, h/15, this);g.drawImage(pic, x0+250, y0+30, (int)(w*0.1), (int)(h*0.2), this);33第33頁,共276頁。Applet小程序34第34頁,共276頁。演示圖像動畫創(chuàng)建Image類的對象數(shù)組drawImage()Thread.sleep()方法repaint()播放聲音public void play(URL url)public AudioClip getAudio(URL url)play()方法/loop()方法/stop()方法35第35頁,共276頁。第四

23、章 結(jié)束!36第36頁,共276頁。概述事件處理基本控制組件布局設(shè)計(jì)常用容器組件第五章 圖形用戶界面設(shè)計(jì)37第37頁,共276頁。概述用戶界面(User Interface)用戶與計(jì)算機(jī)系統(tǒng)(各種程序)交互的接口38第38頁,共276頁。GraphicalUser InterfaceNatural User Interface1990GUIMultiple WindowsMenus1995InternetHyperlinksSearch EnginesDigital DecadeXMLWeb ServicesSmart devicesNatural LanguageMultimodal (sp

24、eech, ink)Personal AssistantCommand line1985PCUser Interface Evolution- Kai Fu Lee in 200339第39頁,共276頁。概述Java GUI的發(fā)展AWT (Java 1.0)AWT (Abstract Window Toolkit): 抽象窗口工具包概念設(shè)計(jì)實(shí)現(xiàn) (about 1 month)字體設(shè)計(jì)(四種), 界面顯示(二流水準(zhǔn))Swing (Lightweight Components, Java 1.1)Swing was the code name of the project that develo

25、ped the new componentsSwing API (附加包, Add-on package)JFC (Java 2)JFC (Java Foundation Classes): Java基礎(chǔ)類JFC encompass a group of features to help people build graphical user interfaces (GUIs). JFC 是指包含在 Java 2 平臺內(nèi)的一整套圖形和用戶界面技術(shù)JFC was first announced at the 1997 JavaOne developer conference 40第40頁,共27

26、6頁。概述JFC (Java Foundation Classes)AWT (Abstract Window Toolkit)一些用戶界面組件 (Component)事件響應(yīng)模型 (Event-handling model)布局管理器 (Layout manager)繪圖和圖形操作類, 如Shape、Font、Color類等Swing Components (Swing組件, JFC的核心)a set of GUI components with a pluggable look and feel (包括已有的AWT組件(Button、Scrollbar、Label等)和更高層的組件 (如tr

27、ee view、list box、tabbed panes等)The pluggable look and feel lets you design a single set of GUI components that can automatically have the look and feel of any OS platform (Microsoft Windows, Solaris, Macintosh).基于Java 1.1 Lightweight UI Framework41第41頁,共276頁。概述JFC (Java Foundation Classes)Java 2D (a

28、dvanced 2D graphics and imaging)Graphics?Imaging? Print Service打印文檔、圖形、圖像設(shè)定打印屬性和頁面屬性發(fā)現(xiàn)打印機(jī) (IPP, Internet Printing Protocol)42第42頁,共276頁。概述JFC (Java Foundation Classes)Input Method Frameworktext editing components to communicate with input methods and implement a well-integrated text input user inter

29、face用Java語言開發(fā)輸入法Accessibility: 輔助功能,幫助傷殘人士screen readers, speech recognition systems, refreshable braille displaysDrag & DropDrag and Drop enables data transfer both across Java programming language and native applications, between Java programming language applications, and within a single Java pro

30、gramming language application. 43第43頁,共276頁。圖形用戶界面的構(gòu)成什么是組件?構(gòu)成圖形用戶界面的元素,拿來即用用圖形表示(能在屏幕上顯示,能和用戶進(jìn)行交互)Button、Checkbox、Scrollbar、Choice、Frame44第44頁,共276頁。圖形用戶界面的構(gòu)成一些特定的Java類java.awt包javax.swing包容器組件(Container): 可包含其他組件頂層容器: Applet, Dialog, Frame, Window一般用途容器: Panel, ScrollPane特定用途容器: InternalFrame非容器組件:

31、 必須要包含在容器中Button, Checkbox, Scrollbar, Choice, Canvas45第45頁,共276頁。圖形用戶界面的構(gòu)成AWT組件 java.awt包ComponentButton, Canvas, Checkbox, Choice, Label, List, ScrollbarTextComponentTextAreaTextFieldContainerPanelWindowScrollPaneDialogFrameMenuComponentMenuBarMenuItem46第46頁,共276頁。圖形用戶界面的構(gòu)成Swing組件 javax.swing包java

32、.awt.Component |-java.awt.Container |-java.awt.Window |-java.awt.Frame |-javax.swing.JFramejava.awt.Component |-java.awt.Container |-javax.swing.JComponent|-JComboBox, JFileChooser, JInternalFrame JLabel, JList, JMenuBar, JOptionPane, JPanel JPopupMenu, JProgressBar, JScrollBar JScrollPane, JSeparat

33、or, JSlider, JSpinner JSplitPane, JTabbedPane, JTable JTextComponent, JToolBar, JTree等47第47頁,共276頁。圖形用戶界面的實(shí)現(xiàn)選取組件設(shè)計(jì)布局響應(yīng)事件應(yīng)用原則Swing比AWT提供更全面、更豐富的圖形界面設(shè)計(jì)功能Java 2平臺支持AWT組件,但鼓勵用Swing組件主要講述AWT和Swing的圖形界面設(shè)計(jì)48第48頁,共276頁。圖形用戶界面的實(shí)現(xiàn)簡單實(shí)例import javax.swing.*; import java.awt.event.*; public class HelloWorldSwing

34、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, 200); f.setVisible(true); import java.awt.*; impor

35、t 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.setSize(200, 200); f.setVisible(true); 4

36、9第49頁,共276頁。概述事件處理基本控制組件布局設(shè)計(jì)常用容器組件第五章 圖形用戶界面設(shè)計(jì)50第50頁,共276頁。事件處理界面設(shè)計(jì) (靜態(tài))界面動起來 !通過事件觸發(fā)對象的響應(yīng)機(jī)制事件? 鼠標(biāo)移動、鼠標(biāo)點(diǎn)擊、鍵盤鍵入等事件處理機(jī)制事件源事件對象事件監(jiān)聽者如何實(shí)現(xiàn)實(shí)現(xiàn)(implements)事件監(jiān)聽接口(interface)產(chǎn)生一個監(jiān)聽器對象(Listener)監(jiān)聽誰? 將該監(jiān)聽器對象注冊到組件對象中編寫事件響應(yīng)方法51第51頁,共276頁。事件處理import javax.swing.*;import java.awt.*;import java.awt.event.*;public cl

37、ass 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.event.Ac

38、tionListener (interface)public void actionPerformed(ActionEvent e)javax.swing.JButton (class)public void addActionListener(ActionListener l)52第52頁,共276頁。事件處理事件分類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 Actio

39、nListener 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 lis

40、t selection changes ListSelectionListener 53第53頁,共276頁。事件處理事件分類interface java.awt.event.ActionListenerpublic void actionPerformed(ActionEvent e)interface java.awt.event.WindowListenerpublic void windowOpened(WindowEvent e)public void windowClosing(WindowEvent e)public void windowClosed(WindowEvent e

41、)public void windowIconified(WindowEvent e)public void windowDeiconified(WindowEvent e)public void windowActivated(WindowEvent e)public void windowDeactivated(WindowEvent e)54第54頁,共276頁。事件處理事件分類interface java.awt.event.MouseListenerpublic void mouseClicked(MouseEvent e)public void mousePressed(Mouse

42、Event e)public void mouseReleased(MouseEvent e)public void mouseEntered(MouseEvent e)public void mouseExited(MouseEvent e)interface java.awt.event.MouseMotionListenerpublic void mouseDragged(MouseEvent e)Invoked when a mouse button is pressed on a component and then draggedpublic void mouseMoved(Mou

43、seEvent e)Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed55第55頁,共276頁。事件處理鼠標(biāo)事件public class MouseEventDemo . implements MouseListener . /Register for mouse events on blankArea(TextArea) and applet blankArea.addMouseListener(this); public void mousePressed

44、(MouseEvent e) saySomething(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) s

45、aySomething(Mouse exited, e); public 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

46、); 56第56頁,共276頁。事件處理多個監(jiān)聽器(Listener)多個組件public class MultiListener . implements ActionListener . button1.addActionListener(this); button2.addActionListener(this); button2.addActionListener(new Eavesdropper(bottomTextArea); public void actionPerformed(ActionEvent e) topTextArea.append(e.getActionComma

47、nd() + newline); class Eavesdropper implements ActionListener . public void actionPerformed(ActionEvent e) myTextArea.append(e.getActionCommand() + newline); 57第57頁,共276頁。第五章 圖形用戶界面設(shè)計(jì)概述事件處理基本控制組件布局設(shè)計(jì)常用容器組件58第58頁,共276頁。AWT組件 (java.awt.*)Component Button Canvas ChoiceCheckBoxLabelListTextComponentScro

48、llbarTextFieldTextArea ContainerScrollPaneFrameFileDialogPanelWindowDialogApplet59第59頁,共276頁。基本控制組件使用步驟:創(chuàng)建基本控制組件類的對象,指定對象屬性;將組件對象加入到制定容器的適當(dāng)位置(布局設(shè)計(jì));創(chuàng)建事件對象的監(jiān)聽者。Swing組件(javax.swing.*)60第60頁,共276頁。按鈕和標(biāo)簽按鈕(Button)創(chuàng)建按鈕public Button()public Button(String label)常用方法public String getLabel()public void setLa

49、bel(String label)public void setActionCommand(String s)public String getActionCommand(String s)事件響應(yīng)java.awt.event.ActionListener(接口)void actionPerformed(ActionEvent e)61第61頁,共276頁。按鈕和標(biāo)簽標(biāo)簽(Label)創(chuàng)建標(biāo)簽public Label()public Label(String s)public Label(String s, int alignment)常用方法public String getText()pu

50、blic void setText(String s)public void setAlignment(int alignment)事件響應(yīng)不引發(fā)事件62第62頁,共276頁。使用標(biāo)簽的例子import java.awt.*;import 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(Co

51、lor.red);lab2.setBackground(Color.green);text1 = new TextField(10);text2 = new TextField(10);add(lab1); add(text1);add(lab2);add(text2);63第63頁,共276頁。使用標(biāo)簽的例子64第64頁,共276頁。文本框和文本區(qū)文本框(TextField)TextComponent類的子類創(chuàng)建文本框public TextField()public TextField(int size)public TextField(String s)public TextField(S

52、tring s, int size)常用方法public void setText(String s)public String getText()public void setEchochar(char c)public void setEditable(boolean b)事件響應(yīng)java.awt.event.TextListener(接口)java.awt.event.ActionListener(接口)65第65頁,共276頁。文本框和文本區(qū)文本區(qū)(TextArea)TextComponent類的子類創(chuàng)建文本區(qū)public TextArea()public TextArea(Strin

53、g s)public TextArea(int rows, int columns)public TextArea(String s, int rows, int columns)public TextArea(String s, int rows, int columns, int scrollbars)SCROLLBARS_BOTH, SCROLLBARS_NONESCROLLBARS_VERTICAL_ONLYSCROLLBARS_HORIZONTAL_ONLY常用方法public void append(String s)public void insert(String s, int

54、 index)pubilc void replaceRange(String s, int start, int end)事件響應(yīng)java.awt.event.TextListener(接口)void textValueChanged(TextEvent e)66第66頁,共276頁。使用文本框的例子import java.awt.*;import java.awt.event.*;import java.applet.*;public class Exam5_4 extends Applet implements ActionListenerLabel lab1, lab2, lab3;Te

55、xtField text1, text2, text3;String str; int i; float f;public void init() lab1 = new Label(“輸入整形數(shù): ”); add(lab1);text1 = new TextField(“0”, 30);text1.addActionListener(this); add(text1);lab2 = new Label(“輸入浮點(diǎn)數(shù): ”); add(lab2);text2 = new TextField(“0.0”, 30);text2.addActionListener(this); add(text2);

56、lab3 = new Label(“輸入字符串: ”); add(lab3);text3 = new TextField(“0.0”, 30);text3.addActionListener(this); add(text3);67第67頁,共276頁。使用文本框的例子public void actionPerformed(ActionEvent e) i = Integer.parseInt(text1.getText();f = (Float.valueOf(text2.getText().floatValue();str = text3.getText();repaint();publi

57、c void paint(Graphics g) g.drawString(“整形數(shù)=” + i, 20, 120);g.drawString(“浮點(diǎn)數(shù)=” + f, 20, 150);g.drawString(“字符串=” + str, 20, 180);68第68頁,共276頁。單復(fù)選框和列表復(fù)選框(Checkbox)創(chuàng)建復(fù)選框public Checkbox()public Checkbox(String s)public TextField(String s, boolean state)常用方法public boolean getState()public void setState(

58、boolean b)public void setLabel(String s)public String getLabel()事件響應(yīng)java.awt.event.ItemListener(接口)void itemStateChanged(ItemEvent e)69第69頁,共276頁。單復(fù)選框和列表單選按鈕組(CheckboxGroup)創(chuàng)建單選按鈕組public Checkbox(String label, boolean state, CheckboxGroup group)public Checkbox(String label, CheckboxGroup group, bool

59、ean state)常用方法與復(fù)選框相同事件響應(yīng)與復(fù)選框相同70第70頁,共276頁。單復(fù)選框和列表列表(List)創(chuàng)建列表public List()public List(int n)public List(int n, boolean b)常用方法public void add(String s)public void add(String s, int n)public void remove(int n)public void removeAll()public int getSelectedIndex()public String getSelectedItem()事件響應(yīng)java.

60、awt.event.ItemListener(接口)java.awt.event.ActionListener(接口)71第71頁,共276頁。下拉列表和滾動條下拉列表(Choice)創(chuàng)建下拉列表public Choice()常用方法public int getSelectedIndex()public String getSelectedItem()public void select(int index)public void select(String item)public void add(String s)public void add(String s, int index)pu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論