![JAVA實現(xiàn)一個登錄窗體功能_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d1.gif)
![JAVA實現(xiàn)一個登錄窗體功能_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d2.gif)
![JAVA實現(xiàn)一個登錄窗體功能_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d3.gif)
![JAVA實現(xiàn)一個登錄窗體功能_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d4.gif)
![JAVA實現(xiàn)一個登錄窗體功能_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d/8b6b8fa8-b35b-4441-bd3e-f884a1132c7d5.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、JAVA實現(xiàn)一個登錄窗體功能該程序顯示了基于Swing的JFrame的一個“登錄”窗口。當(dāng)你輸入正確的用戶ID和密碼,你可以得到確認(rèn),否則你會被驚動由Java標(biāo)準(zhǔn)的消息窗口。在同一時間的容器和在JPanel的FlowLayout GridLayout的使用Swing的JFrame的1. package com.han; 2.3. import java.awt.Container; 4. import java.awt.FlowLayout; 5. import java.awt.GridLayout; 6. import java.awt.event.ActionEvent; 7. impo
2、rt java.awt.event.ActionListener; 8. import java.util.Arrays; 9.10. import javax.swing.*; 11.12. /* 13. * This program shows a "Login" window based on Swing JFrame. 14. * When you input the correct userID and Password, you can obtain a confirmation, 15. * or else you will be alerted by a J
3、AVA standard message window. 16. * <p> 17. * The Swing JFrame used in the same time the GridLayout for the Container and the FlowLayout for the JPanel. 18. * author han 19. * 20. */ 21. public class SwingJFrameLogin 22. /*define all the necessary member variables*/ 23. String s1=null; 24. char
4、 s2=null; 25. JFrame frame=new JFrame(); 26. Container c=frame.getContentPane(); 27. /*the construct function*/ 28. public SwingJFrameLogin() 29. c.setLayout(new GridLayout(3,1,10,10);/the Container uses the GridLayout for 3 JPanels 30. JPanel panel1=new JPanel(new FlowLayout(FlowLayout.CENTER);/eac
5、h JPanel uses the FlowLayout 31. JPanel panel2=new JPanel(new FlowLayout(FlowLayout.CENTER); 32. JPanel panel3=new JPanel(new FlowLayout(); 33. JLabel label1=new JLabel("用戶名:"); 34. final JTextField jt=new JTextField(10); 35. JLabel label2=new JLabel("密碼:"); 36. final JPasswordFi
6、eld jp=new JPasswordField(6); 37. jp.setEchoChar(char) 0);/set the display words as visible. 38. final JButton jb1 = new JButton("提交"); 39. final JButton jb2 = new JButton("重置"); 40. panel1.add(label1); 41. panel1.add(jt); 42. panel2.add(label2); 43. panel2.add(jp); 44. panel3.ad
7、d(jb1); 45. panel3.add(jb2); 46. c.add(panel1); 47. c.add(panel2); 48. c.add(panel3); 49. jb1.addActionListener(new ActionListener() 50. Override 51. public void actionPerformed(ActionEvent e) 52. String s1=jt.getText(); 53. char s2=jp.getPassword(); 54. System.out.println(s1); 55. System.out.printl
8、n(s2); 56. char pw='u','p','s' 57. /*System.out.println(Arrays.equals(s2,pw); 58. System.out.println(s1.equals("han");*/ 59. if (s1.equals("han") && Arrays.equals(s2,pw) 60. JOptionPane.showMessageDialog(frame, 61. "登錄成功 !","Message&
9、quot;,JOptionPane.INFORMATION_MESSAGE); 62. /frame.dispose();(等同于點擊關(guān)閉窗口時執(zhí)行frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );) 63. System.exit(0);/正常退出(等同于點擊關(guān)閉窗口時執(zhí)行frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );) 64. 65. else 66. JOptionPane.showMessageDialog(frame,/it is a JAVA interna
10、l STD message BOX 67. "You had input a wrong userID !","Warning",JOptionPane.WARNING_MESSAGE); 68. 69. Arrays.fill(s2,'0'); /Zero out the possible password, for security. 70. 71. ); 72. jb2.addActionListener(new ActionListener() 73. Override 74. public void actionPerformed(ActionEvent e) /set all the fields empty. 75. jt.setText(""); 76. jp.setText(""); 77. 78. ); 79. frame.pack();/automatically resize all the components to their preferred sizes. 80.
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 晉中山西晉中市太谷區(qū)面向2025屆公費(fèi)師范生招聘教師18人筆試歷年參考題庫附帶答案詳解
- 2025年中國太子佛工藝品市場調(diào)查研究報告
- 2025至2031年中國高壓透鏡行業(yè)投資前景及策略咨詢研究報告
- 2025年藝術(shù)道閘項目可行性研究報告
- 2025年紅外線按摩棒項目可行性研究報告
- 2025年電加熱針織物呢毯預(yù)縮機(jī)項目可行性研究報告
- 成都四川成都天府國際競技訓(xùn)練中心招聘運(yùn)動員4人筆試歷年參考題庫附帶答案詳解
- 2025年曲印項目可行性研究報告
- 2025年揉切粉碎機(jī)項目可行性研究報告
- 2025年安康魚野菜串項目可行性研究報告
- GB/T 2934-2007聯(lián)運(yùn)通用平托盤主要尺寸及公差
- GB/T 13228-2015工業(yè)炸藥爆速測定方法
- CB/T 102-1996錫基合金軸瓦鑄造技術(shù)條件
- 羅森便利店QSC標(biāo)準(zhǔn)課件講義
- 售后服務(wù)的流程圖
- 急診科進(jìn)修匯報課件
- DL∕T 617-2019 氣體絕緣金屬封閉開關(guān)設(shè)備技術(shù)條件
- 信息技術(shù)基礎(chǔ)ppt課件(完整版)
- 弘揚(yáng)與傳承中華傳統(tǒng)文化課件(共16張PPT)
- 鋼琴基礎(chǔ)教程教案
- 電子課件-《飯店服務(wù)心理(第四版)》-A11-2549
評論
0/150
提交評論