




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、代碼實(shí)現(xiàn)SQL Server數(shù)據(jù)庫表中數(shù)據(jù)輸出到圖形用戶界面這個(gè)可以實(shí)現(xiàn)。JTable的有一個(gè)方法是getTableModel(.返回提供此 JTable 所顯示數(shù)據(jù)的 TableModel. TableModel是一個(gè)接口,實(shí)際上返回的是DefaultTableModel類,它實(shí)現(xiàn)了TableModel接口。這個(gè)類中有一個(gè)方法是void addRow(Object rowData。它就是將一行插入到JTable中。 不過JTable的setValueAt方法應(yīng)該就可以實(shí)現(xiàn)。比如你需要插入100行數(shù)據(jù),可以在線程的run方法中寫一個(gè)循環(huán),在循環(huán)中寫兩行代碼,一行是setValueAt,一行是刷
2、新JTable,然后再讓線程睡眠,這樣一行一行的顯示的效果就可以出來了! 可以用進(jìn)度條來打發(fā)等待的時(shí)間,就像打開netbeans的那個(gè)進(jìn)度條一樣,這個(gè)可以用JProgressBar類。import javax.swing.*; import java.awt.event.*; import java.awt.*; import javax.swing.table.*; public class Test extends JFrame implements ActionListener private JButton button1; private JButton button2; priva
3、te JButton button3; private DefaultTableModel model; private JTable table; private JProgressBar bar; private JScrollPane scrollpane; private JPanel panel; public Test( button1=new JButton("演示1" button2=new JButton("演示2" button3=new JButton("清空" panel=new JPanel(; bar=ne
4、w JProgressBar(0,100; String colnames="數(shù)據(jù)一","數(shù)據(jù)二" model=new DefaultTableModel(colnames,100; table=new JTable(model; scrollpane=new JScrollPane(table; panel.setLayout(new FlowLayout(; button1.addActionListener(this; button2.addActionListener(this; button3.addActionListener(this; p
5、anel.add(button1; panel.add(button2; panel.add(button3; panel.add(bar; this.setLayout(new GridLayout(2,1; this.setSize(500,600; this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE; this.add(scrollpane; this.add(panel; public void actionPerformed(ActionEvent e String command=e.getActionCommand(; if(co
6、mmand.equals("演示1" ShowModel show=new ShowModel(true; Thread thread=new Thread(show; thread.start(; else if(command.equals("演示2" ShowModel show=new ShowModel(false; Thread thread=new Thread(show; thread.start(; else String colnames="數(shù)據(jù)一","數(shù)據(jù)二" model=new Defaul
7、tTableModel(colnames,100; table.setModel(model; private class ShowModel implements Runnable private boolean type;/當(dāng)type為true時(shí),則說明是“演示1”的線程,false則相反 public ShowModel(boolean type this.type=type; public void run( if(type/這個(gè)就是讓線程睡眠,并且設(shè)置JTable的值 try for(int i=0;i<100;i+ Test.this.table.setValueAt(Str
8、ing.valueOf(i,i,0; Test.this.table.setValueAt(String.valueOf(i,i,1; Thread.sleep(100; catch(Exception e e.printStackTrace(; else/這個(gè)就是進(jìn)度條的演示 try Test.this.table.setVisible(false; for(int i=0;i<100;i+ Test.this.table.setValueAt(String.valueOf(i,i,0; Test.this.table.setValueAt(String.valueOf(i,i,1; Test.this.bar.setValue(i+1; Test.this.bar.setString(String.valueOf(i+1+"%" Thread.sleep(40; if(i=99 Test.this.table.setVisible(true; JOptionPane.showMessageDialog(Test.this,"OK" Test.t
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年刮墨刀項(xiàng)目資金申請(qǐng)報(bào)告代可行性研究報(bào)告
- 2025年度教育科技股權(quán)分配及資源共享協(xié)議模板
- 2025年度事業(yè)單位聘用合同書模板(保密協(xié)議)正式版
- 2025年度保密性產(chǎn)品研發(fā)與生產(chǎn)合作協(xié)議
- 2025年河南中醫(yī)藥大學(xué)單招職業(yè)技能測(cè)試題庫及答案一套
- 2025年農(nóng)村集體土地租賃與使用權(quán)轉(zhuǎn)讓協(xié)議
- 2025年度宅基地使用權(quán)流轉(zhuǎn)備案與監(jiān)管服務(wù)合同
- 二零二五年度電影演員跨界合作合同范本
- 咖啡廳垃圾運(yùn)輸合作協(xié)議
- 2025年度新能源產(chǎn)業(yè)研發(fā)人工費(fèi)合作協(xié)議
- 北師大版(三起)(2024)三年級(jí)上冊(cè)英語Unit 4 Friends單元測(cè)試卷(含答案)
- 八年級(jí)語文下冊(cè) 第三單元 9 桃花源記教學(xué)設(shè)計(jì) 新人教版
- 2024年歐洲電動(dòng)汽車充電站和充電樁市場(chǎng)主要企業(yè)市場(chǎng)占有率及排名
- 天津市部分區(qū)2022-2023學(xué)年七年級(jí)下學(xué)期期中地理試題【帶答案】
- 2024年煙臺(tái)工程職業(yè)技術(shù)學(xué)院單招職業(yè)適應(yīng)性測(cè)試題庫新版
- JBT 7041-2006 液壓齒輪泵標(biāo)準(zhǔn)規(guī)范
- 水滸傳讀書分享(完美版)模板兩篇
- 《配電自動(dòng)化運(yùn)維人員培訓(xùn)考核規(guī)范(征求意見意見稿)》
- 肌肉注射新版本
- 2021年4月自考00808商法試題及答案含解析
- 新人通識(shí)訓(xùn)試卷附有答案
評(píng)論
0/150
提交評(píng)論