freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

[計算機軟件及應(yīng)用]jaa第9章-資料下載頁

2025-01-21 23:08本頁面
  

【正文】 void setSelection Foreground(Color c) 設(shè)置單元格的前景顏色 int getVisibleRowCount(?) 得到可見的列表選項值 void setVisibleRowCount(int num) 設(shè)置可見的列表選項 Java語言程序設(shè)計 76 ListSelectionEvent事件 JList組件的事件處理一般可分為兩種:一種是當(dāng)用戶單擊列表框中的某一個選項并選中它時,將產(chǎn)生 ListSelectionEvent類的選擇事件,此事件是 Swing的事件;另一種是當(dāng)用戶雙擊列表框中的某個選項時,則產(chǎn)生 MouseEvent類的動作事件。 JList類通過 locatToindex( )方法來得知是單擊還是雙擊。 若希望實現(xiàn) JList的 ListSelectionEvent事件,首先必須聲明實現(xiàn)監(jiān)聽者對象的類接口 ListSelectionListener,并通過 JList類的addListSelectionListener( )方法注冊文本框的監(jiān)聽者對象,再在ListSelectionListener接口的 valueChanged (ListSelectionEvent e)方法體中寫入有關(guān)代碼,就可以響應(yīng) ListSelectionEvent事件了。下面通過示例程序來加以說明。 Java語言程序設(shè)計 77 【 示例程序 】 設(shè)置一個 JLabel組件和 JList組件,點擊列表框中的選項,將所選項的值作為 JLabel組件的文本輸出。 import .*。 import .*。 import .*。 import .*。 public class c9_4 extends JApplet implements ListSelectionListener { JList lis=null。 JLabel lb=null。 Java語言程序設(shè)計 78 String[ ] s={小學(xué) ,初中 ,高中 ,大學(xué) ,研究生 }。 public void init( ) { Container cp=getContentPane( )。 (new BorderLayout( ))。 lb=new JLabel( )。 lis=new JList(s)。 (3)。 //設(shè)置列表框的可見選項行數(shù),選項超過則出現(xiàn)滾動條 ((請選擇))。//設(shè)置列表框的邊框文本 Java語言程序設(shè)計 79 (this)。 //注冊 lis給監(jiān)聽者對象 (lb,)。 //將 lis對象放入滾動容器,再將此容器加載到界面上。 (new JScrollPane(lis),)。 } public void valueChanged(ListSelectionEvent e) { int m=0。 String str=選取的是: 。 //取得所有選項的下標(biāo)值給 index數(shù)組 Java語言程序設(shè)計 80 int[ ] index = ( )。 for(int i=0。i。i++) { //根據(jù)取得的下標(biāo)值,找到相應(yīng)的數(shù)組元素 m=index[i]。 str=str+s[m]+ 。 } (str)。//輸出選中項的值 } } Java語言程序設(shè)計 81 上述程序中的語句: (this)。 表示把 lis注冊給 ListSelectionEvent的監(jiān)聽者ListSelectionListener。當(dāng)用戶單擊某個選項時,系統(tǒng)會自動引用 ListSelectionListener的 valueChanged( )方法來處理選項的改變。 程序 c9_4的運行結(jié)果見圖 。 Java語言程序設(shè)計 82 圖 程序 c9_4的運行結(jié)果 Java語言程序設(shè)計 83 JTextField與 JTextArea組件 JTextField組件的構(gòu)造方法及成員方法 JtextField被稱為文本框。它定義了一個單行條形文本區(qū),可以輸出任何基于文本的信息,也可以接受用戶的輸入。表 列出了 JTextField類的構(gòu)造方法和成員方法。 Java語言程序設(shè)計 84 表 JTextField類構(gòu)造方法和成員方法 方 法 JTextField(?) JTextField(int n) JTextField(String s) JTextField(String s,int n) JTextField(Document doc,String s,int n) int getColumns(?) void setColumns(int Columns) void addActionListener(ActionListener e) void setFont(Font f) void setHorizontalAlignment(int alig) void setActionCommand(String ) Java語言程序設(shè)計 85 功 能 說 明 創(chuàng)建一個 JTextField對象 創(chuàng)建一個列寬為 n的空 JTextField對象 創(chuàng)建一個 JTextField對象 , 并顯示字符串 s 創(chuàng)建一個 JTextField對象 ,并以指定的字寬 n顯示字符串 s 使用指定的文件存儲模式創(chuàng)建一個 JTextField對象 ,并以指定的字寬 n顯示字符串 s 獲取此對象的列數(shù) 設(shè)置此對象的列數(shù) 添加指定的動作事件監(jiān)聽程序 設(shè)置字體 設(shè)置文本的水平對齊方式 (LEFT、 CENTER、 RIGHT) 設(shè)置動作事件使用的命令字符串 Java語言程序設(shè)計 86 JTextArea組件的構(gòu)造方法及成員方法 JTextArea被稱為文本域。它與文本框的主要區(qū)別是:文本框只能輸入 /輸出一行文本,而文本域可以輸入 /輸出多行文本。表 JTextArea類的構(gòu)造方法和成員方法。 Java語言程序設(shè)計 87 表 JTextArea類構(gòu)造方法和成員方法 方 法 功 能 說 明 構(gòu)造方法 JTextArea (?) 創(chuàng)建一個 JTextArea對象 JTextArea (int n,int m) 創(chuàng)建一個具有 n行 m列的空 JTextArea對象 JTextArea(String s) 創(chuàng)建一個 JTextArea對象 , 并顯示字符串 s JTextArea(String s,int n,int m) 創(chuàng)建一個 JTextArea對象并以指定的行數(shù) n和列數(shù) m顯示字符串聯(lián) s JTextArea(String s,int n,int m,int k) 創(chuàng)建一個 JTextArea對象 , 并以指定的行數(shù) n、 列數(shù) m和滾動條的方向顯示字符串 s JTextArea(Document doc) 使用指定的文件存儲模式創(chuàng)建一個JTextArea對象 JTextArea(Document doc,String s,int n) 使用指定的文件存儲模式創(chuàng)建一個JTextArea對象 , 并以指定的字寬 n顯示字符串 s Java語言程序設(shè)計 88 成員方法 void setFont(Font f) 設(shè)置字體 void insert(String str,int pos) 在指定的位置插入指定的文本 void append(String str) 將指定的文本添加到末尾 void replaceRange(String str,int start,int end) 將指定范圍的文本用指定的新文本替換 public int getRows(?) 返回此對象的行數(shù) public void setRows(int rows) 設(shè)置此對象的行數(shù) public int getColumns(?) 獲取此對象的列數(shù) public void setColumns(int Columns) 設(shè)置此對象的列數(shù) Java語言程序設(shè)計 89 事件處理 JTextField類只引發(fā) ActionEvent事件,當(dāng)用戶在文本框中按回車鍵時引發(fā)。 JTextArea的事件響應(yīng)由 JTextComponent類決定。 JTextComponent類可以引發(fā)兩種事件: DocumentEvent事件與 UndoableEditEvent事件。當(dāng)用戶修改了文本區(qū)域中的文本,如做文本的增、刪、改等操作時, TextComponent類將引發(fā) DocumentEvent事件;當(dāng)用戶在文本區(qū)域上撤消所做的增、刪、改時, TextComponent類將引發(fā) UndoableEditEvent事件。 Java語言程序設(shè)計 90 (1) 實現(xiàn)文本框的 ActionEvent事件。當(dāng)監(jiān)聽者對象的類聲明實現(xiàn)了 ActionListener接口,并且通過(this)語句注冊文本框的監(jiān)聽者對象后,監(jiān)聽程序內(nèi)部動作事件的 actionPerformed(ActionEvent e) 方法就可以響應(yīng)動作事件了。 Java語言程序設(shè)計 91 (2) 實現(xiàn)文本區(qū)域的 DocumentEvent事件。當(dāng)監(jiān)聽者對象的類聲明實現(xiàn)了 DocumentEditListener接口,并且通過(this)語句注冊文本區(qū)域的監(jiān)聽者對象后,監(jiān)聽程序內(nèi)部的 DocumentListener接口的下列三個方法之一就可以響應(yīng) DocumentEvent事件了。 changedUpdate(DocumentEvent e)。 //修改文本操作 inset Update(DocumentEvent e)。 //增加文本操作 remove Update(DocumentEvent e)。 //刪除文本操作 Java語言程序設(shè)計 92 (3) 實現(xiàn)文本區(qū)域的 UndoableEditEvent事件。當(dāng)監(jiān)聽者對象的類聲明實現(xiàn)了 UndoableEditListener接口,并且通過(this)語句注冊文本區(qū)域的監(jiān)聽者對象后,監(jiān)聽程序內(nèi)部的 UndoableEditListener接口的UndoableEditHappened(UndoableEditEvent e) 方法就可以響應(yīng) UndoableEditEvent事件了。 Java語言程序設(shè)計 93 應(yīng)用舉例 【 示例程序 】 文本框和文本域組件的使用。 import .*。 import .*。 import .*。 public class c9_5 extends JApplet implements ActionListener { Container ctp=getContentPane( )。 ImageIcon icon1=new ImageIcon(), icon2=new ImageIcon()。 Java語言程序設(shè)計 94 JLabel lb1=new JLabel(輸入文字后按回車 :,icon1,), lb2=new JLabel(輸出結(jié)果 :,icon2,)。 JTextField tf1=new JTextField(10)。 //創(chuàng)建文本框?qū)ο? JTextArea tf2=new JTextArea(5,10)。 //創(chuàng)建文本區(qū)域?qū)ο? public void init( ) { (new FlowLayout( ))。 (lb1)。 (tf1)。 (lb2)。 (tf2)。 (this)。 } Java語言程序設(shè)計 95 public void actionPerformed(ActionEvent e) { String str。 str=( )。 //獲得文本框的文本給 str(此方法是 JTextComponent類的方法 ) // (str)。 (str+\n)。 //將 str添加到文本區(qū)域中 (append方法是 JTextArea類的方法 ) } } Java語言程序設(shè)計 96 圖 程序 c9_5的運行結(jié)果
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1